Animating a bullet

Started by
6 comments, last by LucidIon 19 years, 8 months ago
okay here is the situation. I have a model firing a bullet. The model have its own rotation matrix. The bullet should exit from a point on the model(The gun) and then travel forward in the same direction (no matter if the model chooses to rotate) I have tried the following things 1) The bullet is rendered under the models matrix, but that has obvious flaws since if the model rotates so will the bullet even though its been flying for a while. 2) The bullet inherits a copy of the models matrix and pushes this one on to stack. This works in the sense that the bullet flies. But its not from the point of origin where it should(on the model) Am I missing something obvious?
Advertisement
Ok so ur problem is how to get the bullet to fire from the gun?
yes and to keep it moving without being affected by the model
it sounds to me like you are being too dependant on openGL as your world representation

you should do the bullet motion using some sort of seperate physics(doesnt have to be 'real' physics) section, and only use openGL as the renderer
this means you will need to learn how to do arbitrary translations and rotations matrixes and have seperate ones for each object, and isolate them from one another with push/pop

but once you do that, youre free to do anything you want with the bullet
Well I know what you need to do, but ATM i dont have my code handy to give u some exacts..

Basically you need to go through the models hirerchary and find were the gun is attached to. That would solve the were it starts problem. As i said specifics are hard to give since i havent delt with model stuff in a long time.

Question. what API are you using? OGL or DX?
OGL

oh and yes I have a world representation of my bullet. Its position are incremented by a game tick. I simply need to render it so it goes from a point on my model and in same direction...

haphazardlynamed I did what you suggested in #2. But this resulted in me rotating away from the point at the model
how about something like

//camera transformations
rotate
translate

//render gun
push
translate(gunposition)
rotate(gunorientation)
drawgunmodel
pop

//render bullet
push
translate(bulletposition)
rotate(bulletorientation)
drawbulletmodel
pop

both bullet and gun have totally seperate positions and rotations
and both of their models should be defined with their center's at 0,0,0 (the gun barrel should probably be at 0,0,0 to keep alignment easy)

note that matrixces are evaluated in reverse order that they appear in code
1 the bullet is drawn at 000,
2 bullet is rotated while still at the origin,
3 bullet translated to its proper location,
*same happens for gun*
4 then everything in the scene is translated in the opposite direction of the camera(moving the cam to the right is the same as moving everything else to the left, relative motion)
5 everything is rotated according to camera orientation (also opposite)
A good idea would also to store a position for the bullet to start at and a vector (direction) for the bullet to go in in the model file. You are going to have to ensure your world simulation and OpenGL are separate as I've sure you're going to want to know if you have shot something :) translate the point and vector into world space and move the bullet in the direction of the vector (if the vector is normalised then:

position = point + vector * speed * time if you ignore icky things like gravity.
-- Jonathan

This topic is closed to new replies.

Advertisement