vee_polygon.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00020 #ifndef VEE_POLYGON_H
00021 #define VEE_POLYGON_H
00022 
00023 #include <vee_particle.h>
00024 
00025 #include <vee_vector2.h>
00026 
00027 #include <vector>
00028 
00029 class VEE_Polygon : public VEE_Particle
00030 {
00031 public:
00032 
00033   VEE_Polygon();
00034 
00035   VEE_Polygon(uint num, const VEE_Vector3 *positions,
00036         uint numTri, const uint *indices,
00037         const VEE_Vector3 &velocity,
00038         float ageLimit, int material = -1,
00039         VEE_Looks *looks = 0);
00040   virtual ~VEE_Polygon();
00041 
00042   virtual bool setValue(const char *, VEE_Value *);
00043 
00044   virtual VEE_Polygon *clone() const;
00045 
00046   static VEE_Polygon * createNewMesh(const uint horizontalDivisions,
00047              const uint verticalDivisions,
00048              float width = 1.0,
00049              float height = 1.0,
00050              float ageLimit = 10000.0);
00051   static VEE_Polygon * createNewQuadMesh(const uint horizontalDivisions,
00052            const uint verticalDivisions,
00053            float width = 1.0,
00054            float height = 1.0,
00055            float ageLimit = 10000.0);
00056 
00058   virtual void resetLinks();
00060   virtual void resetDistances();
00061 
00062   virtual void updateVelocity(float dt);
00063   virtual void update(float dt);
00064 
00065   void printTextureUV();
00066 
00067   void transform(const VEE_Matrix3 &);
00068   void move(const VEE_Vector3 &);
00069 
00070   virtual void render(VEE_Renderer *);
00071 
00072   virtual void setStiffness(float s) { m_stiffness = s; }
00074   // virtual void setVertices(VEE_Vector3 *va, uint *vi);
00075   virtual void setTextureCoordinates(const std::vector<VEE_Vector2> &coords) 
00076   { m_vertexTextureCoordinates = coords; }
00078   virtual void setLinks(std::vector<uint> links)
00079   { m_links = links; resetDistances(); }
00080   virtual void setVelocity(const VEE_Vector3 &v);
00081 
00082   uint vertexCount() const { return m_n; }
00083   VEE_Vector3 &getVertex(uint i) { return m_vertexPositions[i]; }
00084 
00085   uint triangleCount() const { return m_nTri; }
00086 
00087   const uint *getTriangle(uint i) const { return & m_indices[i * 3]; }
00088   
00089   VEE_Vector2 &getTextureCoordinate(uint i) 
00090   { return m_vertexTextureCoordinates[i]; }
00091 
00092   void setMaterial(int m) { m_material = m; }
00093   int getMaterial() const { return m_material; }
00094 
00095   uint getMeshColumns() { return m_meshColumns; }
00096   uint getMeshRows() { return m_meshRows; }
00097 
00098 protected:
00099 
00100   // nullify tensions
00101   void initTensions();
00102   // re-evaluate tensions
00103   void evaluateTensions();
00104 
00105   std::vector<VEE_Vector3> m_gravForces;
00106   std::vector<VEE_Vector3> m_dragForces;
00107   // all the vertices (n)
00108   std::vector<VEE_Vector3> m_vertexPositions;
00109   std::vector<VEE_Vector3> m_vertexVelocities;
00110   std::vector<VEE_Vector2> m_vertexTextureCoordinates;
00111   // Table of indices defining the triangles, clockwise ((n-2)*3).
00112   // First index is 0.
00113   std::vector<uint> m_indices;
00114   // Index pairs defining the links. As a default
00115   // this is based on the triangles defined in *m_indices.
00116   std::vector<uint> m_links;
00117   // Optimal distances between vertices for all the links
00118   // present.
00119   std::vector<float> m_distances;
00120   // Tensions between the two vertices. Based on
00121   // *m_distances
00122   std::vector<float> m_tensions;
00123   // maximum tension, same for all the links in the polygon
00124   float m_maxTension;
00125   // Defines how strongly the polygon tries to maintain
00126   // its shape.
00127   float m_stiffness;
00128   // number of vertices n, n >= 3
00129   uint m_n;
00130   // number of triangles
00131   uint m_nTri;
00132   // number of links
00133   uint m_nLinks;
00134   uint m_meshColumns;
00135   uint m_meshRows;
00136 
00137   int  m_material;
00138 };
00139 
00140 #endif

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