Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

object.h

Go to the documentation of this file.
00001 
00008 #ifndef _OBJECT_H
00009 #define _OBJECT_H
00010 
00011 #include "main.h"
00012 #include "actor.h"
00013 #include "odeutils.h"
00014 
00015 #include <gfx/vec4.h>
00016 #include <gfx/mat4.h>
00017 #include <gfx/quat.h>
00018 
00019 #include <ode/ode.h>
00020 
00021 class Object;
00022 class PhysicalEffect;
00023 class Effect;
00024 class Model;
00025 class Camera;
00026 
00031 typedef void (Object::*EffectHandler)(Effect *);
00032 
00041 class Object : public Actor {
00042 public:
00054     Object( Model *model, Vec3 position = Vec3( 0.0, 0.0, 0.0 ), dMatrix3 orientation = NULL, Vec3 scale = Vec3( 1.0, 1.0, 1.0 ), double mass = 1.0, bool on = false, bool stationary = true, bool movable = false, const bool rotatable[3] = NULL);
00055     virtual ~Object( void );
00056 
00064     virtual EffectHandler get_effect_handler( Effect *effect );
00065 
00070     virtual void render( bool selected = false );
00071 
00075     void draw_decor( const Vec3& color );
00076 
00077     virtual void apply_transform( void );
00078 
00079     virtual void tick( double t ) {}
00080 
00081     // keep the object's "sim" positions/orientations updated, and reset them
00082     // when necessary
00083     virtual void start_sim( void );
00084     virtual void stop_sim( void );
00085 
00087     virtual void collide( dContact* contact );
00088 
00090 
00096     void set_id( int id ) { _id = id; }
00097     void set_position( const Vec3& pos ) { dBodySetPosition( _body_id, pos[ 0 ], pos[ 1 ], pos[ 2 ] ); }
00098     void set_orientation_mat( const dMatrix3 orientation ) { dBodySetRotation( _body_id, orientation ); }
00099     void set_orientation_quat( const dQuaternion orientation ) { dBodySetQuaternion( _body_id, orientation ); }
00100     //void set_mass( double m ) { _mass = m; }
00101     void set_scale( const Vec3 s ) { _scale = s; }
00102     void set_stationary( const bool s ) { if( ( _stationary = s ) ) dBodyDisable( _body_id ); else dBodyEnable( _body_id ); }
00103     void set_movable( const bool s ) { _movable = s; }
00104     void set_rotatable( const bool s[3] )
00105         { _rotatable[0] = s[0]; _rotatable[1] = s[1]; _rotatable[2] = s[2]; }
00106     void set_ethereal( const bool e ) { _ethereal = e; }
00107     void set_on( const bool o ) { _on = o; }
00108     void set_bbox_color( const Vec3& v ) { _bbox_color = v; }
00109 
00110     int get_id( ) const { return _id; }
00111     Vec3 get_position( void ) const { const float* pos = dBodyGetPosition( _body_id ); return Vec3( pos[ 0 ], pos[ 1 ], pos[ 2 ] ); }
00112     void get_orientation_mat( dMatrix3 dmat3 ) const { dRealPtrTodMatrix3( dmat3, dBodyGetRotation( _body_id ) ); }
00113     Mat4 get_orientation_mat( ) const { Mat4 m; dMatrix3ToMat4( m, dBodyGetRotation( _body_id ) ); return m; }
00114     void get_orientation_quat( dQuaternion dquat ) const { dRealPtrTodQuaternion( dquat, dBodyGetQuaternion( _body_id ) ); }
00115     Quat get_orientation_quat( ) const { Quat q; dQuaternion_to_quat( q, dBodyGetQuaternion( _body_id ) ); return q; }
00116     Vec3 get_forward_vec( ) const { return get_orientation_mat() * Vec3( 0, 0, 1 ); }
00117     Vec3 get_up_vec( ) const { return get_orientation_mat() * Vec3( 0, 1, 0 ); }
00118     virtual double get_mass( void ) const { dMass dm; dBodyGetMass( _body_id, &dm ); return dm.mass; }
00119     virtual Vec3 get_scale( void ) const { return _scale; }
00120     virtual bool is_stationary( void ) const { return _stationary; }
00121     virtual bool is_movable( void ) const { return _movable; }
00122     virtual bool is_rotatable( int i ) const { return _rotatable[i]; }
00123     virtual bool is_ethereal( void ) const { return _ethereal; }
00124     virtual bool is_on( void ) const { return _on; }
00125     virtual Vec3 get_bbox_color( ) const { return _bbox_color; }
00126     virtual Model *get_model( ) const { return _model; }
00127     virtual string get_type_str( ) const { return "object"; }
00128     virtual string get_info( ) const;
00129 
00130     Vec3 get_init_position( void ) const { return _init_position; }
00131     void get_init_orientation_mat( dMatrix3 dmat3 ) const { dQtoR( _init_orientation, dmat3 ); }
00132     void get_init_orientation_quat( dQuaternion dquat ) const { dRealPtrTodQuaternion( dquat, _init_orientation ); }
00133     bool is_sim_on( void ) const { return _sim_on; }
00134 
00135     const dBodyID get_body_id() { return _body_id; }
00136     const dGeomID get_geom_id() { return _geom_id; }
00137 
00138     void enable_body( void ) { dBodyEnable( _body_id ); }
00139     void disable_body( void ) { dBodyDisable( _body_id ); }
00140 
00142 protected:
00143     Model* _model;              
00144 
00145     Vec3 _scale;                
00146 
00147     int _id;
00148 
00149     dBodyID _body_id;
00150     dGeomID _geom_id;
00151 
00152     Vec3 _init_position;
00153     dQuaternion _init_orientation;
00154     bool _sim_on;
00155 
00156     dMass _mass;
00157 
00158     void setup_geom( void );
00159 
00160     bool _stationary;           
00161     bool _movable;              
00162     bool _rotatable[3];         
00163     bool _ethereal;             
00164 
00165     bool _on;                   
00166 
00167     Vec3 _bbox_color;
00168 private:
00169 
00179     void _handle_physical_effect( PhysicalEffect *effect );
00180 
00181 };
00182 
00183 #endif // header guard

Generated on Sat Mar 13 15:00:10 2004 by doxygen 1.3.5