00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef TEDDY__MODELS__MODEL__H
00026 #define TEDDY__MODELS__MODEL__H
00027
00028
00029 #include "Teddy/SysSupport/StdMaths.h"
00030 #include "Teddy/Maths/Matrix.h"
00031 #include "Teddy/Maths/Quaternion.h"
00032 #include "Teddy/Maths/Vector.h"
00033 #include "Teddy/MixIn/Mutex.h"
00034 #include "Teddy/MixIn/Named.h"
00035 #include "Teddy/MixIn/Options.h"
00036 #include "Teddy/SysSupport/StdList.h"
00037 #include "Teddy/SysSupport/Types.h"
00038 #include "SDL_thread.h"
00039
00040
00041
00042 namespace Teddy {
00043 namespace Materials { class Material; };
00044 namespace PhysicalComponents { class Projection; };
00045 }
00046
00047
00048 namespace Teddy {
00049 namespace Models {
00050
00051
00052 class Geometry;
00053 class Element;
00054 class Vertex;
00055
00056
00061 class Model
00062 :
00063 public Teddy::MixIn::Mutex,
00064 public Teddy::MixIn::Named,
00065 public Teddy::MixIn::Options
00066 {
00067 public:
00068 static const unsigned long OPT_VISIBLE;
00069 static const unsigned long OPT_RECURS_MATERIAL;
00070
00071 public:
00072
00073 Model( std::string name, Model *shape = NULL );
00074
00075 Teddy::Maths::Matrix getLocalToWorldMatrix() const;
00076 Teddy::Maths::Matrix getWorldToLocalMatrix() const;
00077 Teddy::Maths::Matrix getViewMatrix () const;
00078 Teddy::Maths::Matrix getModelMatrix ( Model *camera ) const;
00079 Teddy::Maths::Matrix getScaledModelMatrix ( Model *camera ) const;
00080
00081 void doMaterial ( Teddy::PhysicalComponents::Projection *p, Model *parent = NULL );
00082 virtual void draw ( Teddy::PhysicalComponents::Projection *p, Model *parent = NULL );
00083
00084 list<Model*> &getChildren();
00085 void add ( Model *child );
00086 void remove ( Model *child );
00087 Geometry *getGeometry() const;
00088 void setGeometry( Geometry *g );
00089 virtual Teddy::Materials::Material *getMaterial() const;
00090 void setMaterial( Teddy::Materials::Material *m, bool recursive = false );
00091
00092 void applyMaterial ( const Teddy::PhysicalComponents::Projection &p, Teddy::Materials::Material *material );
00093 void setClipRadius ( const double clip_radius );
00094 void setupClipRadius ();
00095 double getClipRadius () const;
00096 void add ( Element *e );
00097 void addTri ( Vertex *a, Vertex *b, Vertex *c );
00098 void addQuad ( Vertex *a, Vertex *b, Vertex *c, Vertex *d );
00099 void addPenta ( Vertex *a, Vertex *b, Vertex *c, Vertex *d, Vertex *e );
00100 void addHexa ( Vertex *a, Vertex *b, Vertex *c, Vertex *d, Vertex *e, Vertex *f );
00101 void addOcta ( Vertex *a, Vertex *b, Vertex *c, Vertex *d, Vertex *e, Vertex *f, Vertex *g, Vertex *h );
00102 void transformVertices( const Teddy::Maths::Matrix &m );
00103 void transformVertices( const Teddy::Maths::Matrix &m, const Teddy::Maths::Matrix &normal_matrix, const bool reverse );
00104 void clearTraversal ();
00105 void truncate ();
00106
00107 Teddy::Maths::Quaternion &getAttitude ();
00108 void copyAttitude ( const Model &other );
00109 Teddy::Maths::TVector<double> vectorTo ( const Model &other ) const;
00110 double distanceTo ( const Model &other ) const;
00111 double distanceTo ( const Teddy::Maths::TVector<double> &pos ) const;
00112 void setPosition ( const double x, const double y, const double z );
00113 void setPosition ( const Teddy::Maths::TVector<double> &v );
00114 Teddy::Maths::TVector<double> getPosition () const;
00115 void transform ( const Teddy::Maths::Matrix &m );
00116 void translate ( const Teddy::Maths::TVector<double> &v );
00117
00118 void roll ( const double radians );
00119 void pitch ( const double radians );
00120 void heading ( const double radians );
00121 void foward ( const double l );
00122
00123 protected:
00124 Teddy::Maths::Quaternion attitude;
00125 Teddy::Maths::TVector<double> position;
00126 double clip_radius;
00127 list<Model*> children;
00128 Geometry *geometry;
00129 Teddy::Materials::Material *material;
00130
00131 protected:
00132 static Teddy::Materials::Material *default_material;
00133 };
00134
00135
00136 };
00137 };
00138
00139
00140 #endif // TEDDY__MODELS__MODEL__H
00141