Original Post
Hi all, I have a terrain and lets say a box. User controls box with arrow keys. I want box height and orientation follows terrain heights. I implemented and I succeded. But I have a small problem. I am using following code to make orientation
Quaternion q;
Vector3 nodeNormal, rotVector;
FLOAT rotAngle;
nodeNormal = node.GetWorldOrientation().GetYAxis();
rotVector = nodeNormal.Cross( normal );
rotVector.Normalize();
rotAngle = Math_ACos( nodeNormal.Dot( normal ) );
q.RotateAroundAxis( rotVector, rotAngle );
node.SetRotate( q );
It does orientation correctly. But the problem is when it rotates object, it changes z axis of the object. Assume that box is facing (z axis) to (0.0f, 0.0f, 1.0f) when terrain height changes above code is applied and resulting Z axis becomes (0.3f, -0.1, 0.99f). Box should not rotate around Y axis. Is there any suggestion?