KT Kingsley Posted January 7, 2021 Share Posted January 7, 2021 I'm using this bit of code to determine the z-axis direction (as in compass direction) my camera is pointing in: vector euler_rot = llRot2Euler (llGetCameraRot ()); rotation rot = llEuler2Rot (<0.0, 0.0, euler_rot.z>); This works fine when my camera is level, but with flycam mode enabled, where I can roll the camera and turn it upside-down, it gets a bit messy. The value rot is used to rotate a compass card texture on a prim, and also to locate a couple of child prims representing the sun and moon positions in relation to that. What should I be doing? Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted January 7, 2021 Share Posted January 7, 2021 (edited) In times like this, I tend to debug things visually: The red/green/blue lines are the world axes. The black prim matches the camera's rotation. The orange prim tries to be the compass (its rotation is calculated from the black one). In the above video, the orange prim's rotation is calculated exactly as you did, which is how I would've also done it for something simple. This demonstrates the problems with looking straight up/down (and even upside down). Particularly, you'll notice that the euler Z angle doesn't correspond to "rotation around the Z axis" when the camera's Z axis doesn't match the world Z axis. (When looking up/down, the camera's "up" axis is more parallel with the world's X/Y axes.) In an attempt to fix that, I figured we could move into the camera's local space to change the euler angles before converting back, but this doesn't work: rotation rot = llGetCameraRot(); vector euler = llRot2Euler(rot); vector local = euler / rot; // Negate the camera's rotation local.y = 0; // Remove the Y (pitch) angle local *= rot; // Return to original coordinates rot = llEuler2Rot(local); llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, rot]); After doing some googling, I found this question: https://stackoverflow.com/questions/5782658/extracting-yaw-from-a-quaternion "If you want to create a quaternion that only rotates around the y axis, you zero out the x and z axes..." The only difference is that in Second Life the Yaw axis is Z. So this leads us to... rotation rot = llGetCameraRot(); rot.x = 0; rot.y = 0; llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_ROT_LOCAL, rot]); This works "perfectly," it's entirely aligned with the camera reference, the only problem left is that when the camera is upside-down, the left/right directions are inverted. Checking for that should be pretty simple. Edited January 7, 2021 by Wulfie Reanimator 1 2 Link to comment Share on other sites More sharing options...
KT Kingsley Posted January 8, 2021 Author Share Posted January 8, 2021 Thank you very much, Wulfie. You demonstrate how simple things can turn out to be when approached analytically and logically. Your explanation has also triggered some interesting ideas about other ways of presenting the data. Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now