worldsim/include/wmesh.h

00001 /********************************************************************************
00002  *  WorldSim -- library for robot simulations                                   *
00003  *  Copyright (C) 2008-2011 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef WMESH_H
00021 #define WMESH_H
00022 
00023 #include "worldsimconfig.h"
00024 #include "world.h"
00025 
00026 namespace farsa {
00027 
00041 class FARSA_WSIM_API WMesh : public WObject {
00042     Q_OBJECT
00043 public:
00048     WMesh( World* world, QString name="unamed", const wMatrix& tm = wMatrix::identity() );
00050     virtual ~WMesh();
00052     bool loadMS3DModel( QString filename );
00056     void attachTo( WObject* obj );
00058     WObject* attachedTo() {
00059         return attacho;
00060     };
00062     struct Mesh {
00063         int m_materialIndex;
00064         int m_numTriangles;
00065         int *m_pTriangleIndices;
00066     };
00068     struct Material {
00069         float m_ambient[4], m_diffuse[4], m_specular[4], m_emissive[4];
00070         float m_shininess;
00071         QString m_pTextureFilename;
00072     };
00074     struct Triangle {
00075         float m_vertexNormals[3][3];
00076         float m_s[3], m_t[3];
00077         int m_vertexIndices[3];
00078     };
00080     struct Vertex {
00081         char m_boneID;
00082         float m_location[3];
00083     };
00084 
00086     Mesh* meshes() {
00087         return m_pMeshes;
00088     };
00090     int meshesCount() {
00091         return m_numMeshes;
00092     };
00094     Material* materials() {
00095         return m_pMaterials;
00096     };
00098     int materialsCount() {
00099         return m_numMaterials;
00100     };
00102     Triangle* triangles() {
00103         return m_pTriangles;
00104     };
00106     int trianglesCount() {
00107         return m_numTriangles;
00108     };
00110     Vertex* vertices() {
00111         return m_pVertices;
00112     };
00114     int verticesCount() {
00115         return m_numVertices;
00116     };
00117 private:
00119     WObject* attacho;
00120     //--- Data representing the mesh
00121     int m_numMeshes;
00122     Mesh *m_pMeshes;
00123     int m_numMaterials;
00124     Material *m_pMaterials;
00125     int m_numTriangles;
00126     Triangle *m_pTriangles;
00127     int m_numVertices;
00128     Vertex *m_pVertices;
00129 };
00130 
00131 } // end namespace farsa
00132 
00133 #endif