1 #pragma once
2 
3 //********************************************************************************************
4 //*
5 //*    This file is part of Egoboo.
6 //*
7 //*    Egoboo is free software: you can redistribute it and/or modify it
8 //*    under the terms of the GNU General Public License as published by
9 //*    the Free Software Foundation, either version 3 of the License, or
10 //*    (at your option) any later version.
11 //*
12 //*    Egoboo is distributed in the hope that it will be useful, but
13 //*    WITHOUT ANY WARRANTY; without even the implied warranty of
14 //*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //*    General Public License for more details.
16 //*
17 //*    You should have received a copy of the GNU General Public License
18 //*    along with Egoboo.  If not, see <http://www.gnu.org/licenses/>.
19 //*
20 //********************************************************************************************
21 ///
22 /// @file md2.h
23 /// @brief Md2 Model display routines
24 /// @details Adapted from "Tactics - MD2_Model.h" by Jonathan Fischer
25 ///   A class for loading/using Quake 2 and Egoboo md2 models.
26 ///   Creating/destroying objects of this class is done in the same fashion as
27 ///   Textures, so see Texture.h for details.
28 /// @note You will routinely include "md2.h" only in headers (*.h) files where you need to declare an
29 ///       struct defined in this file. In *.inl files or *.c/*.cpp files you will routinely include "md2.inl", instead.
30 
31 #include "id_md2.h"
32 
33 #include "egoboo_typedef.h"
34 #include "physics.h"
35 
36 //--------------------------------------------------------------------------------------------
37 //--------------------------------------------------------------------------------------------
38 
39 #define EGO_NORMAL_COUNT  (MD2_MAX_NORMALS + 1)
40 #define EGO_AMBIENT_INDEX  MD2_MAX_NORMALS
41 
42 //--------------------------------------------------------------------------------------------
43 // MD2_Vertex_t
44 //--------------------------------------------------------------------------------------------
45 
46 struct s_ego_md2_vertex
47 {
48     fvec3_t pos;
49     fvec3_t nrm;
50     int     normal;  ///< index to id-normal array
51 
52 };
53 typedef struct s_ego_md2_vertex MD2_Vertex_t;
54 
55 //--------------------------------------------------------------------------------------------
56 // MD2_TexCoord_t
57 //--------------------------------------------------------------------------------------------
58 
59 struct s_ego_md2_texcoord
60 {
61     fvec2_t tex;
62 };
63 typedef struct s_ego_md2_texcoord MD2_TexCoord_t;
64 
65 //--------------------------------------------------------------------------------------------
66 // MD2_Frame_t
67 //--------------------------------------------------------------------------------------------
68 
69 struct s_ego_md2_frame
70 {
71     char          name[16];
72 
73     size_t        vertex_count;
74     MD2_Vertex_t *vertex_lst;
75 
76     oct_bb_t      bb;             ///< axis-aligned octagonal bounding box limits
77     int           framelip;       ///< the position in the current animation
78     BIT_FIELD     framefx;        ///< the special effects associated with this frame
79 };
80 typedef struct s_ego_md2_frame MD2_Frame_t;
81 
82 //--------------------------------------------------------------------------------------------
83 // MD2_Triangle_t
84 //--------------------------------------------------------------------------------------------
85 
86 typedef id_md2_triangle_t MD2_Triangle_t;
87 
88 //--------------------------------------------------------------------------------------------
89 // MD2_SkinName_t
90 //--------------------------------------------------------------------------------------------
91 
92 typedef id_md2_skin_t MD2_SkinName_t;
93 
94 //--------------------------------------------------------------------------------------------
95 // MD2_GLCommand_t
96 //--------------------------------------------------------------------------------------------
97 
98 struct s_ego_md2_glcommand
99 {
100     struct s_ego_md2_glcommand * next;
101 
102     GLenum              gl_mode;
103     signed int          command_count;
104     id_glcmd_packed_t * data;
105 };
106 typedef struct s_ego_md2_glcommand MD2_GLCommand_t;
107 
108 void MD2_GLCommand_ctor( MD2_GLCommand_t * m );
109 void MD2_GLCommand_dtor( MD2_GLCommand_t * m );
110 
111 MD2_GLCommand_t * MD2_GLCommand_create( void );
112 MD2_GLCommand_t * MD2_GLCommand_new_vector( int n );
113 void              MD2_GLCommand_destroy( MD2_GLCommand_t ** m );
114 void              MD2_GLCommand_delete_vector( MD2_GLCommand_t * v, int n );
115 
116 //--------------------------------------------------------------------------------------------
117 // MD2_Model_t
118 //--------------------------------------------------------------------------------------------
119 
120 struct s_ego_md2_model
121 {
122     int m_numVertices;
123     int m_numTexCoords;
124     int m_numTriangles;
125     int m_numSkins;
126     int m_numFrames;
127     int m_numCommands;
128 
129     MD2_SkinName_t  *m_skins;
130     MD2_TexCoord_t  *m_texCoords;
131     MD2_Triangle_t  *m_triangles;
132     MD2_Frame_t     *m_frames;
133     MD2_GLCommand_t *m_commands;
134 
135 };
136 typedef struct s_ego_md2_model MD2_Model_t;
137 
138 // CTORS
139 MD2_Model_t * MD2_Model_ctor( MD2_Model_t * m );
140 MD2_Model_t * MD2_Model_dtor( MD2_Model_t * m );
141 MD2_Model_t * MD2_Model_create( void );
142 void          MD2_Model_destroy( MD2_Model_t ** m );
143 MD2_Model_t * MD2_Model_new_vector( int n );
144 void          MD2_Model_delete_vector( MD2_Model_t * v, int n );
145 
146 //--------------------------------------------------------------------------------------------
147 // EXTERNAL VARIABLES
148 //--------------------------------------------------------------------------------------------
149 
150 extern float kMd2Normals[EGO_NORMAL_COUNT][3];
151 
152 //--------------------------------------------------------------------------------------------
153 // GLOBAL FUNCTION PROTOTYPES
154 //--------------------------------------------------------------------------------------------
155 
156 MD2_Model_t * md2_load( const char * szFilename, MD2_Model_t* m );
157 void          md2_free( MD2_Model_t * m );
158 void          md2_scale_model( MD2_Model_t * pmd2, float scale_x, float scale_y, float scale_z );
159 
160 //--------------------------------------------------------------------------------------------
161 //--------------------------------------------------------------------------------------------
162 
163 #define _egoboo_md2_h
164