Roll Pitch Yaw Rotation From Angle Axis

Started by
0 comments, last by MusicMonkey5555 10 years, 6 months ago
Advertisement
MusicMonkey5555
August 24, 2011 08:20 PM
I want to get the local roll pitch yaw of my camera given it's angle axis rotation. The engine (Torque3D) I am using has a function called AngleAxisToPitchYaw and it gets the Pitch and yaw correctly, but doesn't give me any Roll. The code for it is:

AngAxisF aa;
dSscanf(argv[1], "%g %g %g %g", &aa.axis.x, &aa.axis.y, &aa.axis.z, &aa.angle);

//convert to radians
aa.angle = mDegToRad(aa.angle);

MatrixF mat;
aa.setMatrix(&mat);

VectorF axisVector[3] = {
VectorF(1,0,0),
VectorF(0,1,0),
VectorF(0,0,1)
};

VectorF localAxis[3];
for(U32 i = 0; i < 3; i++)
{
VectorF tmp;
mat.mulV(axisVector, &tmp);
localAxis = tmp;
localAxis.normalizeSafe();
}

char* ret = Con::getReturnBuffer(256);
float d2 = mAcos(mDot(localAxis[2], axisVector[2])), d0 = mAcos(mDot(localAxis[0], axisVector[0]));
float retY = (localAxis[0].y <= 0.0f ? 1.0 : -1.0) * mRadToDeg(d0);
retY = retY >= 0 ? retY : retY + 360.0f;
dSprintf(ret, 255, "%g %g", (localAxis[2].y <= 0.0f ? 1.0 : -1.0) * mRadToDeg(d2), retY);
return ret;


I want to get the roll as well though. I also have a conversion function to Euler, but I am not sure Euler is the same as Roll, Pitch, and Yaw. Also it seems to return a value when the camera doesn't appear to be rotated around the forward axis.
MusicMonkey5555
November 08, 2011 07:28 PM
I finally figured it out. Just a little background in case someone who isn't using torque and wants a similar function. TransformF simply contains a Point3F position and a Angle axis rotation. A Point3F is simply 3 float values.


///brief Converts the transform's rotation to Roll, Pitch, Yaw.
///param trans Transform to be converted.
///return Roll, Pitch, and Yaw as a Point3F.
Point3F TransformToRollPitchYaw(TransformF trans)
{
// Get current object transform matrix
MatrixF objTx = trans.getMatrix();

// Get rotations from transform matrix
Point3F vec;
objTx.getColumn(1,&vec);

// Get X-vector for roll calculation
Point3F xv;
objTx.getColumn(0,&xv);

// Calculate PRH (x = pitch, y = roll, z = heading)
Point3F rot(-mAtan2(vec.z, mSqrt(vec.x*vec.x + vec.y*vec.y)), mDot(xv,Point3F(0,0,1)), -mAtan2(-vec.x,vec.y) );

// Set up vars
F32 pitch = mRadToDeg(rot.x); // Pitch
F32 yaw = mRadToDeg(rot.z); // Heading
F32 roll = mRadToDeg(rot.y); // Roll

return Point3F(roll, pitch, yaw);
}
Share:

This topic is closed to new replies.

Advertisement