Angle to Vector

Angle to Vector

Post by Christoph Meng » Mon, 05 Jun 2000 04:00:00



Hi All!

I try to add some weapons to my simple 3D-shooter.
However, I have big problems calculating the forward vector of the
player.
I found the following code in Quake 1 that converts angles to vectors:
(here a shortened PSEUDO-CODE:)

void AngleVectors(vec3_t angles, vec3_t forward)
{
        forward[0] = cos(pitch)*cos(yaw);
        forward[1] = cos(pitch)*sin(yaw);
        forward[2] = -sin(pitch);

Quote:}

This didn't work. I think it's because of the different coordinate
systems,
so I changed it to

void AngleVectors(vec3_t angles, vec3_t forward)
{
        forward[2] = -cos(pitch)*cos(yaw);
        forward[1] = cos(pitch)*sin(yaw);
        forward[0] = -sin(pitch);

Quote:}

This is better, but still not 100% correct.

Can you give me some advice how to convert angles to vectors in general?

Thank you in advance,

Chris

 
 
 

Angle to Vector

Post by ZZ » Tue, 06 Jun 2000 04:00:00


u've gotta use tan methinks, theres prolly a much quicker way of doing it
than this but after of an hour of me mit my calculator this is the best i
came up with

rot[1]=y ie up/down ..
vel[1] is upwards/downwards velocity

  float v;
  if (rot[1]>89)
   v = 1000;
  else if (rot[1] < 1 && rot[1] > -1)
   v=0.001;
  else if (rot[1]<-89)
   v = -1000;
  else
   v = tan(rot[1]*DEG2RAD);
  float p = rot[0]*DEG2RAD;
  float xx = -sin(p);
  float zz = -cos(p);

  float tot = fabs(v)+fabs(xx)+fabs(zz);
  vel = VECTOR(xx/tot, v/tot , zz/tot);

cheers zed


Quote:> Hi All!

> I try to add some weapons to my simple 3D-shooter.
> However, I have big problems calculating the forward vector of the
> player.
> I found the following code in Quake 1 that converts angles to vectors:
> (here a shortened PSEUDO-CODE:)

> void AngleVectors(vec3_t angles, vec3_t forward)
> {
> forward[0] = cos(pitch)*cos(yaw);
> forward[1] = cos(pitch)*sin(yaw);
> forward[2] = -sin(pitch);
> }

> This didn't work. I think it's because of the different coordinate
> systems,
> so I changed it to

> void AngleVectors(vec3_t angles, vec3_t forward)
> {
> forward[2] = -cos(pitch)*cos(yaw);
> forward[1] = cos(pitch)*sin(yaw);
> forward[0] = -sin(pitch);
> }

> This is better, but still not 100% correct.

> Can you give me some advice how to convert angles to vectors in general?

> Thank you in advance,

> Chris


 
 
 

Angle to Vector

Post by Hans-Bernhard Broeke » Wed, 07 Jun 2000 04:00:00



> I try to add some weapons to my simple 3D-shooter.
> However, I have big problems calculating the forward vector of the
> player.
[...]
> This didn't work. I think it's because of the different coordinate
> systems, so I changed it to
[...]
> This is better, but still not 100% correct.

Your question lacks important bits of information. Most pressingly,
you don't tell *how* the code fails, for you. Neither do you specify
where the 'pitch' and 'yaw' angles are coming from, and what your
coordinate system is. How is it different from Quake 1, which you
ripped the code fragment from?

It's next to impossible to set up a machinery if you don't know what
the input and expected output exactly is.
--

Even if all the snow were burnt, ashes would remain.

 
 
 

Angle to Vector

Post by Ofer Huberma » Fri, 09 Jun 2000 04:00:00


The code is correct. Make sure you use radians, not degrees, in your code.


Quote:> Hi All!

> I try to add some weapons to my simple 3D-shooter.
> However, I have big problems calculating the forward vector of the
> player.
> I found the following code in Quake 1 that converts angles to vectors:
> (here a shortened PSEUDO-CODE:)

> void AngleVectors(vec3_t angles, vec3_t forward)
> {
> forward[0] = cos(pitch)*cos(yaw);
> forward[1] = cos(pitch)*sin(yaw);
> forward[2] = -sin(pitch);
> }

> This didn't work. I think it's because of the different coordinate
> systems,
> so I changed it to

> void AngleVectors(vec3_t angles, vec3_t forward)
> {
> forward[2] = -cos(pitch)*cos(yaw);
> forward[1] = cos(pitch)*sin(yaw);
> forward[0] = -sin(pitch);
> }

> This is better, but still not 100% correct.

> Can you give me some advice how to convert angles to vectors in general?

> Thank you in advance,

> Chris

 
 
 

1. Euler angles --> Angle axis vector

Hi, once again I try to come back to the poor core math part of my code.

I'm at the point where I need to clarify and try again to setup a solid
3D movement class.

So, I first need is to attach to every object a direction vector. I
presume this direction vector is the one used in calls to glRotate.

So, instead of having the poors :
glRotate(XAngle,1,0,0);
glRotate(YAngle,0,1,0);
glRotate(ZAngle,0,0,1);

I would like to have :

glRotate(angle,dirvector.x,dirvector.y,dirvector.z);
I think it's a first step to a more intelligent code.

Of course my rotate functions still to be controled in degrees.
So I plan to feed my rotateBy(x,y,z) with x,y,z angle increments and
recompute the new angle axis vector.

What do I have ?

- the CVector3 direction vector
- a rotation matrix (opengl OR my own just for learning)
- computing the two will give me a new matrix
- extract from the resulting matrix the new direction vector
- use this vector with glRotate with a 0 value for the angle parameter

Am I right ? How can I "extract" the result from the matrix ? At what
position in the matrix are the 3 values I need (may be 4 in homogenous
coordinates)

Thank you...

By the way, I'm trying to find a simple (java or not) application that
would help me visualizing this kind of operations... Any hint ?

2. Blank Video Tapes?

3. Euler angles from vector

4. Free Cash Grant

5. angle between vectors

6. Antialiasing with RE

7. quickie [angle between vectors]

8. problem with calculating angle between vectors

9. Angles between vectors in 3D

10. 3 rotation angles to vector

11. signed angle between vectors

12. Angle between vectors