Firing projectiles?

Started by
1 comment, last by ToohrVyk 19 years, 8 months ago
Hi, i want to implement a weapon in my first person shooter. The problem is, i don´t know how to get the projectile particles fired in the direction the weapon (or player) looks/points. I have tried to multiply the vertices of the particles with the inverse modelview matrix, but this does not the job... And i don´t want to use open gl´s transform routines, since i need to change my vertices directly (for collision detection). What do i need to do to get it working? Thanks for any help, Gammastrahler
Advertisement
You probably want to start the projectile at the location of the player, and sets the projectile's velocity according to their direction (ie. vx = speed * cos(theta), vy = speed * sin(theta) where theta is the player's current rotation angle, for a Doom-type game. There's a couple more sines and cosines involved for a mouselook-type game. :)

To translate the particle into position for drawing, you need its position and orientation. Then you build a new modelview matrix for the particle based on these - basically you'll be writing your own versions of glRotate(), glTranslate() etc. which are useful to have around anyway.
Moving an object along a line:

If D is the direction of the line, and O is the initial position of the center of the object, then at any time t the position of the center of the object would be:

C(t) = tD + O

Where "+" means you should translate the point O by the vector tD.

Finding the direction vector:

If V is your direction vector, and M is your view matrix, then:

M * V = (0,0,1,0)

So, by extracting the inverse of your view matrix, M-1, you have:

V = M-1 * (0,0,1,0)

Which gives you your view vector (and you can the use it to move the object along the line it defines).

This topic is closed to new replies.

Advertisement