I was trying to use
scene.camera:screenToRay()
yesterday and saw that I was getting errors every single time I used it. Is this a new thing? If not, is it gonna get fixed eventually??
I was trying to use
scene.camera:screenToRay()
yesterday and saw that I was getting errors every single time I used it. Is this a new thing? If not, is it gonna get fixed eventually??
screenToRay() takes a vec2() as a parameter.
screenToRay(vec2(5,5))
Here’s an example using screenToRay. Not sure what all the values returned are or what the input parameters do. Move the ball to the center of the screen (white dot) to change the values at the top of the screen. The top numbers might be the position of the camera.
viewer.mode=FULLSCREEN
function setup()
fill(255)
assert(OrbitViewer, "Please include Cameras as a dependency")
scene = craft.scene()
scene.sun.rotation=quat.eulerAngles(20,45,-30)
v=scene.camera:add(OrbitViewer,vec3(0,0,0),50,0,1000)
skyMaterial=scene.sky.material
skyMaterial.sky=color(158, 202, 223, 255)
skyMaterial.horizon=color(98, 166, 114, 255)
createSphere(vec3(10,10,10),2)
end
function draw()
update(DeltaTime)
scene:draw()
a,b=v.camera:screenToRay(vec2(0,0))
str=string.format("%.2f %.2f %.2f",a.x,a.y,a.z)
text(str,WIDTH/2,HEIGHT-100)
str=string.format("%.2f %.2f %.2f",b.x,b.y,b.z)
text(str,WIDTH/2,HEIGHT-130)
ellipse(WIDTH/2,HEIGHT/2,5) -- draw a center point
end
function update(dt)
scene:update(dt)
end
function createSphere(p,size)
local pt=scene:entity()
pt.position=vec3(p.x,p.y,p.z)
pt.model = craft.model.icosphere(size,2)
pt.material = craft.material(asset.builtin.Materials.Specular)
pt.material.diffuse=color(255,0,0)
end