the following program sets the plank’s rotation to gx,gy,gz on every draw cycle. every 0.1 second, it sets gx,gy,gz to the plank’s rotation’s angles, which should be the angles originally put in. but the plank rotates around. i conclude that angles is not returning the proper values.
viewer.mode=STANDARD
function setup()
time = 0
max = 0.1
scene = craft.scene()
scene.camera.position=vec3(0,1,-4)
ground = scene:entity()
ground.model = craft.model.cube(vec3(1,.2,1))
ground.material = craft.material(asset.builtin.Materials.Specular)
ground.material.map = readImage(asset.builtin.Surfaces.Desert_Cliff_Roughness)
ground.position = vec3(1,1,1)
gx,gy,gz = 45,45,45
ground.rotation = quat.eulerAngles(gx,gy,gz)
end
function update(dt)
time = time + dt
if time >= max then
time = 0
gx,gy,gz = ground.rotation:angles():unpack()
-- if angles worked, this would have no effect
end
ground.rotation=quat.eulerAngles(gx,gy,gz)
scene:update(dt)
end
function draw()
update(DeltaTime)
scene:draw()
end
If you print the values of ground.rotation at the end of setup(), it prints 6 digits past the decimal point. That reminds me of 32 bit math code. I wonder if the math isn’t precise enough.
@skar we can’t expect to get the input angles back, as quat rotations choose the fastest rotation to the desired angle, but they should be equivalent, and stable.
I see, so I tested out what happened if I used those returned values from angles for the given 45, 45, 45 and it’sa completely different position and also returned new values
“66DF…” screenshot is using 45, 45, 45
“1EE2…” is using 59.63, 8.42, 30.36
You already know this since you have it happening in the update loop, but maybe it’s easier for @Simeon to see just one example
simpler example. you’d expect 90,90,0 and the same quat to repeat. the bug is in quat.
local x,y,z,q
x,y,z = 90,90,0
print("x ",x, " y ", y, " z ",z)
q = quat.eulerAngles(x,y,z)
print(q)
x,y,z = q:angles():unpack()
print("x ",x, " y ", y, " z ",z)
q = quat.eulerAngles(x,y,z)
print(q)
x,y,z = q:angles():unpack()
print("x ",x, " y ", y, " z ",z)
q = quat.eulerAngles(x,y,z)
print(q)