Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Paul7

Rotation about arbitary axis

This topic is 5208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Am in the process of implementing 3D lsystems using turtle graphics techniques and need to be able to rotate it about its local axis system HLU (heading, left, up) as opposed to the world XYZ axis. Have tried translating the axis back to the origin then rotating it back to the XYZ axis and applying the rotation I want around the HLU axis and then reversing the process back to its position but this doesnt seem to work. Anyone have any suggestions how I go about doing this? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
goto mathworld.com and search for ''rotation formula''

Share this post


Link to post
Share on other sites
Hi Rotation about an arb axis as follows...




D3DVECTOR Rot_Arb(D3DVECTOR nvec, D3DVECTOR narb,float ang)
{
float x,y,z,n1,n2,n3,nn1,nn2,nn3;
n1=narb.x;
n2=narb.y;
n3=narb.z;

x=nvec.x;
y=nvec.y;
z=nvec.z;

ang=ang*g_DEGTORAD;

// X Component

nn1= (n1*n1+(1-n1*n1)*cosf(ang))*x;
nn1=nn1+(n1*n2*(1-cosf(ang))-n3*sinf(ang))*y;
nn1=nn1+(n1*n3*(1-cosf(ang))+n2*sinf(ang))*z;

// Y Component

nn2= (n1*n2*(1-cosf(ang))+n3*sinf(ang))*x;
nn2=nn2+(n2*n2+(1-n2*n2)*cosf(ang))*y;
nn2=nn2+(n2*n3*(1-cosf(ang))-n1*sinf(ang))*z;

// Z Component

nn3= (n1*n3*(1-cosf(ang))-n2*sinf(ang))*x;
nn3=nn3+(n2*n3*(1-cosf(ang))+n1*sinf(ang))*y;
nn3=nn3+(n3*n3+(1-n3*n3)*cosf(ang))*z;

return Normalize(D3DVECTOR(nn1,nn2,nn3));
}


void ROTATE_ABOUT_Y_AXIS()
{
Camera_Xaxis = Rot_Arb(Camera_Xaxis, Camera_Yaxis, Camera_RotSp);
Camera_Zaxis = Rot_Arb(Camera_Zaxis, Camera_Yaxis, Camera_RotSp);
}

void ROTATE_ABOUT_X_AXIS()
{
Camera_Yaxis = Rot_Arb(Camera_Yaxis, Camera_Xaxis, Camera_RotSp);
Camera_Zaxis = Rot_Arb(Camera_Zaxis, Camera_Xaxis, Camera_RotSp);
}





This is some source taken straight out of my code so I will explain it for you alittle...

Camera_Xaxis, Camera_Yaxis, Camera_Zaxis are of-course the camera axis ( but these can be your objects arb axis instead! )

To rotate about the arb X axis by RotSp call ROTATE_ABOUT_XAXIS etc etc...


Hope this helps.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!