iCub-main
MS3D.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4 * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
5 * Author: Ronny André Reierstad, Vadim Tikhanoff
6 * email: vadim.tikhanoff@iit.it
7 * website: www.robotcub.org
8 * Permission is granted to copy, distribute, and/or modify this program
9 * under the terms of the GNU General Public License, version 2 or any
10 * later version published by the Free Software Foundation.
11 *
12 * A copy of the license can be found at
13 * http://www.robotcub.org/icub/license/gpl.txt
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details
19 */
20 
21 // Thanks to Brett Porter and Mete Ciragan for help with this MS3D model loading code
22 
31 #ifndef MS3D_H
32 #define MS3D_H
33 
34 //#include "ace/limits.h"
35 #ifdef WIN32
36 #include <windows.h>
37 #endif
38 
39 #include "SDL.h"
40 #include "SDL_opengl.h"
41 
42 //#ifdef HAVE_APPLE_OPENGL_FRAMEWORK
43 //#include <OpenGL/gl.h>
44 //#include <OpenGL/glu.h>
45 //#else
46 //#include <GL/gl.h>
47 //#include <GL/glu.h>
48 //#endif
49 
50 #include <iostream>
51 #include <fstream>
52 #include "rendering.h"
53 
54 /*
55  MS3D STRUCTURES
56 */
57 #ifdef _MSC_VER // byte-align structures
58 #pragma pack( push, packing )
59 #pragma pack( 1 )
60 #define PACK_STRUCT
61 
62 #ifndef PATH_MAX
63  #define PATH_MAX _MAX_PATH
64 #endif
65 
66 #elif defined( __GNUC__ )
67 #define PACK_STRUCT __attribute__((packed))
68 #include <limits.h>
69 #else
70 # error you must byte-align these structures with the appropriate compiler directives
71 #endif
72 
73 namespace ms3d {
74  typedef unsigned char byte;
75  typedef unsigned short word;
76 }
77 
78 struct MS3DHeader // File Header
79 {
80  char m_ID[10];
81  int m_version;
82 } PACK_STRUCT;
83 
84 struct MS3DVertex // Vertex info
85 {
87  float m_vertex[3];
88  char m_boneID;
90 } PACK_STRUCT;
91 
92 struct MS3DTriangle // Triangle info
93 {
96  float m_vertexNormals[3][3];
97  float m_s[3], m_t[3];
100 } PACK_STRUCT;
101 
102 struct MS3DMaterial // Material info
103 {
104  static unsigned int Texture[200];
105 
106  char m_name[32];
107  float m_ambient[4];
108  float m_diffuse[4];
109  float m_specular[4];
110  float m_emissive[4];
111  float m_shininess; // 0.0f - 128.0f
112  float m_transparency; // 0.0f - 1.0f
113  ms3d::byte m_mode; // 0, 1, 2 (unused now)
114  char m_texture[128];
115  char m_alphamap[128];
116 } PACK_STRUCT;
117 
118 #ifdef _MSC_VER // Default alignment
119 #pragma pack( pop, packing )
120 #endif
121 
122 #undef PACK_STRUCT
123 
124 struct Mesh // Mesh struct
125 {
129 };
130 
131 struct Material // Material properties
132 {
133  float m_ambient[4], m_diffuse[4], m_specular[4], m_emissive[4];
134  float m_shininess;
135  GLuint m_texture;
137 };
138 
139 struct Triangle // Triangle struct
140 {
141  float m_vertexNormals[3][3];
142  float m_s[3], m_t[3];
144 };
145 
146 struct Vertex // Vertex struct
147 {
148  char m_boneID;
149  float m_location[3];
150 };
151 
152 
153 
155 //The Model Class
157 class Model
158 {
159  public:
160 
161  Model();
162 
163  virtual ~Model();
164 
165  bool loadModelData( const char *filename );
166 
167  void draw(bool wireframed, int TextureNumber);
168 
169  void reloadTextures();
170 
171  protected:
172 
175 
178 
181 
184 };
185 
186 
187 
188 #endif
189 
190 
191 //Ronny André Reierstad
192 //www.morrowland.com
193 //apron@morrowland.com
194 
Model::m_pMaterials
Material * m_pMaterials
Definition: MS3D.h:177
MS3DTriangle::m_groupIndex
ms3d::byte m_groupIndex
Definition: MS3D.h:99
Triangle::m_vertexNormals
float m_vertexNormals[3][3]
Definition: MS3D.h:141
Triangle
Definition: MS3D.h:139
MS3DHeader
Definition: MS3D.h:78
MS3DVertex::m_flags
ms3d::byte m_flags
Definition: MS3D.h:86
Material::m_ambient
float m_ambient[4]
Definition: MS3D.h:133
ms3d::word
unsigned short word
Definition: MS3D.h:75
Model::m_numTriangles
int m_numTriangles
Definition: MS3D.h:179
Material::m_pTextureFilename
char * m_pTextureFilename
Definition: MS3D.h:136
Vertex::m_boneID
char m_boneID
Definition: MS3D.h:148
ms3d::byte
unsigned char byte
Definition: MS3D.h:74
Model::loadModelData
bool loadModelData(const char *filename)
Definition: MS3D.cpp:86
MS3DMaterial::m_alphamap
char m_alphamap[128]
Definition: MS3D.h:115
MS3DMaterial::m_transparency
float m_transparency
Definition: MS3D.h:112
MS3DVertex::m_boneID
char m_boneID
Definition: MS3D.h:88
ms3d
Definition: MS3D.h:73
MS3DTriangle::m_t
float m_t[3]
Definition: MS3D.h:97
Mesh
Definition: MS3D.h:124
Triangle::m_s
float m_s[3]
Definition: MS3D.h:142
rendering.h
Header file for the rendering.
MS3DTriangle::m_vertexNormals
float m_vertexNormals[3][3]
Definition: MS3D.h:96
PACK_STRUCT
struct MS3DHeader PACK_STRUCT
Model::Model
Model()
Definition: MS3D.cpp:35
Material::m_specular
float m_specular[4]
Definition: MS3D.h:133
Material::m_shininess
float m_shininess
Definition: MS3D.h:134
MS3DTriangle::m_s
float m_s[3]
Definition: MS3D.h:97
Vertex
Definition: MS3D.h:146
Model::~Model
virtual ~Model()
Definition: MS3D.cpp:47
Mesh::m_pTriangleIndices
int * m_pTriangleIndices
Definition: MS3D.h:128
Model::m_numVertices
int m_numVertices
Definition: MS3D.h:182
Material::m_diffuse
float m_diffuse[4]
Definition: MS3D.h:133
Vertex::m_location
float m_location[3]
Definition: MS3D.h:149
Material::m_emissive
float m_emissive[4]
Definition: MS3D.h:133
Model::draw
void draw(bool wireframed, int TextureNumber)
Definition: MS3D.cpp:213
MS3DVertex
Definition: MS3D.h:84
MS3DMaterial::m_diffuse
float m_diffuse[4]
Definition: MS3D.h:108
Material
Definition: MS3D.h:131
MS3DTriangle::m_flags
ms3d::word m_flags
Definition: MS3D.h:94
Mesh::m_numTriangles
int m_numTriangles
Definition: MS3D.h:127
Mesh::m_materialIndex
int m_materialIndex
Definition: MS3D.h:126
MS3DMaterial::m_ambient
float m_ambient[4]
Definition: MS3D.h:107
MS3DVertex::m_refCount
ms3d::byte m_refCount
Definition: MS3D.h:89
Model::m_pVertices
Vertex * m_pVertices
Definition: MS3D.h:183
MS3DTriangle::m_smoothingGroup
ms3d::byte m_smoothingGroup
Definition: MS3D.h:98
MS3DTriangle
Definition: MS3D.h:92
MS3DMaterial::m_mode
ms3d::byte m_mode
Definition: MS3D.h:113
Model
Definition: MS3D.h:157
MS3DMaterial::m_name
char m_name[32]
Definition: MS3D.h:106
Model::m_pTriangles
Triangle * m_pTriangles
Definition: MS3D.h:180
MS3DMaterial::m_texture
char m_texture[128]
Definition: MS3D.h:114
Triangle::m_vertexIndices
int m_vertexIndices[3]
Definition: MS3D.h:143
Model::m_numMeshes
int m_numMeshes
Definition: MS3D.h:173
Material::m_texture
GLuint m_texture
Definition: MS3D.h:135
MS3DMaterial::m_specular
float m_specular[4]
Definition: MS3D.h:109
MS3DMaterial::m_emissive
float m_emissive[4]
Definition: MS3D.h:110
Model::m_pMeshes
Mesh * m_pMeshes
Definition: MS3D.h:174
Triangle::m_t
float m_t[3]
Definition: MS3D.h:142
MS3DHeader::m_ID
char m_ID[10]
Definition: MS3D.h:80
MS3DHeader::m_version
int m_version
Definition: MS3D.h:81
MS3DMaterial
Definition: MS3D.h:102
Model::reloadTextures
void reloadTextures()
Definition: MS3D.cpp:277
MS3DMaterial::m_shininess
float m_shininess
Definition: MS3D.h:111
MS3DMaterial::Texture
static unsigned int Texture[200]
Definition: MS3D.h:104
Model::m_numMaterials
int m_numMaterials
Definition: MS3D.h:176
MS3DVertex::m_vertex
float m_vertex[3]
Definition: MS3D.h:87
MS3DTriangle::m_vertexIndices
ms3d::word m_vertexIndices[3]
Definition: MS3D.h:95