Render.ru

Angle Between two 3d vectors and object's direction.

#1
Hi, I need to adjust object's direction in 3d.
I have current point vector , and destination point vector.
When current point == destination point, destination point gets a new random position.
The poblem that i can't torn and adjust object to a new direction.

i need to use function:
glRotatef (XAngle, 1.0f, 0.0f, 0.0f);
glRotatef (YAngle, 0.0f, 1.0f, 0.0f);
glRotatef (ZAngle, 0.0f, 0.0f, 1.0f);

but i can't calculate XAngle,YAngle,ZAngle.

Please help.


P.S.

function don't work
void DCreature::ComputeRPY (void)
{

float roll, pitch, yaw;

// Determine the direction of the lateral acceleration.

Dpoint lateralDir = (DestPoint % (DestPoint - CurrPoint)) % DestPoint;

lateralDir.Normalize();

// Set the lateral acceleration's magnitude. The magnitude is the vector
// projection of the appliedAcceleration vector onto the direction of the
// lateral acceleration).

float lateralMag = (DestPoint - CurrPoint) * lateralDir;

// compute roll

if (lateralMag == 0) {
roll = 0.0f;
} else {
roll = (float) -atan2(GRAVITY, lateralMag) + PI/2;
}

// compute pitch

pitch = (float) -atan(CurrPoint.y / sqrt((CurrPoint.z*CurrPoint.z) + (CurrPoint.x*CurrPoint.x)));

// compute yaw

yaw = (float) atan2(CurrPoint.x, CurrPoint.z);

// store them

XAngle = pitch;

YAngle = yaw;

ZAngle = roll;
}
 
Сверху