Jump to content
  • Advertisement


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


Changing rotation angles...any ideas?

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

I am trying to Rotate an object to ''look'' towards a certain point, but Im failing miserably. All this maths is really frying my brain. Can anyone help me, perhaps see something Im doing wrong? I have a model, which is facing, say, North. There is another object, say a pole, that is slightly in front (to the North) and to the left of my model. Lets say that the pole is at a 25 degree angle from the model. Now, I want to be able to rotate the model so that it is looking at the pole. So basically it needs to rotate by 25 degrees (using glRotate). Now, the problem is that the model and the pole are not static, so this angle may be constantly changing. Therefore, I need to calculate this number of degrees every frame (or however often) and this is where I am getting my problem. The results I am getting seem to be random, large values, which dont represent the correct degrees at all. I wonder if I am calculating the two vectors incorrectly? When finding a vector, you subtract the source point from the destination point right? Here''s my code:

// This is the function that is supposed to calculate the angle in degrees

double findAngle()

	CVector3 toPoleVec = Normalize( destPoint1 - sourcePoint1);

	CVector3 toModelVec = Normalize( destPoint2 - sourcePoint2);

	float dotProduct = Dot(toPoleVec, toModelVec);				
	double Angle = acos(dotProduct);

		Angle = 0;

	// To convert radians to degress use this equation:   radians * (PI / 180)

	double AngleInDeg = Angle * (PI / 180);
return AngleInDeg;

// Here I rotate the model, by calling my function to return the degree of rotation.

// Draw model etc..

Any suggestions?

Share this post

Link to post
Share on other sites
I have studied the ''dot product'' and various other mathematical formulas to try and get this idea working.

Please can someone see where I am going wrong...I am sure many of you may have done something similar before.

Share this post

Link to post
Share on other sites
well, you can use the dot product to find the angle between the model and the pole.

then just rotate the model the difference. thats all there is to it.

Its my duty, to please that booty ! - John Shaft

Share this post

Link to post
Share on other sites
Err, yes. I think you''ll find that by looking at my code, that is what I have attempted to do.

Unfortunately, I am getting garbled results...or at least results that arent the angles in degrees I was expecting. I have recently reposted this question in the OpenGL forum, and I am getting some good feedback there. I think I am on the verge of solving it. But thanks anyway.

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!