Skip to main content
GameDev.net gamedev.net
🔒 Locked

Models that move

Started by cclements Nov 26, 2003 at 8:55 AM 4 replies 600+ views
Original Post
cclements
cclements
I have code that can load a model just fine. Now I would like to move certain parts of that model in my program. For instance, if I wanted to rotate the turret of the tank only, does that turret represent an independent model that is rotated like you would expect? How do I keep it in positioned correctly over the hull? What about the bogey wheels? Is this considered animation? Where should I begin my research?
No signature files!!! =)
iNsAn1tY
iNsAn1tY
Many games use more than one model to make one object (tank, person, huge stomping Mech, etc.) For instance, Quake III uses three different models to create it''s players: one for the head, one for the body and one for the legs.

Now, the game knows how the models "fit" together using a series of tags. Each tag has a 3D position and a rotation matrix. For each frame of animation, the legs model has a tag which defines where the body model should be at that point in time. When the model is loaded, the tags are found, and the models are linked together in memory. When it''s time to render the person in the game, the legs are positioned and drawn in 3D space, then the body is positioned and drawn in 3D space according to the tag in the legs model.

Taking this example to your tank, you would need a tag in the tank bogey model which defines where the turret attaches. When you position the tank bogey model, you push the modelview matrix, apply the translation in the tag with glTranslatef() or whatever, and draw the turret model. Then, it will always be in the right position. If you wanted to specify the rotation of the turret, all you''d have to do is load the turret rotation into glRotatef(), or it''s D3D equivalent, and you''re away.

In terms of research, I''d check out the MD3 loader over at www.GameTutorials.com, and the MD3 model format in general. It''s only a little bit of extra work to add a tag to your model, and link the turret to it, and it''s completely reliable. By the way, I think everything above is correct, but I was typing a little quickly (I have to go out), so some details might be a little off...

Insert [CENSORED] here.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
cclements
cclements
Thanks for the tips. Looks like I have some study ahead of me.
No signature files!!! =)
Rellik
Rellik
Hmmm... when you move around the model like that, with the Pushing and the Popping and the translating, wouldn''t that make collision detection difficult? If you need to know the location of the vertices you are comparing for collision, and one set has been translated or rotated while the other set hasn''t, how do you record the absolute value of all the vertices in one matrix (or, if I used "matrix" incorrectly, in one continuous space without any translations or rotations)?
End of Post
pjcast
pjcast
I would suggest using a Hierarchical scene graph. Basically, you have a root node (world). You can add as many child nodes or objects to each node you create. The render loop traverses down all its nodes/objects to render scene. Just do a searc on Hierarchical scene graph and you will sure find some complete source for that type of scene manager.

But how it makes life easier:

Create a child node of root, name it "TankNode". To that child node you add a tank mesh. Create a child node of "TankMesh", call it "TurretNode", and add a turret mesh to it. Create another child node of "TankNode", call it "CannonNode", and add a machine gun mesh.

The beauty of this pattern is that when you rotate your world (Root node) all attached nodes (and hence objects) will rotate with it. Also, animation becomes easier for such things as movable objects on other movable objects. The turret will be able to rotate with out affecting its parent node. However, when the TankNode rotates, all attached nodes will rotate.
cclements
cclements
That sounds reasonable too.
No signature files!!! =)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.