Jump to content
  • Advertisement
Sign in to follow this  

Simple mesh rotation problem

This topic is 5059 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

Hi all, I am having trouble getting a mesh to rotate correctly. I have a demo where the camera can rotate around the mesh freely. What I would like is that when the user presses the up arrow, the mesh will rotate into the screen. Currently I am using this:
				Microsoft.DirectX.Vector3 Tmp = this.Mod_Array[1].ROTATION;
				this.Mod_Array[1].ROTATION = Tmp;
Where Mod_Array[1].ROTATION is the vector holding all the rotation values m_Camera.VectorRIGHT is the vector pointing to the right of the screen (calculated from camera view, and position cross) I thought that theorectically this should work. When rotating into the screen you need to turn along the axis represented by a vector running directly across the screen. However, what happens is that the rotation angle does not change, i.e. to start with the model does rotate into the screen, if I move the camera around to the left 90 degrees, instead of rotating into the screen, it now rotates left, i.e. the axis has not changed. I am definately updating the vectorRIGHT to respond to camera movements, so it is always up to date. Here is the code for generating the mesh matrix
Microsoft.DirectX.Quaternion qRot;
			Microsoft.DirectX.Vector3 RadianRot;
			RadianRot.X = (float)System.Math.PI * this.m_VecRot.X/180;
			RadianRot.Y = (float)System.Math.PI * this.m_VecRot.Y/180;
			RadianRot.Z = (float)System.Math.PI * this.m_VecRot.Z/180;

			qRot = Microsoft.DirectX.Quaternion.RotationYawPitchRoll(RadianRot.X,RadianRot.Y,RadianRot.Z);
			Microsoft.DirectX.Matrix RotMatrix = Microsoft.DirectX.Matrix.Identity;
			RotMatrix.AffineTransformation(1.0f,this.m_ActualCenter,qRot,new Microsoft.DirectX.Vector3(0,0,0));

			return RotMatrix;
I have searched the internet for help on rotation, but haven't found anything that suggests why this is happening. Any help would be much appreciated. Cheers DRB2k2

Share this post

Link to post
Share on other sites
I thought that I could create a quaternion on the right vector axis, and rotate it by a certain amount, then build a rotation matrix from this, and apply it to the current rotation vector like this:

Microsoft.DirectX.Vector3 Tmp = this.Mod_Array[1].ROTATION;
Quaternion q = new Quaternion(0f,0f,0f,0f);

Matrix mat = Matrix.Identity;
this.Mod_Array[1].ROTATION = Tmp;

However this doesn't work either. The model just starts flipping around on the wrong axis, and only in a small amount.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!