I am using the U3D sample software library to create a U3D viewer.
I have a problem with rotation view.
I cannot find a way to set an arbitrary pivot point to rotate the camera view around.
I tried to use the "computePivot" function before rotate the view to compute the pivot point, but doesn't work.
This is the function to handle the rotate view from U3D sample software library:
F32 radians;
if (pViewMatrix) {
if ( mod )
{
if ( fInX != 0 )
{
// Roll the camera in camera space
radians = ToRadians(fInX * 0.5f);
pViewMatrix->Rotate3x4( radians, IFX_Z_AXIS );
}
}
else
{
if ( fInY != 0 )
{
F32 *rawMatrix=pViewMatrix->Raw();
// Tilt camera in world space about pivot
radians = ToRadians(-fInY * 0.5f);
IFXVector3 right(rawMatrix[0], rawMatrix[1], rawMatrix[2]);
right.Normalize();
// Build axis-angle rotation matrix
IFXQuaternion quat;
quat.MakeRotation(radians, right);
IFXMatrix4x4 mAngleAxisRot = quat;
IFXMatrix4x4 mIntermediate(rawMatrix);
// rather than actually compositing these matrices, build
// the translation component of TRT^-1 directly (faster).
rawMatrix[12] = -(pivotPoint.X()*rawMatrix[0] +
pivotPoint.Y()*rawMatrix[4] +
pivotPoint.Z()*rawMatrix[8]) + pivotPoint.X();
rawMatrix[13] = -(pivotPoint.X()*rawMatrix[1] +
pivotPoint.Y()*rawMatrix[5] +
pivotPoint.Z()*rawMatrix[9]) + pivotPoint.Y();
rawMatrix[14] = -(pivotPoint.X()*rawMatrix[2] +
pivotPoint.Y()*rawMatrix[6] +
pivotPoint.Z()*rawMatrix[10]) + pivotPoint.Z();
// Now apply this rotation about the pivot point
pViewMatrix->Multiply3x4(mAngleAxisRot, mIntermediate);
}
if ( fInX != 0 )
{
F32 *rawMatrix=pViewMatrix->Raw();
// compute up vector
IFXVector3 up(0.0f, 0.0f, 0.0f);
if ( yKeyDown )
up.Y() = 1.0f; // Y is UP
else
up.Z() = 1.0f; // Z is UP
// compute rotation angle
radians = ToRadians(-fInX * 0.5f);
// Rotate camera about Up axis in world space about pivot
// Build axis-angle rotation matrix
IFXQuaternion quat;
quat.MakeRotation(radians, up);
IFXMatrix4x4 mAngleAxisRot = quat;
IFXMatrix4x4 mIntermediate(rawMatrix);
// rather than actually compositing these matrices, build
// the translation component of TRT^-1 directly (faster).
rawMatrix[12] = -(pivotPoint.X()*rawMatrix[0] + pivotPoint.Y()*rawMatrix[4] + pivotPoint.Z()*rawMatrix[8]) + pivotPoint.X();
rawMatrix[13] = -(pivotPoint.X()*rawMatrix[1] + pivotPoint.Y()*rawMatrix[5] + pivotPoint.Z()*rawMatrix[9]) + pivotPoint.Y();
rawMatrix[14] = -(pivotPoint.X()*rawMatrix[2] + pivotPoint.Y()*rawMatrix[6] + pivotPoint.Z()*rawMatrix[10]) + pivotPoint.Z();
// Now apply this rotation about the pivot point
pViewMatrix->Multiply3x4(mAngleAxisRot, mIntermediate);
}
}
}
Change the variable "pivotPoint" does not have effect.
Do you have any idea how to do it?
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the U3D sample software library to create a U3D viewer.
I have a problem with rotation view.
I cannot find a way to set an arbitrary pivot point to rotate the camera view around.
I tried to use the "computePivot" function before rotate the view to compute the pivot point, but doesn't work.
This is the function to handle the rotate view from U3D sample software library:
Change the variable "pivotPoint" does not have effect.
Do you have any idea how to do it?
Thanks