26 link(NxActor *actorPtr) {
30 _ptr->userData =
this;
36 scene->_actors.add(
this);
39 NxShape *
const *shapes = _ptr->getShapes();
40 NxU32 nShapes = _ptr->getNbShapes();
42 for (NxU32 i=0; i < nShapes; i++) {
43 PhysxShape *shape = PhysxShape::factory(shapes[i]->getType());
44 shape->link(shapes[i]);
55 NxShape *
const *shapes = _ptr->getShapes();
56 NxU32 nShapes = _ptr->getNbShapes();
58 for (NxU32 i=0; i < nShapes; i++) {
64 _ptr->userData =
nullptr;
65 _error_type = ET_released;
68 scene->_actors.remove(
this);
77 nassertv(_error_type == ET_ok);
80 _ptr->getScene().releaseActor(*_ptr);
90 _controller = controller;
100 nassertr(_error_type == ET_ok,
false);
101 return _ptr->saveBodyToDesc(bodyDesc._desc);
110 nassertv(_error_type == ET_ok);
111 _ptr->saveToDesc(actorDesc._desc);
121 nassertv(_error_type == ET_ok);
123 _name = name ? name :
"";
124 _ptr->setName(_name.c_str());
133 nassertr(_error_type == ET_ok,
"");
134 return _ptr->getName();
149 if (_error_type != ET_ok)
return;
154 LVector3f hpr(_controller->get_h(), 0.0f, 0.0f);
155 LPoint3f pos = _controller->get_pos();
169 nassertr(_error_type == ET_ok, LPoint3f::zero());
179 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat());
189 nassertr(_error_type == ET_ok, LQuaternionf::zero());
200 nassertv(_error_type == ET_ok);
201 nassertv_always(!pos.is_nan());
232 nassertv(_error_type == ET_ok);
233 nassertv_always(!mat.is_nan());
245 nassertv(_error_type == ET_ok);
248 q.set_hpr(LVector3f(h, p, r));
263 nassertv(_error_type == ET_ok);
264 nassertv_always(!pos.is_nan());
291 nassertv(_error_type == ET_ok);
292 nassertv_always(!mat.is_nan());
308 nassertv(_error_type == ET_ok);
311 q.set_hpr(LVector3f(h, p, r));
325 nassertv(_error_type == ET_ok);
338 nassertv(_error_type == ET_ok);
361 nassertr(_error_type == ET_ok,
nullptr);
363 NxScene *scenePtr = &(_ptr->getScene());
372 unsigned int PhysxActor::
373 get_num_shapes()
const {
375 nassertr(_error_type == ET_ok, -1);
377 return _ptr->getNbShapes();
390 nassertr(_error_type == ET_ok,
nullptr);
391 nassertr(desc.is_valid(),
nullptr);
393 PhysxShape *shape = PhysxShape::factory(desc.ptr()->getType());
394 nassertr(shape,
nullptr);
396 NxShape *shapePtr = _ptr->createShape(*desc.ptr());
397 nassertr(shapePtr,
nullptr);
399 shape->link(shapePtr);
411 nassertr(_error_type == ET_ok,
nullptr);
412 nassertr_always(idx < _ptr->getNbShapes(),
nullptr);
414 NxShape *
const *shapes = _ptr->getShapes();
415 NxShape *shapePtr = shapes[idx];
429 nassertr(_error_type == ET_ok,
nullptr);
431 NxShape *
const *shapes = _ptr->getShapes();
432 NxShape *shapePtr =
nullptr;
433 NxU32 nShapes = _ptr->getNbShapes();
435 for (NxU32 i=0; i < nShapes; i++) {
436 shapePtr = shapes[i];
438 if (strcmp(shapePtr->getName(), name) == 0) {
458 add_force(
const LVector3f force, PhysxForceMode mode,
bool wakeup) {
460 nassertv(_error_type == ET_ok);
461 nassertv_always(!force.is_nan());
481 add_force_at_pos(
const LVector3f force,
const LPoint3f &pos, PhysxForceMode mode,
bool wakeup) {
483 nassertv(_error_type == ET_ok);
484 nassertv_always(!force.is_nan());
485 nassertv_always(!pos.is_nan());
507 nassertv(_error_type == ET_ok);
508 nassertv_always(!force.is_nan());
509 nassertv_always(!pos.is_nan());
524 add_torque(
const LVector3f torque, PhysxForceMode mode,
bool wakeup) {
526 nassertv(_error_type == ET_ok);
527 nassertv_always(!torque.is_nan());
544 nassertv(_error_type == ET_ok);
545 nassertv_always(!force.is_nan());
567 nassertv(_error_type == ET_ok);
568 nassertv_always(!force.is_nan());
569 nassertv_always(!pos.is_nan());
591 nassertv(_error_type == ET_ok);
592 nassertv_always(!force.is_nan());
593 nassertv_always(!pos.is_nan());
610 nassertv(_error_type == ET_ok);
611 nassertv_always(!torque.is_nan());
645 nassertr(_error_type == ET_ok,
false);
646 return _ptr->updateMassFromShapes(density, totalMass);
656 nassertr(_error_type == ET_ok, 0.0f);
657 return _ptr->computeKineticEnergy();
666 nassertr(_error_type == ET_ok,
false);
667 return _ptr->isDynamic();
677 nassertv(_error_type == ET_ok);
678 nassertv(group >= 0 && group < 32);
680 NxShape *
const *shapes = _ptr->getShapes();
681 NxU32 nShapes = _ptr->getNbShapes();
683 for (NxU32 i=0; i < nShapes; i++) {
684 shapes[i]->setGroup( group );
695 _ptr->raiseBodyFlag((NxBodyFlag)flag);
698 _ptr->clearBodyFlag((NxBodyFlag)flag);
708 nassertr(_error_type == ET_ok,
false);
709 return ptr()->readBodyFlag((NxBodyFlag)flag);
719 _ptr->raiseActorFlag((NxActorFlag)flag);
722 _ptr->clearActorFlag((NxActorFlag)flag);
732 nassertr(_error_type == ET_ok,
false);
733 return ptr()->readActorFlag((NxActorFlag)flag);
750 nassertv(_error_type == ET_ok);
752 NxU32 flags = _ptr->getContactReportFlags();
761 _ptr->setContactReportFlags(flags);
770 nassertv(_error_type == ET_ok);
771 nassertv(threshold >= 0.0f);
773 _ptr->setContactReportThreshold(threshold);
791 nassertv(_error_type == ET_ok);
792 nassertv(group >= 0 && group < 0x8000);
794 ptr()->setGroup(group);
803 nassertr(_error_type == ET_ok, 0);
805 return ptr()->getGroup();
823 nassertv(_error_type == ET_ok);
824 nassertv(group >= 0 && group < 32);
827 _ptr->setDominanceGroup(group);
836 nassertr(_error_type == ET_ok, 0);
838 return ptr()->getDominanceGroup();
849 nassertv(_error_type == ET_ok);
850 nassertv(angDamp >= 0.0f);
852 _ptr->setAngularDamping(angDamp);
861 nassertr(_error_type == ET_ok, 0.0f);
862 return _ptr->getAngularDamping();
873 nassertv(_error_type == ET_ok);
874 nassertv(linDamp >= 0.0f);
876 _ptr->setLinearDamping(linDamp);
885 nassertr(_error_type == ET_ok, 0.0f);
886 return _ptr->getLinearDamping();
901 nassertv(_error_type == ET_ok);
902 nassertv(_ptr->isDynamic());
919 nassertv(_error_type == ET_ok);
920 nassertv(_ptr->isDynamic());
947 nassertv(_error_type == ET_ok);
948 nassertv(_ptr->isDynamic());
950 _ptr->setMaxAngularVelocity(maxAngVel);
959 nassertr(_error_type == ET_ok, LVector3f::zero());
969 nassertr(_error_type == ET_ok, LVector3f::zero());
979 nassertr(_error_type == ET_ok, 0.0f);
980 return _ptr->getMaxAngularVelocity();
992 nassertr(_error_type == ET_ok, LVector3f::zero());
993 nassertr_always(!point.is_nan(), LVector3f::zero());
1008 nassertr(_error_type == ET_ok, LVector3f::zero());
1009 nassertr_always(!point.is_nan(), LVector3f::zero());
1025 nassertv(_error_type == ET_ok);
1038 nassertv(_error_type == ET_ok);
1049 nassertr(_error_type == ET_ok, LVector3f::zero());
1061 nassertr(_error_type == ET_ok, LVector3f::zero());
1077 nassertv(_error_type == ET_ok);
1078 _ptr->setSleepLinearVelocity(threshold);
1093 nassertv(_error_type == ET_ok);
1094 _ptr->setSleepAngularVelocity(threshold);
1110 nassertv(_error_type == ET_ok);
1111 _ptr->setSleepEnergyThreshold(threshold);
1122 nassertr(_error_type == ET_ok, 0.0f);
1123 return _ptr->getSleepLinearVelocity();
1134 nassertr(_error_type == ET_ok, 0.0f);
1135 return _ptr->getSleepAngularVelocity();
1146 nassertr(_error_type == ET_ok, 0.0f);
1147 return _ptr->getSleepEnergyThreshold();
1164 nassertr(_error_type == ET_ok,
false);
1165 return _ptr->isSleeping();
1180 nassertv(_error_type == ET_ok);
1181 _ptr->wakeUp(wakeCounterValue);
1196 nassertv(_error_type == ET_ok);
1206 nassertv(_error_type == ET_ok);
1207 _ptr->setMass(mass);
1216 nassertr(_error_type == ET_ok, 0.0f);
1217 return _ptr->getMass();
1226 nassertv(_error_type == ET_ok);
1236 nassertv(_error_type == ET_ok);
1246 nassertv(_error_type == ET_ok);
1256 nassertv(_error_type == ET_ok);
1266 nassertv(_error_type == ET_ok);
1276 nassertv(_error_type == ET_ok);
1286 nassertv(_error_type == ET_ok);
1296 nassertv(_error_type == ET_ok);
1306 nassertv(_error_type == ET_ok);
1317 nassertv(_error_type == ET_ok);
1327 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat());
1337 nassertr(_error_type == ET_ok, LPoint3f::zero());
1347 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat());
1357 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat());
1367 nassertr(_error_type == ET_ok, LPoint3f::zero());
1377 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat());
1388 nassertr(_error_type == ET_ok, LVector3f::zero());
1399 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat());
1410 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat());
LVector3f get_angular_velocity() const
Returns the angular velocity of the actor.
LPoint3f get_c_mass_local_pos() const
Returns the center of mass position relative to the actor.
float get_sleep_energy_threshold() const
Returns the energy below which an actor may go to sleep.
void set_sleep_linear_velocity(float threshold)
Sets the linear velocity below which an actor may go to sleep.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
unsigned int get_dominance_group() const
Retrieves the dominance group of this actor.
bool save_body_to_desc(PhysxBodyDesc &bodyDesc) const
Saves the body information of a dynamic actor to the passed body descriptor.
float get_sleep_linear_velocity() const
Returns the linear velocity below which an actor may go to sleep.
bool get_actor_flag(PhysxActorFlag flag) const
Return the specified ActorFlag flag.
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_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.
bool is_empty() const
Returns true if the NodePath contains no nodes.
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.
LMatrix4f get_global_mat() const
Retrieves the actors world space transform.
void set_mass(float mass)
Sets the mass of a dynamic actor.
void set_c_mass_offset_local_pos(const LPoint3f &pos)
Sets the position of the center of mass relative to the actor.
LVector3f get_linear_momentum() const
Retrieves the linear momentum of an actor.
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.
bool is_sleeping() const
Returns true if this body is sleeping.
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...
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 compute_kinetic_energy() const
Computes the total kinetic (rotational and translational) energy of the object.
LVector3f get_mass_space_inertia_tensor() const
Returns the diagonal inertia tensor of the actor relative to the mass coordinate frame.
float get_sleep_angular_velocity() const
Returns the angular velocity below which an actor may go to sleep.
float get_mass() const
Returns the mass of the actor.
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.
LMatrix3f get_c_mass_local_orientation() const
Returns the center of mass orientation relative to the actor.
A scene is a collection of bodies, constraints, and effectors which can interact.
LPoint3f get_global_pos() const
Retrieves the actors world space position.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
float get_max_angular_velocity() const
Returns the maximum angular velocity permitted for this actor.
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
LMatrix3f get_global_inertia_tensor() const
Returns the inertia tensor of the actor relative to the world coordinate frame.
LQuaternionf get_global_quat() const
Retrieves the actors world space orientation.
void set_transform(const TransformState *transform, Thread *current_thread=Thread::get_current_thread())
Changes the complete transform object on this node.
const char * get_name() const
Retrieves the name string.
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...
LMatrix4f get_c_mass_global_mat() const
Returns the center of mass transform in world space.
void move_global_pos(const LPoint3f &pos)
The move_global_* calls serve to move kinematically controlled dynamic actors through the game world.
void save_to_desc(PhysxActorDesc &actorDesc) const
Saves the state of the actor to the passed descriptor.
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.
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...
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.
void set_angular_momentum(const LVector3f &momentum)
Sets the angular momentum of the actor.
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.
LVector3f get_linear_velocity() const
Returns the linear velocity of an actor.
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 is_dynamic() const
Returns true if the actor is dynamic.
float get_linear_damping() const
Retrieves the linear damping coefficient.
void set_sleep_energy_threshold(float threshold)
Sets the energy threshold below which an actor may go to sleep.
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.
LMatrix3f get_c_mass_global_orientation() const
Returns the center of mass orientation in world space.
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.
get_shape
Retrieves an individual shape from the actor's array of shapes.
void set_name(const char *name)
Sets a name string for the object that can be retrieved with get_name().
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.
LPoint3f get_c_mass_global_pos() const
Returns the center of mass position in world space.
LMatrix3f get_global_inertia_tensor_inverse() const
Returns the inverse of the inertia tensor of the actor relative to the world coordinate frame.
void set_max_angular_velocity(float maxAngVel)
Lets you set the maximum angular velocity permitted for this actor.
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.
void detach_node_path()
Detaches a previously assigned NodePath from this actor.
unsigned int get_group() const
Retrieves the actor group this actor is assigned to.
void set_c_mass_offset_global_mat(const LMatrix4f &mat)
Sets the matrix of the center of mass relative to world space.
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...
Descriptor for the optional rigid body dynamic state of PhysxActor.
PhysxShape * get_shape_by_name(const char *name) const
Retrieves an individual shape from the actor's array of shapes.
bool get_body_flag(PhysxBodyFlag flag) const
Return the specified BodyFlag flag.
PhysxScene * get_scene() const
Retrieves the scene which this actor belongs to.
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 put_to_sleep()
Forces the actor to sleep.
TypeHandle is the identifier used to differentiate C++ class types.
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.
NodePath get_node_path() const
Retrieves a previously attached NodePath.
static LMatrix3f nxMat33_to_mat3(const NxMat33 &m)
Converts from NxMat33 to LMatrix3f.
LVector3f get_angular_momentum() const
Retrieves the angular momentum of an actor.
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...
void set_dominance_group(unsigned int group)
Assigns dynamic actors a dominance group identifier.
LMatrix4f get_c_mass_local_mat() const
Returns the center of mass transform relative to the actor.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
float get_angular_damping() const
Returns the angular damping coefficient.
void set_angular_damping(float angDamp)
Sets the angular damping coefficient.