Best way to track moving objects

I’m basically just wanting to know which is better to use when you have a very large amount of objects that move around: do you store a matrix for each object and then multiply the modelview matrix with that matrix each time you render that object, or is it better to merely “manually” modify the vertices of the object itself to cause it to move in the desired fashion?

In my case I’m shooting hundreds upon hundreds of laser beams (a few simple quads or tris), should I keep a matrix for each one to draw it at its proper location and orientation or should I just keep the vertices (or position) of the beam and just modify its vertices according to its movement? Like this:
beam.front.x += beam.velocity.x;
beam.front.y += beam.velocity.y;

beam.back.x += beam.velocity.x;

What’s the best way to do something like this and keep track of MANY moving objects that require the tracking of orientation information?

[This message has been edited by Punchey (edited 12-05-2000).]

I believe this would depend on the speed of your processor vs. the speed of the geometry engine of your graphics chipset.

If you manually modify the vertices and refresh, you’d be relying on the system CPU to calculate the incremental changes in the objects transformations, while putting these transformations inside a series of pushes and pop of the matrix stack would allow the GPU to do all the calculations. So, if the machine was a 1.4ghz Pentium 4 and you had an NV10-based GPU, you would opt for the former, but if it were an 866mhz Pentium 3 and you had an NV15 or Radeon GPU, you would opt for the latter.

Am I correct in these assumtions?


Well, that makes sense… but, in the case of something like a bunch of laser beams, the model is very simple and has very few vertices. So I’m just wondering if, even with a good GPU, if doing a push, a matrix mult, and a pop for EACH and EVERY little laser beam would grind things to a halt or not. Currently, I’m just drawing the lasers with GL_LINES so all I have to do is draw a line from one point to another point determined by the velocity vector of the beam. But if I used an actual “model” tris or quads or whatever, then I have the problem of actually defining the vertices in such a way that it actually “looks” like the beam is facing the right direction. The easiest way to make it face the right direction is with a matrix. So, since a laser will never change its orientation after being fired, perhaps I could use a matrix initially to rotate the model for the laser to get the right orientation, and then from there add the velocity vector to the vertices of the laser. So then the question becomes, how do I rotate a matrix or, say, use the parent ship’s rotation matrix to alter the coordinates of the model? Do I multiply each vertex of the stored model by the matrix? If so, how is this done?

You may want to try a few methods on a few different machines to get a good idea what works best.

Of what I’ve seen of the performance within the NV15 GPU and Radeon chipset, placing all the transformations within set of matrix mults based on the parent ships transformation at time of firing would be the best performance method. Additionally, this would buy you additional CPU cycles for AI or whatever else you need to implement.

Just my 2 cents though.


So was I correct aboutu multiplying the vertexes of the “beam” model by the ships matrix to get the rotated verts for the beam? Does anyone know exactly how to do this? I’ve never had to do something like this so I don’t know how to go about multiplying a vertex be a rotation matrix.