Trajectory / Matrices

Started by
4 comments, last by DJTN 11 years, 8 months ago
I have a collection of bullet particles. Each frame I update their position using a velocity vector. The bullets move from the camera (gun) outwards regardless of the movement of the camera which is correct, but when the camera moves -the bullets in the distance move with it, which is incorrect. They should continue on their trajectory (driven by their velocity) regardless of the camera’s movement.


I think the problem is the world transform matrix. It attaches a mesh and the particle emitter to the camera, however it also causes the bullets that have already been shot to move with the camera. The bullets should maintain their same trajectory after they’ve left.

Storing the world matrix for each particle is impractical but this gives you an idea of what I’m trying to accomplish. If each time a particle was added to the collection I stored the current world matrix then I could transform the particles position to maintain its trajectory. The question is - how I can I get the particles to maintain their trajectory without storing the world matrix for each particle?
Advertisement
Why is a bullet particle system required to be attached to the camera? When the bullets start moving could you not just use the cameras current world position and direction as the starting point for the bullet movement? Sounds like they need to move free from the camera, so why attach them?
Otherwise, if they need to be attached, youll need to apply the inverse of the translations and rotations the camera does each frame to the bullets. If the camera strafes right along its right vector youd move the bullets to the negative right (left) the same amount, same with rotations, you rotate (pitch) down, apply an equal pitch up to the bullets to counter what the camera does.
They would still be attached, technically, but would appear to move free of the cameras movements.
Sorry for the delayed reply, I was up late working.

Thanks for the input NumberXaero. This is not actually a gun and bullets its an effect for something else but it's easier to explain if I used this scenario to get my point (problem) across.

I have fixed the issue by transforming the start position by the matrix that attaches the emitter to the camera and then setting the velocity once, transforming it by the rotation matrix for the camera - and finally setting the world matrix to the emitter’s position before rendering.

I still have an issue with the yaw to iron out and clean the code up to be more efficient, but I'm happy with the solution.


Thanks again,
Dj
Well now I’ve got another issue pertaining to the velocity. It’s changing incorrectly.

If I have a velocity vector (0, 0 ,10) and I do a matrix transform based off the rotations of the camera (pitch, roll, yaw), the velocity should always be pushing away from the camera. The problem is that the velocities Y is fluctuating up and down with the slightest change in the camera's pitch.
Anyone?
I've solved my issue. For anyone else that finds this thread, the issue was in the matrix I was using to transform the velocity vector. To correct the matrix I created an inverted view matrix and manually changed element 41,42,43,14,24,34 to equal 0 and element 44 to equal 1.

This gave me the correct matrix to transform my velocity vector for anything attached to the camera (gun, flame thrower, etc...).


Hope this helps someone else.

This topic is closed to new replies.

Advertisement