Rotation about arbitary axis

Started by
2 comments, last by Paul7 20 years ago
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
Advertisement
goto mathworld.com and search for ''rotation formula''
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  Componentnn1=	(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  Componentnn2=	(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  Componentnn3=	(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.
Thanks alot that works great!

This topic is closed to new replies.

Advertisement