Exemple simple d'implémentation d'un mesh
Un article de MonWiki.
En construction...
[modifier]
Vertex.h
#ifndef __VERTEX_H__ #define __VERTEX_H__ #include <vector> using std::vector; // Vertex est minimal, car on est ammené à en stocker un grand nombre. struct Vertex { Vertex(float f1, float f2, float f3) : x(f1), y(f2), z(f3) {} void set(float f1, float f2, float f3); // permet la réutilisation d'un Vertex const float* getVertex3fv() const; // utile pour la lisibilité des appels OpenGL float x, y, z; }; // Structure stockant une face polygonale. Seul les indices des vertices sont mémorisés. struct PolygonFace { void addVertNormTex(int vi, int ni, int ti) { v.push_back(vi); vn.push_back(ni); vt.push_back(ti); } vector<int> v; // vertex indices vector<int> vn; // normal indices vector<int> vt; // texture indices }; #endif //__VERTEX_H__
[modifier]
Mesh.h
#ifndef __MESH_H__ #define __MESH_H__ #include <vector> #include <iostream> #include "Vertex.h" using std::istream; using std::vector; class Mesh { public: Mesh(istream& is); void draw() const; private: vector<Vertex> vVertices; // Vertex data vector<Vertex> vNormals; // Normal data vector<Vertex> vTexCoords; // Texture coordinates (u, v, w) vector<PolygonFace> vFaces; // Face data }; #endif //__MESH_H__