#### Archived

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.

## 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 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 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 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 on other sites
If the calculation above is ok, the problem lies here:

double AngleInDeg = Angle * (PI / 180);

change it to

double AngleInDeg = (Angle * 180 )/ PI;

Regards,
Endurion

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
20
5. 5

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

• Total Topics
632559
• Total Posts
3007080

×