physicsObject.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Filename: physicsObject.h
  2. // Created by: charles (13Jun00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef PHYSICS_OBJECT_H
  19. #define PHYSICS_OBJECT_H
  20. #include "pandabase.h"
  21. #include "typedReferenceCount.h"
  22. #include "luse.h"
  23. #include "configVariableDouble.h"
  24. ////////////////////////////////////////////////////////////////////
  25. // Class : PhysicsObject
  26. // Description : A body on which physics will be applied. If you're
  27. // looking to add physical motion to your class, do
  28. // NOT derive from this. Derive from Physical instead.
  29. ////////////////////////////////////////////////////////////////////
  30. class EXPCL_PANDAPHYSICS PhysicsObject : public TypedReferenceCount {
  31. public:
  32. typedef pvector<PT(PhysicsObject)> Vector;
  33. PUBLISHED:
  34. PhysicsObject();
  35. PhysicsObject(const PhysicsObject &copy);
  36. virtual ~PhysicsObject();
  37. const PhysicsObject &operator =(const PhysicsObject &other);
  38. static ConfigVariableDouble _default_terminal_velocity;
  39. INLINE void set_active(bool flag);
  40. INLINE bool get_active() const;
  41. INLINE void set_mass(float);
  42. INLINE float get_mass() const;
  43. //INLINE void set_center_of_mass(const LPoint3f &pos); use set_position.
  44. INLINE void set_position(const LPoint3f &pos);
  45. INLINE void set_position(float x, float y, float z);
  46. INLINE LPoint3f get_position() const;
  47. INLINE void reset_position(const LPoint3f &pos);
  48. INLINE void set_last_position(const LPoint3f &pos);
  49. INLINE LPoint3f get_last_position() const;
  50. INLINE void set_velocity(const LVector3f &vel);
  51. INLINE void set_velocity(float x, float y, float z);
  52. INLINE LVector3f get_velocity() const;
  53. INLINE LVector3f get_implicit_velocity() const;
  54. // Global instantanious forces
  55. INLINE void add_torque(const LRotationf &torque);
  56. INLINE void add_impulse(const LVector3f &impulse);
  57. virtual void add_impact(
  58. const LPoint3f &offset_from_center_of_mass, const LVector3f &impulse);
  59. // Local instantanious forces
  60. INLINE void add_local_torque(const LRotationf &torque);
  61. INLINE void add_local_impulse(const LVector3f &impulse);
  62. virtual void add_local_impact(
  63. const LPoint3f &offset_from_center_of_mass, const LVector3f &impulse);
  64. INLINE void set_terminal_velocity(float tv);
  65. INLINE float get_terminal_velocity() const;
  66. INLINE void set_oriented(bool flag);
  67. INLINE bool get_oriented() const;
  68. INLINE void set_orientation(const LOrientationf &orientation);
  69. INLINE LOrientationf get_orientation() const;
  70. INLINE void reset_orientation(const LOrientationf &orientation);
  71. INLINE void set_rotation(const LRotationf &rotation);
  72. INLINE LRotationf get_rotation() const;
  73. virtual LMatrix4f get_inertial_tensor() const;
  74. virtual LMatrix4f get_lcs() const;
  75. virtual PhysicsObject *make_copy() const;
  76. #ifndef NDEBUG
  77. void set_name(const string &name) {
  78. _name = name;
  79. }
  80. const string& get_name() {
  81. return _name;
  82. }
  83. #endif
  84. virtual void output(ostream &out) const;
  85. virtual void write(ostream &out, unsigned int indent=0) const;
  86. private:
  87. // physical
  88. LPoint3f _position; // aka _center_of_mass
  89. LPoint3f _last_position;
  90. LVector3f _velocity; // aka _linear_velocity
  91. // angular
  92. LOrientationf _orientation;
  93. LRotationf _rotation; // aka _angular_velocity
  94. float _terminal_velocity;
  95. float _mass;
  96. bool _process_me;
  97. bool _oriented;
  98. #ifndef NDEBUG
  99. string _name;
  100. #endif
  101. public:
  102. static TypeHandle get_class_type() {
  103. return _type_handle;
  104. }
  105. static void init_type() {
  106. TypedReferenceCount::init_type();
  107. register_type(_type_handle, "PhysicsObject",
  108. TypedReferenceCount::get_class_type());
  109. }
  110. virtual TypeHandle get_type() const {
  111. return get_class_type();
  112. }
  113. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  114. private:
  115. static TypeHandle _type_handle;
  116. };
  117. #include "physicsObject.I"
  118. #endif // __PHYSICS_OBJECT_H__