15 #include "physxActor.h"
16 #include "physxActorDesc.h"
17 #include "physxBodyDesc.h"
18 #include "physxShapeDesc.h"
19 #include "physxManager.h"
29 link(NxActor *actorPtr) {
33 _ptr->userData =
this;
39 scene->_actors.add(
this);
42 NxShape *
const *shapes = _ptr->getShapes();
43 NxU32 nShapes = _ptr->getNbShapes();
45 for (NxU32 i=0; i < nShapes; i++) {
46 PhysxShape *shape = PhysxShape::factory(shapes[i]->getType());
47 shape->link(shapes[i]);
60 NxShape *
const *shapes = _ptr->getShapes();
61 NxU32 nShapes = _ptr->getNbShapes();
63 for (NxU32 i=0; i < nShapes; i++) {
69 _ptr->userData = NULL;
70 _error_type = ET_released;
73 scene->_actors.remove(
this);
84 nassertv(_error_type == ET_ok);
87 _ptr->getScene().releaseActor(*_ptr);
99 _controller = controller;
111 nassertr(_error_type == ET_ok,
false);
112 return _ptr->saveBodyToDesc(bodyDesc._desc);
124 nassertv(_error_type == ET_ok);
125 _ptr->saveToDesc(actorDesc._desc);
139 nassertv(_error_type == ET_ok);
141 _name = name ? name :
"";
142 _ptr->setName(_name.c_str());
153 nassertr(_error_type == ET_ok,
"");
154 return _ptr->getName();
173 if (_error_type != ET_ok)
return;
178 LVector3f hpr(_controller->get_h(), 0.0f, 0.0f);
179 LPoint3f pos = _controller->get_pos();
233 nassertv(_error_type == ET_ok);
234 nassertv_always(!pos.
is_nan());
277 nassertv(_error_type == ET_ok);
278 nassertv_always(!mat.
is_nan());
293 nassertv(_error_type == ET_ok);
313 nassertv(_error_type == ET_ok);
314 nassertv_always(!pos.
is_nan());
348 nassertv(_error_type == ET_ok);
349 nassertv_always(!mat.
is_nan());
367 nassertv(_error_type == ET_ok);
388 nassertv(_error_type == ET_ok);
404 nassertv(_error_type == ET_ok);
432 nassertr(_error_type == ET_ok, NULL);
434 NxScene *scenePtr = &(_ptr->getScene());
449 nassertr(_error_type == ET_ok, -1);
451 return _ptr->getNbShapes();
469 nassertr(_error_type == ET_ok, NULL);
470 nassertr(desc.is_valid(),NULL);
472 PhysxShape *shape = PhysxShape::factory(desc.ptr()->getType());
473 nassertr(shape, NULL);
475 NxShape *shapePtr = _ptr->createShape(*desc.ptr());
476 nassertr(shapePtr, NULL);
478 shape->link(shapePtr);
493 nassertr(_error_type == ET_ok, NULL);
494 nassertr_always(idx < _ptr->getNbShapes(), NULL);
496 NxShape *
const *shapes = _ptr->getShapes();
497 NxShape *shapePtr = shapes[idx];
514 nassertr(_error_type == ET_ok, NULL);
516 NxShape *
const *shapes = _ptr->getShapes();
517 NxShape *shapePtr = NULL;
518 NxU32 nShapes = _ptr->getNbShapes();
520 for (NxU32 i=0; i < nShapes; i++) {
521 shapePtr = shapes[i];
523 if (strcmp(shapePtr->getName(), name) == 0) {
549 nassertv(_error_type == ET_ok);
550 nassertv_always(!force.
is_nan());
579 nassertv(_error_type == ET_ok);
580 nassertv_always(!force.
is_nan());
581 nassertv_always(!pos.
is_nan());
610 nassertv(_error_type == ET_ok);
611 nassertv_always(!force.
is_nan());
612 nassertv_always(!pos.
is_nan());
633 nassertv(_error_type == ET_ok);
634 nassertv_always(!torque.
is_nan());
656 nassertv(_error_type == ET_ok);
657 nassertv_always(!force.
is_nan());
686 nassertv(_error_type == ET_ok);
687 nassertv_always(!force.
is_nan());
688 nassertv_always(!pos.
is_nan());
717 nassertv(_error_type == ET_ok);
718 nassertv_always(!force.
is_nan());
719 nassertv_always(!pos.
is_nan());
740 nassertv(_error_type == ET_ok);
741 nassertv_always(!torque.
is_nan());
784 nassertr(_error_type == ET_ok,
false);
785 return _ptr->updateMassFromShapes(density, totalMass);
798 nassertr(_error_type == ET_ok, 0.0f);
799 return _ptr->computeKineticEnergy();
810 nassertr(_error_type == ET_ok,
false);
811 return _ptr->isDynamic();
823 nassertv(_error_type == ET_ok);
824 nassertv(group >= 0 && group < 32);
826 NxShape *
const *shapes = _ptr->getShapes();
827 NxU32 nShapes = _ptr->getNbShapes();
829 for (NxU32 i=0; i < nShapes; i++) {
830 shapes[i]->setGroup( group );
843 _ptr->raiseBodyFlag((NxBodyFlag)flag);
846 _ptr->clearBodyFlag((NxBodyFlag)flag);
858 nassertr(_error_type == ET_ok,
false);
859 return ptr()->readBodyFlag((NxBodyFlag)flag);
871 _ptr->raiseActorFlag((NxActorFlag)flag);
874 _ptr->clearActorFlag((NxActorFlag)flag);
886 nassertr(_error_type == ET_ok,
false);
887 return ptr()->readActorFlag((NxActorFlag)flag);
910 nassertv(_error_type == ET_ok);
912 NxU32 flags = _ptr->getContactReportFlags();
921 _ptr->setContactReportFlags(flags);
933 nassertv(_error_type == ET_ok);
934 nassertv(threshold >= 0.0f);
936 _ptr->setContactReportThreshold(threshold);
958 nassertv(_error_type == ET_ok);
959 nassertv(group >= 0 && group < 0x8000);
961 ptr()->setGroup(group);
973 nassertr(_error_type == ET_ok, 0);
975 return ptr()->getGroup();
999 nassertv(_error_type == ET_ok);
1000 nassertv(group >= 0 && group < 32);
1003 _ptr->setDominanceGroup(group);
1014 nassertr(_error_type == ET_ok, 0);
1016 return ptr()->getDominanceGroup();
1031 nassertv(_error_type == ET_ok);
1032 nassertv(angDamp >= 0.0f);
1034 _ptr->setAngularDamping(angDamp);
1046 nassertr(_error_type == ET_ok, 0.0f);
1047 return _ptr->getAngularDamping();
1061 nassertv(_error_type == ET_ok);
1062 nassertv(linDamp >= 0.0f);
1064 _ptr->setLinearDamping(linDamp);
1076 nassertr(_error_type == ET_ok, 0.0f);
1077 return _ptr->getLinearDamping();
1096 nassertv(_error_type == ET_ok);
1097 nassertv(_ptr->isDynamic());
1118 nassertv(_error_type == ET_ok);
1119 nassertv(_ptr->isDynamic());
1153 nassertv(_error_type == ET_ok);
1154 nassertv(_ptr->isDynamic());
1156 _ptr->setMaxAngularVelocity(maxAngVel);
1194 nassertr(_error_type == ET_ok, 0.0f);
1195 return _ptr->getMaxAngularVelocity();
1250 nassertv(_error_type == ET_ok);
1268 nassertv(_error_type == ET_ok);
1318 nassertv(_error_type == ET_ok);
1319 _ptr->setSleepLinearVelocity(threshold);
1338 nassertv(_error_type == ET_ok);
1339 _ptr->setSleepAngularVelocity(threshold);
1360 nassertv(_error_type == ET_ok);
1361 _ptr->setSleepEnergyThreshold(threshold);
1375 nassertr(_error_type == ET_ok, 0.0f);
1376 return _ptr->getSleepLinearVelocity();
1390 nassertr(_error_type == ET_ok, 0.0f);
1391 return _ptr->getSleepAngularVelocity();
1404 nassertr(_error_type == ET_ok, 0.0f);
1405 return _ptr->getSleepEnergyThreshold();
1426 nassertr(_error_type == ET_ok,
false);
1427 return _ptr->isSleeping();
1445 nassertv(_error_type == ET_ok);
1446 _ptr->wakeUp(wakeCounterValue);
1465 nassertv(_error_type == ET_ok);
1477 nassertv(_error_type == ET_ok);
1478 _ptr->setMass(mass);
1489 nassertr(_error_type == ET_ok, 0.0f);
1490 return _ptr->getMass();
1502 nassertv(_error_type == ET_ok);
1515 nassertv(_error_type == ET_ok);
1528 nassertv(_error_type == ET_ok);
1541 nassertv(_error_type == ET_ok);
1554 nassertv(_error_type == ET_ok);
1567 nassertv(_error_type == ET_ok);
1580 nassertv(_error_type == ET_ok);
1593 nassertv(_error_type == ET_ok);
1606 nassertv(_error_type == ET_ok);
1619 nassertv(_error_type == ET_ok);
void set_sleep_linear_velocity(float threshold)
Sets the linear velocity below which an actor may go to sleep.
float get_mass() const
Returns the mass of the actor.
LPoint3f get_c_mass_local_pos() const
Returns the center of mass position relative to the actor.
LVector3f get_linear_velocity() const
Returns the linear velocity of an 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 ...
static const LMatrix3f & ident_mat()
Returns an identity matrix.
void set_contact_report_flag(PhysxContactPairFlag flag, bool value)
Sets the actor's contact report flags.
void move_global_mat(const LMatrix4f &mat)
The move_global_* calls serve to move kinematically controlled dynamic actors through the game world...
void set_c_mass_offset_global_orientation(const LMatrix3f &mat)
Sets the orientation of the center of mass relative to world space.
void set_c_mass_offset_local_orientation(const LMatrix3f &mat)
Sets the orientation of the center of mass relative 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_linear_velocity(const LVector3f &linVel)
Sets the linear velocity of the actor.
static NxQuat quat_to_nxQuat(const LQuaternionf &q)
Converts from LQuaternionf to NxQuat.
void set_body_flag(PhysxBodyFlag flag, bool value)
Raise or lower individual BodyFlag flags.
float get_angular_damping() const
Returns the angular damping coefficient.
void set_mass(float mass)
Sets the mass of a dynamic actor.
LMatrix3f get_global_inertia_tensor_inverse() const
Returns the inverse of the inertia tensor of the actor relative to the world coordinate frame...
NodePath get_top(Thread *current_thread=Thread::get_current_thread()) const
Returns a singleton NodePath that represents the top of the path, or empty NodePath if this path is e...
NodePath get_node_path() const
Retrieves a previously attached NodePath.
void set_c_mass_offset_local_pos(const LPoint3f &pos)
Sets the position of the center of mass relative to the actor.
static const LPoint3f & zero()
Returns a zero-length point.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
Abstract base class for shapes.
void set_c_mass_global_orientation(const LMatrix3f &mat)
Moves the actor by setting the orientation of the center of mass.
void set_linear_damping(float linDamp)
Sets the linear damping coefficient.
static const LVector3f & zero()
Returns a zero-length vector.
void set_global_pos(const LPoint3f &pos)
Method for setting a dynamic actor's position in the world.
void set_shape_group(unsigned int group)
Sets the collision group for all shapes of this actor.
float get_max_angular_velocity() const
Returns the maximum angular velocity permitted for this actor.
LVector3f get_angular_momentum() const
Retrieves the angular momentum of an actor.
PhysxShape * get_shape(unsigned int idx) const
Retrieves an individual shape from the actor's array of shapes.
bool get_actor_flag(PhysxActorFlag flag) const
Return the specified ActorFlag flag.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
void set_actor_flag(PhysxActorFlag flag, bool value)
Raise or lower individual ActorFlag flags.
void set_mass_space_inertia_tensor(const LVector3f &m)
Sets the inertia tensor, using a parameter specified in mass space coordinates.
float get_linear_damping() const
Retrieves the linear damping coefficient.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
A scene is a collection of bodies, constraints, and effectors which can interact. ...
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 update_transform(const LMatrix4f &m)
Updates the transform of an assigned NodePath.
void set_linear_momentum(const LVector3f &momentum)
Sets the linear momentum of the actor.
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
LMatrix3f get_global_inertia_tensor() const
Returns the inertia tensor of the actor relative to the world coordinate frame.
float get_sleep_energy_threshold() const
Returns the energy below which an actor may go to sleep.
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
bool save_body_to_desc(PhysxBodyDesc &bodyDesc) const
Saves the body information of a dynamic actor to the passed body descriptor.
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Changes the complete transform object on this node.
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_sleep_angular_velocity() const
Returns the angular velocity below which an actor may go to sleep.
void move_global_pos(const LPoint3f &pos)
The move_global_* calls serve to move kinematically controlled dynamic actors through the game world...
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. ...
unsigned int get_dominance_group() const
Retrieves the dominance group of this actor.
void set_sleep_angular_velocity(float threshold)
Sets the angular velocity below which an actor may go to sleep.
void set_global_hpr(float h, float p, float r)
Method for setting a dynamic actor's orientation in the world.
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...
float get_sleep_linear_velocity() const
Returns the linear velocity below which an actor may go to sleep.
void wake_up(float wakeCounterValue=NX_SLEEP_INTERVAL)
Wakes up the actor if it is sleeping.
Abstract base class for character controllers.
static NodePath fail()
Creates a NodePath with the ET_fail error type set.
LMatrix4f get_global_mat() const
Retrieves the actors world space transform.
void set_angular_momentum(const LVector3f &momentum)
Sets the angular momentum of the actor.
This is a 4-by-4 transform matrix.
LVector3f get_mass_space_inertia_tensor() const
Returns the diagonal inertia tensor of the actor relative to the mass coordinate frame.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
static LQuaternionf nxQuat_to_quat(const NxQuat &q)
Converts from NxQuat to LQuaternionf.
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
void set_contact_report_threshold(float threshold)
Sets the force threshold for contact reports.
bool update_mass_from_shapes(float density, float totalMass)
Recomputes a dynamic actor's mass properties from its shapes.
Descriptor for PhysxActor.
PhysxShape * create_shape(PhysxShapeDesc &desc)
Creates a new shape and adds it to the list of shapes of this 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 ...
bool get_body_flag(PhysxBodyFlag flag) const
Return the specified BodyFlag flag.
void set_hpr(const LVecBase3f &hpr, CoordinateSystem cs=CS_default)
Sets the quaternion as the unit quaternion that is equivalent to these Euler angles.
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...
LMatrix4f get_c_mass_local_mat() const
Returns the center of mass transform relative to the actor.
PhysxShape * get_shape_by_name(const char *name) const
Retrieves an individual shape from the actor's array of shapes.
unsigned int get_group() const
Retrieves the actor group this actor is assigned to.
void set_sleep_energy_threshold(float threshold)
Sets the energy threshold below which an actor may go to sleep.
LMatrix3f get_c_mass_local_orientation() const
Returns the center of mass orientation relative to the actor.
void save_to_desc(PhysxActorDesc &actorDesc) const
Saves the state of the actor to the passed descriptor.
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 set_angular_velocity(const LVector3f &angVel)
Sets the angular velocity of the actor.
void set_c_mass_global_mat(const LMatrix4f &mat)
Moves the actor by setting the transform of the center of mass.
static const LMatrix4f & zeros_mat()
Returns an matrix filled with zeros.
float compute_kinetic_energy() const
Computes the total kinetic (rotational and translational) energy of the object.
void set_name(const char *name)
Sets a name string for the object that can be retrieved with get_name().
LVector3f get_angular_velocity() const
Returns the angular velocity of the actor.
LVector3f get_linear_momentum() const
Retrieves the linear momentum of an actor.
void set_global_mat(const LMatrix4f &mat)
Method for setting a dynamic actor's transform matrix in the world.
void set_c_mass_offset_global_pos(const LPoint3f &pos)
Sets the position of the center of mass relative to world space.
Abstract base class for shape descriptors.
void set_max_angular_velocity(float maxAngVel)
Lets you set the maximum angular velocity permitted for this actor.
bool is_sleeping() const
Returns true if this body is sleeping.
This is the base quaternion class.
LPoint3f get_c_mass_global_pos() const
Returns the center of mass position in world space.
LMatrix3f get_c_mass_global_orientation() const
Returns the center of mass orientation in world space.
void attach_node_path(const NodePath &np)
Attaches a node path to this actor.
static LPoint3f nxVec3_to_point3(const NxVec3 &p)
Converts from NxVec3 to LPoint3f.
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.
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 detach_node_path()
Detaches a previously assigned NodePath from this actor.
bool is_dynamic() const
Returns true if the actor is dynamic.
LQuaternionf get_global_quat() const
Retrieves the actors world space orientation.
void set_c_mass_offset_global_mat(const LMatrix4f &mat)
Sets the matrix of the center of mass relative to world space.
bool is_empty() const
Returns true if the NodePath contains no nodes.
Descriptor for the optional rigid body dynamic state of PhysxActor.
void put_to_sleep()
Forces the actor to sleep.
TypeHandle is the identifier used to differentiate C++ class types.
This is a 3-by-3 transform matrix.
void set_group(unsigned int group)
Assigns the actor to a user defined group of actors.
void set_c_mass_global_pos(const LPoint3f &pos)
Moves the actor by setting the position of the center of mass.
static LMatrix4f nxMat34_to_mat4(const NxMat34 &m)
Converts from NxMat34 to LMatrix4f.
static LMatrix3f nxMat33_to_mat3(const NxMat33 &m)
Converts from NxMat33 to LMatrix3f.
void set_c_mass_offset_local_mat(const LMatrix4f &mat)
Sets the matrix of the center of mass relative to the actor.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
LPoint3f get_global_pos() const
Retrieves the actors world space position.
unsigned int get_num_shapes() const
Returns the number of shapes assigned to the actor.
void set_dominance_group(unsigned int group)
Assigns dynamic actors a dominance group identifier.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
static const LVecBase4f & zero()
Returns a zero-length vector.
PhysxScene * get_scene() const
Retrieves the scene which this actor belongs to.
const char * get_name() const
Retrieves the name string.
LMatrix4f get_c_mass_global_mat() const
Returns the center of mass transform in world space.
void set_angular_damping(float angDamp)
Sets the angular damping coefficient.