Panda3D
physxActor.h
1 // Filename: physxActor.h
2 // Created by: enn0x (14Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PHYSXACTOR_H
16 #define PHYSXACTOR_H
17 
18 #include "pandabase.h"
19 #include "nodePath.h"
20 #include "luse.h"
21 
22 #include "physxObject.h"
23 #include "physxObjectCollection.h"
24 #include "physxEnums.h"
25 #include "physx_includes.h"
26 
27 class PhysxController;
28 class PhysxScene;
29 class PhysxShape;
30 class PhysxShapeDesc;
31 class PhysxActorDesc;
32 class PhysxBodyDesc;
33 
34 ////////////////////////////////////////////////////////////////////
35 // Class : PhysxActor
36 // Description : Actors are the main simulation objects. Actors
37 // are owned by a scene (PhysxScene).
38 //
39 // An actor may optionally encapsulate a dynamic rigid
40 // body by setting the body member of the actor's
41 // descriptor when it is created. Otherwise the actor
42 // will be static (fixed in the world).
43 //
44 // Instances of PhysxActor are created by calling
45 // PhysxScene::create_actor() and destroyed by calling
46 // PhysxActor::release().
47 ////////////////////////////////////////////////////////////////////
48 class EXPCL_PANDAPHYSX PhysxActor : public PhysxObject, public PhysxEnums {
49 
50 PUBLISHED:
51  INLINE PhysxActor();
52  INLINE ~PhysxActor();
53 
54  bool save_body_to_desc(PhysxBodyDesc &bodyDesc) const;
55  void save_to_desc(PhysxActorDesc &actorDesc) const;
56 
57  void set_name(const char *name);
58  void set_global_pos(const LPoint3f &pos);
59  void set_global_mat(const LMatrix4f &mat);
60  void set_global_hpr(float h, float p, float r);
61  void set_body_flag(PhysxBodyFlag flag, bool value);
62  void set_actor_flag(PhysxActorFlag flag, bool value);
63  void set_contact_report_flag(PhysxContactPairFlag flag, bool value);
64  void set_contact_report_threshold(float threshold);
65  void set_group(unsigned int group);
66  void set_dominance_group(unsigned int group);
67  void set_shape_group( unsigned int group );
68 
69  const char *get_name() const;
70  LPoint3f get_global_pos() const;
71  LMatrix4f get_global_mat() const;
72  LQuaternionf get_global_quat() const;
73  bool get_body_flag(PhysxBodyFlag flag) const;
74  bool get_actor_flag(PhysxActorFlag flag) const;
75  unsigned int get_group() const;
76  unsigned int get_dominance_group() const;
77 
78  bool is_dynamic() const;
79  float compute_kinetic_energy() const;
80  bool update_mass_from_shapes(float density, float totalMass);
81 
82  PhysxScene *get_scene() const;
83 
84  // NodePath
85  void attach_node_path(const NodePath &np);
86  void detach_node_path();
87  NodePath get_node_path() const;
88 
89  // Shapes
90  unsigned int get_num_shapes() const;
91  PhysxShape *create_shape(PhysxShapeDesc &desc);
92  PhysxShape *get_shape(unsigned int idx) const;
93  PhysxShape *get_shape_by_name(const char *name) const;
94  MAKE_SEQ(get_shapes, get_num_shapes, get_shape);
95 
96  // Forces
97  void add_force(const LVector3f force,
98  PhysxForceMode mode=FM_force, bool wakeup=true);
99  void add_force_at_pos(const LVector3f force, const LPoint3f &pos,
100  PhysxForceMode mode=FM_force, bool wakeup=true);
101  void add_force_at_local_pos(const LVector3f force, const LPoint3f &pos,
102  PhysxForceMode mode=FM_force, bool wakeup=true);
103  void add_torque(const LVector3f torque,
104  PhysxForceMode mode=FM_force, bool wakeup=true);
105  void add_local_force(const LVector3f force,
106  PhysxForceMode mode=FM_force, bool wakeup=true);
107  void add_local_force_at_pos(const LVector3f force, const LPoint3f &pos,
108  PhysxForceMode mode=FM_force, bool wakeup=true);
109  void add_local_force_at_local_pos(const LVector3f force, const LPoint3f &pos,
110  PhysxForceMode mode=FM_force, bool wakeup=true);
111  void add_local_torque(const LVector3f torque,
112  PhysxForceMode mode=FM_force, bool wakeup=true);
113 
114  // Mass manipulation
115  void set_mass(float mass);
116  void set_c_mass_offset_local_mat(const LMatrix4f &mat);
117  void set_c_mass_offset_local_pos(const LPoint3f &pos);
118  void set_c_mass_offset_local_orientation(const LMatrix3f &mat);
119  void set_c_mass_offset_global_mat(const LMatrix4f &mat);
120  void set_c_mass_offset_global_pos(const LPoint3f &pos);
121  void set_c_mass_offset_global_orientation(const LMatrix3f &mat);
122  void set_c_mass_global_mat(const LMatrix4f &mat);
123  void set_c_mass_global_pos(const LPoint3f &pos);
124  void set_c_mass_global_orientation(const LMatrix3f &mat);
125  void set_mass_space_inertia_tensor(const LVector3f &m);
126 
127  float get_mass() const;
128  LMatrix4f get_c_mass_global_mat() const;
129  LPoint3f get_c_mass_global_pos() const;
130  LMatrix3f get_c_mass_global_orientation() const;
131  LMatrix4f get_c_mass_local_mat() const;
132  LPoint3f get_c_mass_local_pos() const;
133  LMatrix3f get_c_mass_local_orientation() const;
134  LVector3f get_mass_space_inertia_tensor() const;
135  LMatrix3f get_global_inertia_tensor() const;
136  LMatrix3f get_global_inertia_tensor_inverse() const;
137 
138  // Damping
139  void set_linear_damping(float linDamp);
140  void set_angular_damping(float angDamp);
141  float get_linear_damping() const;
142  float get_angular_damping() const;
143 
144  // Velocity
145  void set_linear_velocity(const LVector3f &linVel);
146  void set_angular_velocity(const LVector3f &angVel);
147  void set_max_angular_velocity(float maxAngVel);
148 
149  LVector3f get_linear_velocity() const;
150  LVector3f get_angular_velocity() const;
151  float get_max_angular_velocity() const;
152 
153  // Point Velocity
154  LVector3f get_point_velocity(const LPoint3f &point) const;
155  LVector3f get_local_point_velocity(const LPoint3f &point) const;
156 
157  // Momentum
158  void set_linear_momentum(const LVector3f &momentum);
159  void set_angular_momentum(const LVector3f &momentum);
160  LVector3f get_linear_momentum() const;
161  LVector3f get_angular_momentum() const;
162 
163  // Sleeping
164  void set_sleep_linear_velocity(float threshold);
165  void set_sleep_angular_velocity(float threshold);
166  void set_sleep_energy_threshold(float threshold);
167  float get_sleep_linear_velocity() const;
168  float get_sleep_angular_velocity() const;
169  float get_sleep_energy_threshold() const;
170  bool is_sleeping() const;
171  void wake_up(float wakeCounterValue=NX_SLEEP_INTERVAL);
172  void put_to_sleep();
173 
174  // Kinematic
175  void move_global_pos(const LPoint3f &pos);
176  void move_global_mat(const LMatrix4f &mat);
177  void move_global_hpr(float h, float p, float r);
178 
179  INLINE void ls() const;
180  INLINE void ls(ostream &out, int indent_level=0) const;
181 
182 public:
183  void update_transform(const LMatrix4f &m);
184 
185 ////////////////////////////////////////////////////////////////////
186 PUBLISHED:
187  void release();
188 
189 public:
190  INLINE NxActor *ptr() const { return _ptr; };
191 
192  void link_controller(PhysxController *controller);
193  void link(NxActor *ptr);
194  void unlink();
195 
197 
198 private:
199  NxActor *_ptr;
200  NodePath _np;
201  PT(PhysxController) _controller;
202  string _name;
203 
204 ////////////////////////////////////////////////////////////////////
205 public:
206  static TypeHandle get_class_type() {
207  return _type_handle;
208  }
209  static void init_type() {
210  PhysxObject::init_type();
211  register_type(_type_handle, "PhysxActor",
212  PhysxObject::get_class_type());
213  }
214  virtual TypeHandle get_type() const {
215  return get_class_type();
216  }
217  virtual TypeHandle force_init_type() {
218  init_type();
219  return get_class_type();
220  }
221 
222 private:
223  static TypeHandle _type_handle;
224 };
225 
226 #include "physxActor.I"
227 
228 #endif // PHYSXACTOR_H
Abstract base class for shapes.
Definition: physxShape.h:41
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
Abstract base class for character controllers.
This class exists just to provide scoping for the enums shared by PhysX classes.
Definition: physxEnums.h:357
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
Descriptor for PhysxActor.
Actors are the main simulation objects.
Definition: physxActor.h:48
Abstract base class for shape descriptors.
This is the base quaternion class.
Definition: lquaternion.h:96
Descriptor for the optional rigid body dynamic state of PhysxActor.
Definition: physxBodyDesc.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165