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