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?
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.
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.
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.