FPS Animations

Pages: 12
I'm currently developing an FPS game with GLUT and C++. I have an XML file that defines every weapon in the game, including its OBJ model and MAT texture material. I am attempting to define certain aspects of the animation in the Weapons.xml file. How do I define a switch, reload, and fire recoil animation in my XML file? Any suggestions?
The XML file is solely determined by how you want to do it.

Something like:
<weapon id="smg_1">
// etc 

Last edited on
I meant literally, like how do I program the game to recognize stuff in the XML doc and apply it to the game?
Look at the available XML Parsers. Otherwise you have to write your own text interpreter for it
So I'll have to make a custom XML parser? Okay, thanks. Now how do I create the reload animation in the window?
Can you do any drawing that you can see? IE, make GLUT draw the teapot?
Last edited on
At the moment, no. I have read a tutorial, but it's for Visual Studio. I use Code::Blocks 12.11, so I don't know how to setup GLUT in C::B.
You will either have to use an XML parsing library or write one of your own. Personally, I wrote some functions of my own for similar purposes.

Well, playing animation clips from your XML file requires having implemented some features prior to that in your engine. I.e. : enabling a viewport in your window, displaying static meshes (using OpenGL in your case), and probably -- although it's not necessary for simply playing the clips -- to have your program effectively receiving and registering keyboard input.

So, your first objective would likely be to parse your XML file, get the directories for your OBJ file, then open that OBJ file, parse it, and store the data in it (vertices, UVsets, normals, faces, textures) in a C++ class that you'll have defined for this purpose (probably involving dynamic arrays or std::vectors for storing all this information).

At this point, you should be able to render your static character, environment, etc, using OpenGL.

Once that's done, reading animation clips involves reading the data that compose these (from your XML file format): they are -- assuming skeletal animation -- : a skeleton hierarchy that is bound to your character mesh, a source to determine per-vertex skinning weights for the animation of the mesh (which can be in the form of an array of data in your file, or a set of grayscale textures you'll have to open and sample your values from, depending on the way you exported your skeletal animation data), and a number of interpolation data specifications for your animation keyframes (for each animation clip). The exact way these are defined in your file depend on the type of exported file you have your character in -- for example an ASCII FBX file would define the same information with different syntax and internal structure than a COLLADA file. So at this point, the format your parser will have to read depends on your exported filetype, and you should look into the documentation of that file type for the way all these are represented inside it.

So, at this point, to play the animation clips, you'd have to apply the animation specified in the clips to your skeleton hierarchy, which in turn will affect the vertices of your mesh by a percentage of the original rotation value of the skeletal joint -- which depends on the weight value you have stored for that vertex in respect to that joint. So, a 100% weight for that joint would amount to a 100% influence in that vertex for that rotation, and a 0% would amount to 0% for that vertex, and any other weighting value would amount to an intermediate amount of rotation. I.e., for a 50% weighting for a given vertex, and assuming that your joint has rotated 90 degrees, would allow the vertex to rotate around the joint's local pivot/origin for 90*(50%)=45 degrees, while, as a second example, a 100% percent weight would amount to 90*(100%)=90 degrees for that same vertex.

You would have to get the time difference since your last frame of animation, and use interpolation between your skeletal animation keyframes to calculate the position of your vertices for your next frame. Then render that frame, and keep doing that until your animation clip plays through.

Also, you may want to look into freeGLUT, since as far as I know GLUT has stopped being maintained and this makes it harder to integrate with newer libraries and development environments.

Last edited on
Also, for an FPS, fire, recoil and switch weapon animations would not necessarily have to use skeletal animation. They could involve keyframes for transformations involving object movement, rotation, or scaling. The idea is the same for reading them from the file, except that you wouldn't have a skeleton and weights. You'd have to simply apply the animation on them as whole objects/meshes, based on the time difference since your last frame. However, your other characters, which will will be visible to you as you move around the game world, will likely involve skeletal animation, whose process of implementation is the one I described above.
Last edited on

Do you happen to have a tutorial document/video I could see/watch?
yes you would need an XML parser or write your own. (shouldnt be too hard) but you might want to add file io privileges to the XML file. XML is easy to edit by simply opening it up in a txt editor
R3C0N will be open-source, so there is no need for source protection. Can anyone make a small tutorial about this?:

enabling a viewport in your window, displaying static meshes (using OpenGL in your case), and probably to have your program effectively receiving and registering keyboard input.
im just saying that your game could be modified through the xml file to make it "easier"

ps. Rastertek is good for Dx and Opengl basics, but the terrain tutorial doesnt have anything for Opengl
OBJ files have no sense of animation, they are simply a list of vertices, normals, and texture coords (a few other things too). In order to animate an OBJ you need either glTranslate/glRotate or export one OBJ for each frame.
yeah OBJ is a bad format for animation. unfourtunately i only know a good format for Directx
So what format do you recommend for animation? *.3ds? I have DLed Blender and I guess now have a more advanced 3D editor...
well I have heard some about .md3, .3ds is somewhat supported for animation but it is not the best. if you used directx you could go with .x. do a little research. I'm sure you will find something

by the way if you can 3d model do you know a good tutorial. this is the one thing that has kept me from writing games

I am looking at them right now. I just got a good tutorial collection:


I just found out that you can model via blueprint background image :P
thanks I'm 14 I can program but I cant simply model
Pages: 12