hi im trying to make compass, by getting value from rotationY of the mesh but the value im getting is ranged from -90 to 90 which is not sufficient to calculate the heading. am i doing it right?
thanks
make a compassSoftware: Away3D 4.x |
||
jackisgames, Newbie
Posted: 08 August 2012 10:27 AM Total Posts: 7 hi im trying to make compass, by getting value from rotationY of the mesh but the value im getting is ranged from -90 to 90 which is not sufficient to calculate the heading. am i doing it right? thanks |
||
Richard Olsson, Administrator
Posted: 08 August 2012 11:29 AM Total Posts: 1192 [ # 1 ] Are you using any of the yaw/pitch/roll/rotate functions to apply the rotation? What happens when you do that is that the rotation (around an arbitrary axis) is applied straight to the transform matrix. When you then retrieve rotationY, the matrix is decomposed to find the Euler angle rotation representing the rotation transform described in the matrix. This means that even though what has actually happened is a 180 degree rotation around Y, that same rotation could also be described as a rotation around several axes, resulting in the same visual orientation. The decomposition is just as likely to return this more complex rotation operation. That’s what’s happening here, and to get the full information about the rotation, you will need to look at both rotationX, rotationY and rotationZ. Try tracing out all of them, and you’ll see that after rotationY reaches 90 and starts declining again, the rotationX and rotationZ will have changed. There are a couple of ways to solve the compass scenario. One is to never use the rotate() function (or the yaw/pitch/roll functions which in turn use rotate() and instead just update rotationY manually. The other is to use the object’s transform matrix to transform a unit vector of your choice, in this case preferably (0,0,1) and then calculate how much that vector has turned around the Y axis to get single-axis rotation. Something like the below should work. The (0,0,1) vector exists as a constant on Vector3D called Z_AXIS.
turnedVector = myObject.transform.transformVector(Vector3D.Z_AXIS); The variable “bearing” should then contain the angle around the Y axis between the two points (0,0,1) and the transformed point, i.e. the single-axis rotation of the object. |
||
jackisgames, Newbie
Posted: 09 August 2012 09:10 AM Total Posts: 7 [ # 2 ] Thanks richard for the explanation and i managed to get it working now also a tips for those who use awayphysic you can use body.front value to determine the rotation so it will be like cheers! |