Panda3D
Loading...
Searching...
No Matches
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"
23#include "physxEnums.h"
24#include "physx_includes.h"
25
26class PhysxController;
27class PhysxScene;
28class PhysxShape;
29class PhysxShapeDesc;
30class PhysxActorDesc;
31class 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 */
44class EXPCL_PANDAPHYSX PhysxActor : public PhysxObject, public PhysxEnums {
45
46PUBLISHED:
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;
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
178public:
179 void update_transform(const LMatrix4f &m);
180
181PUBLISHED:
182 void release();
183
184public:
185 INLINE NxActor *ptr() const { return _ptr; };
186
187 void link_controller(PhysxController *controller);
188 void link(NxActor *ptr);
189 void unlink();
190
192
193private:
194 NxActor *_ptr;
195 NodePath _np;
196 PT(PhysxController) _controller;
197 std::string _name;
198
199public:
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
216private:
217 static TypeHandle _type_handle;
218};
219
220#include "physxActor.I"
221
222#endif // PHYSXACTOR_H
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
Descriptor for PhysxActor.
LPoint3f get_c_mass_global_pos() const
Returns the center of mass position in world space.
void set_c_mass_global_orientation(const LMatrix3f &mat)
Moves the actor by setting the orientation of the center of mass.
void set_name(const char *name)
Sets a name string for the object that can be retrieved with get_name().
void move_global_mat(const LMatrix4f &mat)
The move_global_* calls serve to move kinematically controlled dynamic actors through the game world.
NodePath get_node_path() const
Retrieves a previously attached NodePath.
const char * get_name() const
Retrieves the name string.
void add_local_torque(const LVector3f torque, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies an impulsive torque defined in the actor local coordinate frame to the actor.
void save_to_desc(PhysxActorDesc &actorDesc) const
Saves the state of the actor to the passed descriptor.
LMatrix3f get_global_inertia_tensor_inverse() const
Returns the inverse of the inertia tensor of the actor relative to the world coordinate frame.
void put_to_sleep()
Forces the actor to sleep.
void set_linear_momentum(const LVector3f &momentum)
Sets the linear momentum of the actor.
void add_force_at_local_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies a force (or impulse) defined in the global coordinate frame, acting at a particular point in ...
void set_body_flag(PhysxBodyFlag flag, bool value)
Raise or lower individual BodyFlag flags.
void set_contact_report_threshold(float threshold)
Sets the force threshold for contact reports.
void add_local_force(const LVector3f force, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies a force (or impulse) defined in the actor local coordinate frame to the actor.
void update_transform(const LMatrix4f &m)
Updates the transform of an assigned NodePath.
PhysxShape * get_shape_by_name(const char *name) const
Retrieves an individual shape from the actor's array of shapes.
LVector3f get_angular_momentum() const
Retrieves the angular momentum of an actor.
void set_c_mass_offset_local_pos(const LPoint3f &pos)
Sets the position of the center of mass relative to the actor.
void set_group(unsigned int group)
Assigns the actor to a user defined group of actors.
void set_linear_velocity(const LVector3f &linVel)
Sets the linear velocity of the actor.
void set_dominance_group(unsigned int group)
Assigns dynamic actors a dominance group identifier.
void add_torque(const LVector3f torque, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies an impulsive torque defined in the global coordinate frame to the actor.
void move_global_hpr(float h, float p, float r)
The move_global_* calls serve to move kinematically controlled dynamic actors through the game world.
void set_angular_damping(float angDamp)
Sets the angular damping coefficient.
LMatrix3f get_c_mass_local_orientation() const
Returns the center of mass orientation relative to the actor.
void set_shape_group(unsigned int group)
Sets the collision group for all shapes of this actor.
get_num_shapes
Returns the number of shapes assigned to the actor.
Definition physxActor.h:90
float get_angular_damping() const
Returns the angular damping coefficient.
void set_c_mass_global_mat(const LMatrix4f &mat)
Moves the actor by setting the transform of the center of mass.
LMatrix3f get_global_inertia_tensor() const
Returns the inertia tensor of the actor relative to the world coordinate frame.
bool is_sleeping() const
Returns true if this body is sleeping.
void set_c_mass_offset_local_mat(const LMatrix4f &mat)
Sets the matrix of the center of mass relative to the actor.
void set_c_mass_offset_global_orientation(const LMatrix3f &mat)
Sets the orientation of the center of mass relative to world space.
float get_mass() const
Returns the mass of the actor.
void set_sleep_linear_velocity(float threshold)
Sets the linear velocity below which an actor may go to sleep.
bool update_mass_from_shapes(float density, float totalMass)
Recomputes a dynamic actor's mass properties from its shapes.
LPoint3f get_global_pos() const
Retrieves the actors world space position.
void attach_node_path(const NodePath &np)
Attaches a node path to this actor.
unsigned int get_group() const
Retrieves the actor group this actor is assigned to.
void wake_up(float wakeCounterValue=NX_SLEEP_INTERVAL)
Wakes up the actor if it is sleeping.
void add_local_force_at_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies a force (or impulse) defined in the actor local coordinate frame, acting at a particular poin...
float get_max_angular_velocity() const
Returns the maximum angular velocity permitted for this actor.
PhysxScene * get_scene() const
Retrieves the scene which this actor belongs to.
void add_force(const LVector3f force, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies a force (or impulse) defined in the global coordinate frame to the actor.
float get_sleep_energy_threshold() const
Returns the energy below which an actor may go to sleep.
LMatrix4f get_c_mass_local_mat() const
Returns the center of mass transform relative to the actor.
void add_force_at_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies a force (or impulse) defined in the global coordinate frame, acting at a particular point in ...
PhysxShape * create_shape(PhysxShapeDesc &desc)
Creates a new shape and adds it to the list of shapes of this actor.
bool get_actor_flag(PhysxActorFlag flag) const
Return the specified ActorFlag flag.
bool is_dynamic() const
Returns true if the actor is dynamic.
LVector3f get_linear_momentum() const
Retrieves the linear momentum of an actor.
get_shape
Retrieves an individual shape from the actor's array of shapes.
Definition physxActor.h:90
LVector3f get_linear_velocity() const
Returns the linear velocity of an actor.
float get_sleep_angular_velocity() const
Returns the angular velocity below which an actor may go to sleep.
LMatrix4f get_global_mat() const
Retrieves the actors world space transform.
void set_global_hpr(float h, float p, float r)
Method for setting a dynamic actor's orientation in the world.
void set_max_angular_velocity(float maxAngVel)
Lets you set the maximum angular velocity permitted for this actor.
void add_local_force_at_local_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode=FM_force, bool wakeup=true)
Applies a force (or impulse) defined in the actor local coordinate frame, acting at a particular poin...
void set_actor_flag(PhysxActorFlag flag, bool value)
Raise or lower individual ActorFlag flags.
LPoint3f get_c_mass_local_pos() const
Returns the center of mass position relative to the actor.
void set_c_mass_offset_global_pos(const LPoint3f &pos)
Sets the position of the center of mass relative to world space.
void set_c_mass_global_pos(const LPoint3f &pos)
Moves the actor by setting the position of the center of mass.
LVector3f get_angular_velocity() const
Returns the angular velocity of the actor.
void set_c_mass_offset_local_orientation(const LMatrix3f &mat)
Sets the orientation of the center of mass relative to the actor.
LVector3f get_point_velocity(const LPoint3f &point) const
Computes the velocity of a point given in world coordinates if it were attached to the actor and movi...
LVector3f get_local_point_velocity(const LPoint3f &point) const
Computes the velocity of a point given in body local coordinates as if it were attached to the actor ...
void set_mass(float mass)
Sets the mass of a dynamic actor.
bool get_body_flag(PhysxBodyFlag flag) const
Return the specified BodyFlag flag.
LQuaternionf get_global_quat() const
Retrieves the actors world space orientation.
void detach_node_path()
Detaches a previously assigned NodePath from this actor.
LMatrix4f get_c_mass_global_mat() const
Returns the center of mass transform in world space.
void set_linear_damping(float linDamp)
Sets the linear damping coefficient.
void set_contact_report_flag(PhysxContactPairFlag flag, bool value)
Sets the actor's contact report flags.
float get_sleep_linear_velocity() const
Returns the linear velocity below which an actor may go to sleep.
void set_c_mass_offset_global_mat(const LMatrix4f &mat)
Sets the matrix of the center of mass relative to world space.
void set_angular_momentum(const LVector3f &momentum)
Sets the angular momentum of the actor.
bool save_body_to_desc(PhysxBodyDesc &bodyDesc) const
Saves the body information of a dynamic actor to the passed body descriptor.
float compute_kinetic_energy() const
Computes the total kinetic (rotational and translational) energy of the object.
void set_sleep_angular_velocity(float threshold)
Sets the angular velocity below which an actor may go to sleep.
void set_angular_velocity(const LVector3f &angVel)
Sets the angular velocity of the actor.
unsigned int get_dominance_group() const
Retrieves the dominance group of this actor.
LVector3f get_mass_space_inertia_tensor() const
Returns the diagonal inertia tensor of the actor relative to the mass coordinate frame.
void set_global_pos(const LPoint3f &pos)
Method for setting a dynamic actor's position in the world.
void set_global_mat(const LMatrix4f &mat)
Method for setting a dynamic actor's transform matrix in the world.
LMatrix3f get_c_mass_global_orientation() const
Returns the center of mass orientation in world space.
void set_sleep_energy_threshold(float threshold)
Sets the energy threshold below which an actor may go to sleep.
void set_mass_space_inertia_tensor(const LVector3f &m)
Sets the inertia tensor, using a parameter specified in mass space coordinates.
void move_global_pos(const LPoint3f &pos)
The move_global_* calls serve to move kinematically controlled dynamic actors through the game world.
float get_linear_damping() const
Retrieves the linear damping coefficient.
Descriptor for the optional rigid body dynamic state of PhysxActor.
Abstract base class for character controllers.
This class exists just to provide scoping for the enums shared by PhysX classes.
Definition physxEnums.h:355
A scene is a collection of bodies, constraints, and effectors which can interact.
Definition physxScene.h:69
Abstract base class for shape descriptors.
Abstract base class for shapes.
Definition physxShape.h:39
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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(),...