#### Archived

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

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

## 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 on other sites
goto mathworld.com and search for ''rotation formula''

##### 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  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.

##### Share on other sites
Thanks alot that works great!

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 13
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009836
• ### Who's Online (See full list)

There are no registered users currently online

×