1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Patrick Boenzli |
---|
13 | */ |
---|
14 | |
---|
15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER |
---|
16 | |
---|
17 | #include "md3_model.h" |
---|
18 | |
---|
19 | #include "md3_data.h" |
---|
20 | |
---|
21 | #include "md3_animation_cfg.h" |
---|
22 | |
---|
23 | namespace md3 |
---|
24 | { |
---|
25 | |
---|
26 | /** |
---|
27 | * md3 model |
---|
28 | */ |
---|
29 | MD3Model::MD3Model(std::string filename, float scaling) |
---|
30 | { |
---|
31 | this->md3Data = new MD3Data(filename, filename, scaling); |
---|
32 | |
---|
33 | MD3AnimationCfg cfg("/home/boenzlip/tmp/q3/Downloads/MOH/q3mdl-alien3/models/players/alien3/animation.cfg"); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | MD3Model::~MD3Model() |
---|
39 | {} |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | /** |
---|
44 | * this draws the md3 model |
---|
45 | */ |
---|
46 | void MD3Model::draw() |
---|
47 | { |
---|
48 | //draw current bone frame |
---|
49 | #if 0 |
---|
50 | if( this->bDrawBones) |
---|
51 | { |
---|
52 | //get bone frame, interpolate if necessary |
---|
53 | if( model.interpolationFraction!=0.0 && model.currentFrame!=model.nextFrame) |
---|
54 | //interpolate bone frame |
---|
55 | drawBoneFrame(interpolateBoneFrame(model.boneFrames[model.currentFrame], model.boneFrames[model.nextFrame], model.interpolationFraction)); |
---|
56 | else |
---|
57 | //stick with current bone frame |
---|
58 | drawBoneFrame(model.boneFrames[model.currentFrame]); |
---|
59 | } |
---|
60 | |
---|
61 | //draw all meshes of current frame of this model |
---|
62 | for (int i=0; i<model.meshNum; i++) { |
---|
63 | MD3GLMesh mesh = (MD3GLMesh)model.meshes[i]; |
---|
64 | |
---|
65 | gl.glBlendFunc(mesh.GLSrcBlendFunc, mesh.GLDstBlendFunc); |
---|
66 | gl.glDepthMask(mesh.GLDepthMask); |
---|
67 | if (mesh.textureNum > 0 && mesh.textures[0]!=null) |
---|
68 | gl.glBindTexture(GLEnum.GL_TEXTURE_2D, ((MD3GLTexture)mesh.textures[0]).bind); |
---|
69 | else |
---|
70 | gl.glBindTexture(GLEnum.GL_TEXTURE_2D, 0); |
---|
71 | |
---|
72 | //get mesh frame, do interpolation if necessary |
---|
73 | Vec3[] frame; |
---|
74 | if (model.interpolationFraction!=0.0 && model.currentFrame!=model.nextFrame) |
---|
75 | //interpolate mesh frame between the 2 current mesh frames |
---|
76 | frame=interpolateMeshFrame(mesh.meshFrames[model.currentFrame], mesh.meshFrames[model.nextFrame], model.interpolationFraction); |
---|
77 | else |
---|
78 | //no interpolation needed, just draw current frame |
---|
79 | frame=mesh.meshFrames[model.currentFrame]; |
---|
80 | |
---|
81 | drawMesh(mesh, frame); |
---|
82 | |
---|
83 | //draw vertex normals |
---|
84 | if (canvas.showVertexNormals) { |
---|
85 | //get vertex normals, interpolate if necessary |
---|
86 | if (model.interpolationFraction!=0.0 && model.currentFrame!=model.nextFrame) |
---|
87 | //interpolate vertex normals |
---|
88 | drawVertexNormals(frame, interpolateVertexNormals(mesh.meshVertexNormals[model.currentFrame], mesh.meshVertexNormals[model.nextFrame], model.interpolationFraction)); |
---|
89 | else |
---|
90 | //stick with current vertex normals |
---|
91 | drawVertexNormals(frame, mesh.meshVertexNormals[model.currentFrame]); |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | //draw all models linked to this model |
---|
96 | |
---|
97 | Iterator it=model.linkedModels(); |
---|
98 | while (it.hasNext()) { |
---|
99 | MD3Model child=(MD3Model)it.next(); |
---|
100 | |
---|
101 | //build transformation array m from matrix, interpolate if necessary |
---|
102 | float[] m=new float[16]; |
---|
103 | MD3Tag currFrameTag=model.boneFrames[model.currentFrame].tags[child.getParentTagIndex()]; |
---|
104 | if (model.interpolationFraction!=0.0f && model.currentFrame!=model.nextFrame) { |
---|
105 | //we need to interpolate |
---|
106 | MD3Tag nextFrameTag=model.boneFrames[model.nextFrame].tags[child.getParentTagIndex()]; |
---|
107 | m=interpolateTransformation(currFrameTag, nextFrameTag, model.interpolationFraction); |
---|
108 | } |
---|
109 | else { |
---|
110 | //no interpolation needed, stay with last transformation |
---|
111 | //OpenGL matrix is in column-major order |
---|
112 | m[0] = currFrameTag.matrix[0][0]; m[4] = currFrameTag.matrix[0][1]; m[8] = currFrameTag.matrix[0][2]; m[12] = currFrameTag.position.x; |
---|
113 | m[1] = currFrameTag.matrix[1][0]; m[5] = currFrameTag.matrix[1][1]; m[9] = currFrameTag.matrix[1][2]; m[13] = currFrameTag.position.y; |
---|
114 | m[2] = currFrameTag.matrix[2][0]; m[6] = currFrameTag.matrix[2][1]; m[10]= currFrameTag.matrix[2][2]; m[14] = currFrameTag.position.z; |
---|
115 | m[3] = 0.0f; m[7] = 0.0f; m[11]= 0.0f; m[15] = 1.0f; |
---|
116 | } |
---|
117 | |
---|
118 | //switch to child coord system and draw child |
---|
119 | gl.glPushMatrix(); |
---|
120 | gl.glMultMatrixf(m); |
---|
121 | child.accept(this); |
---|
122 | gl.glPopMatrix(); |
---|
123 | } |
---|
124 | #endif |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | } |
---|