GraphicTriangleMesh.hpp

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Simple Object Loader and Renderer - SOLAR
00006  *
00007  * Read the file "SOLAR-LICENSE" for the license.
00008  *
00009  * Authors & Copyright:
00010  *
00011  * Tommi Ilmonen, 2001-2003, except LWO-code by RJ, 2001-2003
00012  *
00013  * Tommi's email: firstname.lastname@hut.fi
00014  *
00015  */
00016 
00017 #ifndef SOLAR_GRAPHIC_TRIANGLE_MESH_H
00018 #define SOLAR_GRAPHIC_TRIANGLE_MESH_H
00019 
00020 #include <Fluid/Vector2.hpp>
00021 
00022 #include <Solar/BoundingBox.hpp>
00023 #include <Solar/Graphic.hpp>
00024 
00025 #include <vector>
00026 
00027 namespace Solar {
00028 
00029 class GraphicTriangleMesh : public Graphic
00030 {
00031 public:
00032   GraphicTriangleMesh();
00033   virtual ~GraphicTriangleMesh();
00034 
00035   class Triangle {
00036   public:
00037 
00038     uint & vertex(uint i) { return m_vertices[i]; }
00039     const uint & vertex(uint i) const { return m_vertices[i]; }
00040 
00041     uint m_vertices[3];
00042     void clear();
00043     void write(std::ostream *);
00044   };
00045 
00046   class VertexData {
00047   public:
00048     
00049     void scale(const Fluid::Vector3 &v)
00050     {
00051       m_location[0] *= v[0];
00052       m_location[1] *= v[1];
00053       m_location[2] *= v[2];      
00054     }
00055 
00056     void move(const Fluid::Vector3 &v)
00057     { m_location += v; }
00058 
00059     void transform(const Fluid::Matrix3 &m)
00060     {
00061       m_location = m * m_location;
00062       m_normal   = m * m_normal;
00063     }
00064 
00065     Fluid::Vector3 & location() { return m_location; }
00066     Fluid::Vector3 & normal() { return m_normal; }
00067     Fluid::Vector2 & uv() { return m_uv; }
00068 
00069     const Fluid::Vector3 & location() const { return m_location; }
00070     const Fluid::Vector3 & normal() const { return m_normal; }
00071     const Fluid::Vector2 & uv() const { return m_uv; }
00072 
00073     Fluid::Vector3 m_location;
00074     Fluid::Vector3 m_normal;
00075     Fluid::Vector2 m_uv;
00076 
00077     void write(std::ostream *);
00078   };
00079 
00080   virtual Type type() const;
00081   virtual void getBoundingBox(BoundingBox *bbox);
00082   virtual int nofPrimitives() const;
00083   virtual void render(Renderer *);
00084   virtual void scale(const Fluid::Vector3 &);
00085   virtual void move(const Fluid::Vector3 &);
00086   virtual void transform(const Fluid::Matrix3 &);
00087   virtual void write(std::ostream *);
00088 
00089   void clear();
00090 
00091   void addVertex(const VertexData &);
00092   void addTriangle(const Triangle &);
00093   void addTriangle(uint i, uint j, uint k);
00094   
00095   void recalculateBoundingBox();
00096 
00097   uint nofTriangles() const { return m_triangles.size(); }
00098   const Triangle &triangle(uint i) const { return m_triangles[i]; }
00099   void reserveTriangles(uint n) { m_triangles.reserve(n); }
00100 
00101   const VertexData * vertexPtr() const { return &* m_vertices.begin(); }
00102   VertexData & vertex(uint i) { return m_vertices[i]; }
00103   const VertexData & vertex(uint i) const { return m_vertices[i]; }
00104   void reserveVertices(uint n) { m_vertices.reserve(n); }
00105 
00106 protected:
00107 
00108   BoundingBox m_boundingBox;
00109 
00110   std::vector<VertexData> m_vertices;
00111   std::vector<Triangle>   m_triangles;
00112 };
00113 
00114 } // namespace Solar
00115 
00116 #endif

Generated on Mon Mar 12 21:09:00 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6