macklebee Posted July 20, 2010 Share Posted July 20, 2010 I was trying to set an entity to always be certain degrees offset from another entity and noticed that when rotating the X-axis, the Y and Z axis values bounce from 180 to 0 to -180, which screws up my offset. It does not do this if you rotate on the other two axis. Why is this happening and what can I do to prevent it from happening? Example code showing the problem: RegisterAbstractPath("") Graphics(1024,768) fw=CreateFramework() fw.main.camera:SetPositionf(0,1,-3) mesh1=CreateCube() mesh1:SetColor(Vec4(1,.25,0,1)) mesh1:SetPositionf(-1.75,0,0) mesh2=CreateCube() mesh2:SetColor(Vec4(1,0,1,1)) mesh2:SetPositionf(0,0,0) mesh3=CreateCube() mesh3:SetColor(Vec4(1,0,0,1)) mesh3:SetPositionf(1.75,0,0) fw.main.camera:Point(mesh2,3,1,0) light=CreateDirectionalLight() light:SetRotationf(45,45,0) while AppTerminate()==0 do mesh1:Turn(Vec3(.15,0,0),1) mesh2:Turn(Vec3(0,.15,0),1) mesh3:Turn(Vec3(0,0,.15),1) fw:Update() fw:Render() mesh1rot = mesh1:GetRotation(1) mesh2rot = mesh2:GetRotation(1) mesh3rot = mesh3:GetRotation(1) DrawText("Mesh 1 Rotated on X axis: ",100,100) DrawText("X axis: "..mesh1rot.x,100,120) DrawText("Y axis: "..mesh1rot.y,100,140) DrawText("Z axis: "..mesh1rot.z,100,160) DrawText("Mesh 2 Rotated on Y axis: ",390,100) DrawText("X axis: "..mesh2rot.x,390,120) DrawText("Y axis: "..mesh2rot.y,390,140) DrawText("Z axis: "..mesh2rot.z,390,160) DrawText("Mesh 3 Rotated on Z axis: ",680,100) DrawText("X axis: "..mesh3rot.x,680,120) DrawText("Y axis: "..mesh3rot.y,680,140) DrawText("Z axis: "..mesh3rot.z,680,160) Flip() end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
macklebee Posted July 20, 2010 Author Share Posted July 20, 2010 Noticed something else weird, when rotating on X-axis, the X-axis angle value varies between -90 to 90, while when rotating on the other two axis, the angles range from -180 to 180. This explains why the X-axis rotation causes the -180 to 0 to 180 values on the Y & Z. But why is this like this and how can I get it to stop doing this so all three axis use the same ranges? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Canardia Posted July 20, 2010 Share Posted July 20, 2010 I never actually understood how the angle bouncing logic works, it seems like a value which works when used directly between entity1.GetRotation() to entity2.SetRotation(), but all attempts to check for the value will fail. I think it should be changed to give a real angle from 0 to 359.999..., because people also think and speak in 0 to 359.999.... Nobody uses -180 to 0 or 0 to 180 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
macklebee Posted July 20, 2010 Author Share Posted July 20, 2010 agreed... but at the very least i would be happy if all three axis had the same value range... it makes no sense at all that they are different from each other and screws up simple offsets on the Y & Z when rotating on the X axis. This is a huge bug in my mind. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Naughty Alien Posted July 21, 2010 Share Posted July 21, 2010 ..well..you can always make small method/function to normalize such thing and you are set..provide input in range 0-360 and normalize that in range exposure 0-180<->-180-0.. Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 21, 2010 Author Share Posted July 21, 2010 I've tried but my coding skills are failing me at the moment... by the time I get it figured out josh will have fixed it or changed it to something else for me to have to figure out... it just makes no sense why the ranges between axis don't match... i assume there is a very good reason, but its confusing as all get out... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Naughty Alien Posted July 21, 2010 Share Posted July 21, 2010 ..well..actually its related to something called gimbal lock thats why such definitions are made..ill make small normalizing function and post it back, so u can use it. Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 21, 2010 Author Share Posted July 21, 2010 ..well..actually its related to something called gimbal lock thats why such definitions are made..ill make small normalizing function and post it back, so u can use it. ah interesting read on gimbal lock, and it makes some sense... but then I guess my next question is why do you not see the same effect on the other two when rotating around on the Y or Z axis... shouldn't they produce the same effect? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.