Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Rotations

Started by Agwan Jan 23, 2008 at 6:51 AM 3 replies 1k views
Original Post
Agwan
Agwan
I have an object 'an enemy spaceship' it's roation is represented as a quaternion which I also use to calculate the objects look, up and right Vectors. I have the position that i want my object to face and am trying to figure out how to calculate the correct rotation angles. To rotate the object i call a method that takes yaw, pitch and roll (six degrees of freedom). Does anyone know of a way to do this?
Zakwayda
Zakwayda
Quote:
Original post by Agwan
I have an object 'an enemy spaceship' it's roation is represented as a quaternion which I also use to calculate the objects look, up and right Vectors. I have the position that i want my object to face and am trying to figure out how to calculate the correct rotation angles. To rotate the object i call a method that takes yaw, pitch and roll (six degrees of freedom). Does anyone know of a way to do this?
The function that takes yaw, pitch, and roll - what does it do exactly?

Maybe you could post the code for it...
apatriarca
apatriarca
Not sure if I have understanded your problem but I think you should search "quaternion to euler angles" with google.
Sneftel
Sneftel
Quote:
Original post by Agwan
I have an object 'an enemy spaceship' it's roation is represented as a quaternion which I also use to calculate the objects look, up and right Vectors. I have the position that i want my object to face and am trying to figure out how to calculate the correct rotation angles. To rotate the object i call a method that takes yaw, pitch and roll (six degrees of freedom). Does anyone know of a way to do this?

If your object's orientation is expressed as a quaternion, don't bother finding euler angles to use to construct the rotation matrix. Just construct the rotation matrix directly from the quaternion.
Agwan
Agwan
I am not trying to find the euler angles for the quaternion or generate a matrix from it. I am trying to write it so that it 'pilots' the object.
(object is a automated space ship).

Vector3 lookNormal = Vector3.Normalize(base.Look);Vector3 directionNormal = Vector3.Normalize(position - this.Position);float adjustYaw, adjustPitch, adjustRoll;// Do calculations here...// Calculate Roll AdjustmentVector3 worldXAxis;Vector3 perpAxis;worldXAxis = Vector3.Cross(TargetUpDirection, Look);worldXAxis.Normalize();perpAxis = Vector3.Cross(Right, worldXAxis);adjustRoll = Vector3.Dot(Look, perpAxis);// Calculate Pitch Adjustment//??// Calculate Yaw Adjustment//??// 6dof rotation style.. eg if the object is looking down then applies Yaw (90 degrees) the object is now looking to the side with a 90 degree roll angle..base.GenerateRotationImpulse(adjustYaw, adjustPitch, adjustRoll);//-- Rotation Method --//public void GenerateRotationImpulse(float pitch, float yaw, float roll){   rotationVerlocity += new Vector3(   yaw,                                       pitch,                                       roll);}//-- Update Code--//// Update the rotationVector3 updateVelocity = Vector3.Multiply(rotationVerlocity, elapsedTime);roation *= Quaternion.RotationYawPitchRoll(updateVelocity.X,updateVelocity.Y,updateVelocity.Z);// Update the positionposition += verlocity * elapsedTime;// Set the Rendering matrixroation.Normalize();Matrix rotationalDisplacement = Matrix.RotationQuaternion(Quaternion.Conjugate(roation));renderMatrix = rotationalDisplacement * Matrix.Translation(position);            //xaxis            right.X = rotationalDisplacement.M11;            right.Y = rotationalDisplacement.M21;            right.Z = rotationalDisplacement.M31;            //yaxis            up.X = rotationalDisplacement.M12;            up.Y = rotationalDisplacement.M22;            up.Z = rotationalDisplacement.M32;            //zaxis            look.X = rotationalDisplacement.M13;            look.Y = rotationalDisplacement.M23;            look.Z = rotationalDisplacement.M33;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.