Archived

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

Dark_Streak

Changing rotation angles...any ideas?

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);

	if(_isnan(Angle))
		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.

glRotated(findAng(),0,1,0);
// 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