Panda3D
|
00001 // Filename: physicsObject.h 00002 // Created by: charles (13Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PHYSICS_OBJECT_H 00016 #define PHYSICS_OBJECT_H 00017 00018 #include "pandabase.h" 00019 #include "typedReferenceCount.h" 00020 #include "luse.h" 00021 #include "configVariableDouble.h" 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : PhysicsObject 00025 // Description : A body on which physics will be applied. If you're 00026 // looking to add physical motion to your class, do 00027 // NOT derive from this. Derive from Physical instead. 00028 //////////////////////////////////////////////////////////////////// 00029 class EXPCL_PANDAPHYSICS PhysicsObject : public TypedReferenceCount { 00030 public: 00031 typedef pvector<PT(PhysicsObject)> Vector; 00032 00033 PUBLISHED: 00034 PhysicsObject(); 00035 PhysicsObject(const PhysicsObject ©); 00036 virtual ~PhysicsObject(); 00037 const PhysicsObject &operator =(const PhysicsObject &other); 00038 00039 static ConfigVariableDouble _default_terminal_velocity; 00040 00041 INLINE void set_active(bool flag); 00042 INLINE bool get_active() const; 00043 00044 INLINE void set_mass(PN_stdfloat); 00045 INLINE PN_stdfloat get_mass() const; 00046 00047 //INLINE void set_center_of_mass(const LPoint3 &pos); use set_position. 00048 INLINE void set_position(const LPoint3 &pos); 00049 INLINE void set_position(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z); 00050 INLINE LPoint3 get_position() const; 00051 00052 INLINE void reset_position(const LPoint3 &pos); 00053 00054 INLINE void set_last_position(const LPoint3 &pos); 00055 INLINE LPoint3 get_last_position() const; 00056 00057 INLINE void set_velocity(const LVector3 &vel); 00058 INLINE void set_velocity(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z); 00059 INLINE LVector3 get_velocity() const; 00060 INLINE LVector3 get_implicit_velocity() const; 00061 00062 // Global instantanious forces 00063 INLINE void add_torque(const LRotation &torque); 00064 INLINE void add_impulse(const LVector3 &impulse); 00065 virtual void add_impact( 00066 const LPoint3 &offset_from_center_of_mass, const LVector3 &impulse); 00067 00068 // Local instantanious forces 00069 INLINE void add_local_torque(const LRotation &torque); 00070 INLINE void add_local_impulse(const LVector3 &impulse); 00071 virtual void add_local_impact( 00072 const LPoint3 &offset_from_center_of_mass, const LVector3 &impulse); 00073 00074 INLINE void set_terminal_velocity(PN_stdfloat tv); 00075 INLINE PN_stdfloat get_terminal_velocity() const; 00076 00077 INLINE void set_oriented(bool flag); 00078 INLINE bool get_oriented() const; 00079 00080 INLINE void set_orientation(const LOrientation &orientation); 00081 INLINE LOrientation get_orientation() const; 00082 00083 INLINE void reset_orientation(const LOrientation &orientation); 00084 00085 INLINE void set_rotation(const LRotation &rotation); 00086 INLINE LRotation get_rotation() const; 00087 00088 virtual LMatrix4 get_inertial_tensor() const; 00089 virtual LMatrix4 get_lcs() const; 00090 virtual PhysicsObject *make_copy() const; 00091 00092 #ifndef NDEBUG 00093 void set_name(const string &name) { 00094 _name = name; 00095 } 00096 const string& get_name() { 00097 return _name; 00098 } 00099 #endif 00100 00101 virtual void output(ostream &out) const; 00102 virtual void write(ostream &out, unsigned int indent=0) const; 00103 00104 private: 00105 // physical 00106 LPoint3 _position; // aka _center_of_mass 00107 LPoint3 _last_position; 00108 LVector3 _velocity; // aka _linear_velocity 00109 00110 // angular 00111 LOrientation _orientation; 00112 LRotation _rotation; // aka _angular_velocity 00113 00114 PN_stdfloat _terminal_velocity; 00115 PN_stdfloat _mass; 00116 00117 bool _process_me; 00118 bool _oriented; 00119 00120 #ifndef NDEBUG 00121 string _name; 00122 #endif 00123 00124 public: 00125 static TypeHandle get_class_type() { 00126 return _type_handle; 00127 } 00128 static void init_type() { 00129 TypedReferenceCount::init_type(); 00130 register_type(_type_handle, "PhysicsObject", 00131 TypedReferenceCount::get_class_type()); 00132 } 00133 virtual TypeHandle get_type() const { 00134 return get_class_type(); 00135 } 00136 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00137 00138 private: 00139 static TypeHandle _type_handle; 00140 }; 00141 00142 #include "physicsObject.I" 00143 00144 #endif // __PHYSICS_OBJECT_H__