# vector to anges ???

Hi

I´ve made a simple landscape engine and now I want to move around some vehicles in it.
I did already do the entire physics stuff to make it react correct in the world, but now I´m getting more and more confused.
In order to rotate e.g. the chassis in the direction so that it is facing as it is given by a vector I tried to calculate all 3
angles x,y,z, but I didn´t get it to work.
I know it all sounds quite confusing and please excuse my poor english but I hope you get what I mean.

ralph

You can use this code, which is taken from the Quake 2 source, to convert vectors to angles:

``````void vectoangles (vec3_t value1, vec3_t angles)
{
float	forward;
float	yaw, pitch;

if (value1 == 0 && value1 == 0)
{
yaw = 0;
if (value1 > 0)
pitch = 90;
else
pitch = 270;
}
else
{
if (value1)
yaw = (int) (atan2(value1, value1) * 180 / M_PI);
else if (value1 > 0)
yaw = 90;
else
yaw = -90;
if (yaw < 0)
yaw += 360;

forward = sqrt (value1*value1 + value1*value1);
pitch = (int) (atan2(value1, forward) * 180 / M_PI);
if (pitch < 0)
pitch += 360;
}

angles[PITCH] = -pitch;
angles[YAW] = yaw;
angles[ROLL] = 0;
}
``````

Thanks a lot, I almost got mad because of that.
Yeah, and it works.
Thanks again

ralph

[This message has been edited by ralph318 (edited 05-22-2001).]