GraphicTriangles.hpp

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

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