Angle of Trajectory?

• 12-18-2003
napkin111
Angle of Trajectory?
I'm trying to create a bullet class that stores the bullets current position (x,y,z) and its trajectory. Traditionally I've used 3 variables called xtraject, ytraject, and ztraject where each loop xtraject was added to x and same for y/z. So in order to get the bullet travelling upper right at a 45 degree angle xtraject and ytraject would be 1. I'm want to have bullets that can fire at arbitrary angles, perhaps just have an angle variable (maybe I would need 2?) to control which way it goes and then a speed to say how fast its moving.

Do I use polar coordinates to do this? What about quaternions?

Thanks,

//napKIN
• 12-18-2003
Salem
• 12-18-2003
XSquared
You really need to learn how to use the search button, buddy.
• 12-18-2003
VirtualAce
Although that post is really not about the same thing. There is another post here about bullets that covers it better.

Essentially:

Code:

```#define PI 3.14159 #define DEGTORAD(angle) ((double)angle*PI/180.0) struct point2D {   double x;   double y; }; struct Bullet {   point2D Pos;   point2D Vel;   double speed;   int active; }; void FireBullet(point2D Start,int angle,double speed,Bullet *newbullet) {   newbullet->x=Start.x;   newbullet->y=Start.y;   newbullet->vel.x=cos(DEGTORAD(angle));   newbullet->vel.y=sin(DEGTORAD(angle));   newbullet->speed=speed;   newbullet->active=TRUE; } //Assuming we have an array of Bullet objects called Bullets void UpdateBullets {   for (int i=0;i<NumBullets;i++)   {     if (Bullets[i].active)     {         Bullets[i].x+=(Bullets[i].vel.x*Bullets[i].speed);         Bullets[i].y+=(Bullets[i].vel.y*Bullets[i].speed);     }   } }```
This is only for 2D, for 3D you must do a little more.