Suppose you have quaternion that describes the rotation of a 3D Model. What I want to do is, given an Object (with rotationQuaternion, side vector...), I want to align it to a target point. For a spaceship, I want the cockpit to point to a target. Here is some code I have ... It's not doing what I want and I don't know why...
if (_target._ray.Position != _obj._ray.Position) { Vector3 vec = Vector3.Normalize(_target._ray.Position - _obj._ray.Position); float angle = (float)Math.Acos(Vector3.Dot(vec, _obj._ray.Direction)); Vector3 cross = Vector3.Cross(vec, _obj._ray.Direction); if (cross == Vector3.Zero) cross = _obj._side; _obj._rotationQuaternion *= Quaternion.CreateFromAxisAngle(cross,angle); } // Updates direction, up, side vectors and model Matrix _obj.UpdateMatrix();
after some time the rotationQuaternion is filled with almost Zero at X,Y,Z and W Any help? Thanks ;-)