Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Trajectory / Matrices


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 24 July 2012 - 03:58 PM

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?

Sponsor:

#2 NumberXaero   Prime Members   -  Reputation: 1520

Like
0Likes
Like

Posted 24 July 2012 - 06:07 PM

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.

Edited by NumberXaero, 24 July 2012 - 06:08 PM.


#3 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 25 July 2012 - 09:58 AM

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

#4 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 25 July 2012 - 04:21 PM

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.

Edited by DJTN, 26 July 2012 - 10:52 AM.


#5 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 26 July 2012 - 10:52 AM

Anyone?

#6 DJTN   Members   -  Reputation: 207

Like
0Likes
Like

Posted 26 July 2012 - 05:30 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS