Panda3D
|
00001 // Filename: physxActor.cxx 00002 // Created by: enn0x (14Sep09) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "physxActor.h" 00016 #include "physxActorDesc.h" 00017 #include "physxBodyDesc.h" 00018 #include "physxShapeDesc.h" 00019 #include "physxManager.h" 00020 00021 TypeHandle PhysxActor::_type_handle; 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Function: PhysxActor::link 00025 // Access: Public 00026 // Description: 00027 //////////////////////////////////////////////////////////////////// 00028 void PhysxActor:: 00029 link(NxActor *actorPtr) { 00030 00031 // Link self 00032 _ptr = actorPtr; 00033 _ptr->userData = this; 00034 _error_type = ET_ok; 00035 00036 set_name(actorPtr->getName()); 00037 00038 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; 00039 scene->_actors.add(this); 00040 00041 // Link shapes 00042 NxShape * const *shapes = _ptr->getShapes(); 00043 NxU32 nShapes = _ptr->getNbShapes(); 00044 00045 for (NxU32 i=0; i < nShapes; i++) { 00046 PhysxShape *shape = PhysxShape::factory(shapes[i]->getType()); 00047 shape->link(shapes[i]); 00048 } 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PhysxActor::unlink 00053 // Access: Public 00054 // Description: 00055 //////////////////////////////////////////////////////////////////// 00056 void PhysxActor:: 00057 unlink() { 00058 00059 // Unlink shapes 00060 NxShape * const *shapes = _ptr->getShapes(); 00061 NxU32 nShapes = _ptr->getNbShapes(); 00062 00063 for (NxU32 i=0; i < nShapes; i++) { 00064 PhysxShape *shape = (PhysxShape *)shapes[i]->userData; 00065 shape->unlink(); 00066 } 00067 00068 // Unlink self 00069 _ptr->userData = NULL; 00070 _error_type = ET_released; 00071 00072 PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData; 00073 scene->_actors.remove(this); 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: PhysxActor::release 00078 // Access: Published 00079 // Description: 00080 //////////////////////////////////////////////////////////////////// 00081 void PhysxActor:: 00082 release() { 00083 00084 nassertv(_error_type == ET_ok); 00085 00086 unlink(); 00087 _ptr->getScene().releaseActor(*_ptr); 00088 _ptr = NULL; 00089 } 00090 00091 //////////////////////////////////////////////////////////////////// 00092 // Function: PhysxActor::link_controller 00093 // Access: Public 00094 // Description: 00095 //////////////////////////////////////////////////////////////////// 00096 void PhysxActor:: 00097 link_controller(PhysxController *controller) { 00098 00099 _controller = controller; 00100 } 00101 00102 //////////////////////////////////////////////////////////////////// 00103 // Function: PhysxActor::save_body_to_desc 00104 // Access: Published 00105 // Description: Saves the body information of a dynamic actor to 00106 // the passed body descriptor. 00107 //////////////////////////////////////////////////////////////////// 00108 bool PhysxActor:: 00109 save_body_to_desc(PhysxBodyDesc &bodyDesc) const { 00110 00111 nassertr(_error_type == ET_ok, false); 00112 return _ptr->saveBodyToDesc(bodyDesc._desc); 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: PhysxActor::save_to_desc 00117 // Access: Published 00118 // Description: Saves the state of the actor to the passed 00119 // descriptor. 00120 //////////////////////////////////////////////////////////////////// 00121 void PhysxActor:: 00122 save_to_desc(PhysxActorDesc &actorDesc) const { 00123 00124 nassertv(_error_type == ET_ok); 00125 _ptr->saveToDesc(actorDesc._desc); 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: PhysxActor::set_name 00130 // Access: Published 00131 // Description: Sets a name string for the object that can be 00132 // retrieved with get_name(). 00133 // This is for debugging and is not used by the 00134 // engine. 00135 //////////////////////////////////////////////////////////////////// 00136 void PhysxActor:: 00137 set_name(const char *name) { 00138 00139 nassertv(_error_type == ET_ok); 00140 00141 _name = name ? name : ""; 00142 _ptr->setName(_name.c_str()); 00143 } 00144 00145 //////////////////////////////////////////////////////////////////// 00146 // Function: PhysxActor::get_name 00147 // Access: Published 00148 // Description: Retrieves the name string. 00149 //////////////////////////////////////////////////////////////////// 00150 const char *PhysxActor:: 00151 get_name() const { 00152 00153 nassertr(_error_type == ET_ok, ""); 00154 return _ptr->getName(); 00155 } 00156 00157 //////////////////////////////////////////////////////////////////// 00158 // Function: PhysxActor::update_transform 00159 // Access: Public 00160 // Description: Updates the transform of an assigned NodePath. If 00161 // the actor has been created by a PhysxController 00162 // then this method will update the NodePath's 00163 // transform from the controller's transform. 00164 //////////////////////////////////////////////////////////////////// 00165 void PhysxActor:: 00166 update_transform(const LMatrix4f m) { 00167 00168 // Active transforms are update AFTER scene.fetchResults() has 00169 // been called, and thus can contain removed objects. So either 00170 // update transforms after scene.fetchResults() - which means 00171 // poor performance - or check if an actor has been removed here 00172 // in this method. 00173 if (_error_type != ET_ok) return; 00174 00175 if (_np.is_empty()) return; 00176 00177 if (_controller) { 00178 LVector3f hpr(_controller->get_h(), 0.0f, 0.0f); 00179 LPoint3f pos = _controller->get_pos(); 00180 _np.set_transform(_np.get_top(), TransformState::make_pos_hpr(pos, hpr)); 00181 } 00182 else { 00183 _np.set_transform(_np.get_top(), TransformState::make_mat(m)); 00184 } 00185 } 00186 00187 //////////////////////////////////////////////////////////////////// 00188 // Function: PhysxActor::get_global_pos 00189 // Access: Published 00190 // Description: Retrieves the actors world space position. 00191 //////////////////////////////////////////////////////////////////// 00192 LPoint3f PhysxActor:: 00193 get_global_pos() const { 00194 00195 nassertr(_error_type == ET_ok, LPoint3f::zero()); 00196 return PhysxManager::nxVec3_to_point3(_ptr->getGlobalPosition()); 00197 } 00198 00199 //////////////////////////////////////////////////////////////////// 00200 // Function: PhysxActor::get_global_mat 00201 // Access: Published 00202 // Description: Retrieves the actors world space transform. 00203 //////////////////////////////////////////////////////////////////// 00204 LMatrix4f PhysxActor:: 00205 get_global_mat() const { 00206 00207 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); 00208 return PhysxManager::nxMat34_to_mat4(_ptr->getGlobalPose()); 00209 } 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function: PhysxActor::get_global_quat 00213 // Access: Published 00214 // Description: Retrieves the actors world space orientation. 00215 //////////////////////////////////////////////////////////////////// 00216 LQuaternionf PhysxActor:: 00217 get_global_quat() const { 00218 00219 nassertr(_error_type == ET_ok, LQuaternionf::zero()); 00220 return PhysxManager::nxQuat_to_quat(_ptr->getGlobalOrientation()); 00221 } 00222 00223 //////////////////////////////////////////////////////////////////// 00224 // Function: PhysxActor::set_global_pos 00225 // Access: Published 00226 // Description: Method for setting a dynamic actor's position in 00227 // the world. Please see set_global_mat for some 00228 // caveats. 00229 //////////////////////////////////////////////////////////////////// 00230 void PhysxActor:: 00231 set_global_pos(const LPoint3f &pos) { 00232 00233 nassertv(_error_type == ET_ok); 00234 nassertv_always(!pos.is_nan()); 00235 00236 _ptr->setGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); 00237 } 00238 00239 //////////////////////////////////////////////////////////////////// 00240 // Function: PhysxActor::set_global_mat 00241 // Access: Published 00242 // Description: Method for setting a dynamic actor's transform 00243 // matrix in the world. 00244 // 00245 // This method instantaneously changes the actor space 00246 // to world space transformation. 00247 // 00248 // One should exercise restraint in making use of 00249 // these methods. 00250 // 00251 // Static actors should not be moved at all. There are 00252 // various internal data structures for static actors 00253 // which may need to be recomputed when one moves. 00254 // Also, moving static actors will not interact 00255 // correctly with dynamic actors or joints. If you 00256 // would like to directly control an actor's position 00257 // and would like to have it correctly interact with 00258 // dynamic bodies and joints, you should create a 00259 // dynamic body with the BF_kinematic flag, and then 00260 // use the move_global_*() commands to move it along 00261 // a path! 00262 // 00263 // When briefly moving dynamic actors, one should not: 00264 // - Move actors into other actors, thus causing 00265 // interpenetration (an invalid physical state). 00266 // - Move an actor that is connected by a joint to 00267 // another away from the other (thus causing joint 00268 // error). 00269 // - When moving jointed actors the joints' cached 00270 // transform information is destroyed and recreated 00271 // next frame; thus this call is expensive for 00272 // jointed actors. 00273 //////////////////////////////////////////////////////////////////// 00274 void PhysxActor:: 00275 set_global_mat(const LMatrix4f &mat) { 00276 00277 nassertv(_error_type == ET_ok); 00278 nassertv_always(!mat.is_nan()); 00279 00280 _ptr->setGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); 00281 } 00282 00283 //////////////////////////////////////////////////////////////////// 00284 // Function: PhysxActor::set_global_hpr 00285 // Access: Published 00286 // Description: Method for setting a dynamic actor's orientation in 00287 // the world. Please see set_global_mat for some 00288 // caveats. 00289 //////////////////////////////////////////////////////////////////// 00290 void PhysxActor:: 00291 set_global_hpr(float h, float p, float r) { 00292 00293 nassertv(_error_type == ET_ok); 00294 00295 LQuaternionf q; 00296 q.set_hpr(LVector3f(h, p, r)); 00297 _ptr->setGlobalOrientationQuat(PhysxManager::quat_to_nxQuat(q)); 00298 } 00299 00300 //////////////////////////////////////////////////////////////////// 00301 // Function: PhysxActor::move_global_pos 00302 // Access: Published 00303 // Description: The move_global_* calls serve to move kinematically 00304 // controlled dynamic actors through the game world. 00305 // 00306 // See move_global_mat() for more information. 00307 // 00308 // This call wakes the actor if it is sleeping. 00309 //////////////////////////////////////////////////////////////////// 00310 void PhysxActor:: 00311 move_global_pos(const LPoint3f &pos) { 00312 00313 nassertv(_error_type == ET_ok); 00314 nassertv_always(!pos.is_nan()); 00315 00316 _ptr->moveGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); 00317 } 00318 00319 //////////////////////////////////////////////////////////////////// 00320 // Function: PhysxActor::move_global_mat 00321 // Access: Published 00322 // Description: The move_global_* calls serve to move 00323 // kinematically controlled dynamic actors through 00324 // the game world. 00325 // 00326 // You set a dynamic actor to be kinematic using the 00327 // BF_KINEMATIC body flag, used either in the 00328 // PhysBodyDesc or with set_body_flag(). 00329 // 00330 // The move command will result in a velocity that, 00331 // when successfully carried out (i.e. the motion is 00332 // not blocked due to joints or collisions) inside 00333 // run*(), will move the body into the desired pose. 00334 // After the move is carried out during a single time 00335 // step, the velocity is returned to zero. Thus, you 00336 // must continuously call this in every time step for 00337 // kinematic actors so that they move along a path. 00338 // 00339 // These functions simply store the move destination 00340 // until run*() is called, so consecutive calls will 00341 // simply overwrite the stored target variable. 00342 // 00343 // This call wakes the actor if it is sleeping. 00344 //////////////////////////////////////////////////////////////////// 00345 void PhysxActor:: 00346 move_global_mat(const LMatrix4f &mat) { 00347 00348 nassertv(_error_type == ET_ok); 00349 nassertv_always(!mat.is_nan()); 00350 00351 _ptr->moveGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); 00352 } 00353 00354 //////////////////////////////////////////////////////////////////// 00355 // Function: PhysxActor::move_global_hpr 00356 // Access: Published 00357 // Description: The move_global_* calls serve to move kinematically 00358 // controlled dynamic actors through the game world. 00359 // 00360 // See move_global_mat() for more information. 00361 // 00362 // This call wakes the actor if it is sleeping. 00363 //////////////////////////////////////////////////////////////////// 00364 void PhysxActor:: 00365 move_global_hpr(float h, float p, float r) { 00366 00367 nassertv(_error_type == ET_ok); 00368 00369 LQuaternionf q; 00370 q.set_hpr(LVector3f(h, p, r)); 00371 _ptr->moveGlobalOrientationQuat(PhysxManager::quat_to_nxQuat(q)); 00372 } 00373 00374 //////////////////////////////////////////////////////////////////// 00375 // Function: PhysxActor::attach_node_path 00376 // Access: Published 00377 // Description: Attaches a node path to this actor. The node 00378 // path's transform will be updated automatically if 00379 // the actor's transform changes (and only then). 00380 // 00381 // Note: any non-uniform scale or shear set on the 00382 // NodePath's transform will be overwritten at the 00383 // time of the first update. 00384 //////////////////////////////////////////////////////////////////// 00385 void PhysxActor:: 00386 attach_node_path(const NodePath &np) { 00387 00388 nassertv(_error_type == ET_ok); 00389 nassertv_always(!np.is_empty()); 00390 00391 _np = NodePath(np); 00392 } 00393 00394 //////////////////////////////////////////////////////////////////// 00395 // Function: PhysxActor::detach_node_path 00396 // Access: Published 00397 // Description: Detaches a previously assigned NodePath from this 00398 // actor. The NodePath's transform will no longer 00399 // be updated from the actor's transform. 00400 //////////////////////////////////////////////////////////////////// 00401 void PhysxActor:: 00402 detach_node_path() { 00403 00404 nassertv(_error_type == ET_ok); 00405 00406 _np = NodePath(); 00407 } 00408 00409 //////////////////////////////////////////////////////////////////// 00410 // Function: PhysxActor::get_node_path 00411 // Access: Published 00412 // Description: Retrieves a previously attached NodePath. An empty 00413 // NodePath will be returned if no NodePath has been 00414 // attached to this actor. 00415 //////////////////////////////////////////////////////////////////// 00416 NodePath PhysxActor:: 00417 get_node_path() const { 00418 00419 nassertr(_error_type == ET_ok, NodePath::fail()); 00420 00421 return _np; 00422 } 00423 00424 //////////////////////////////////////////////////////////////////// 00425 // Function: PhysxActor::get_scene 00426 // Access: Published 00427 // Description: Retrieves the scene which this actor belongs to. 00428 //////////////////////////////////////////////////////////////////// 00429 PhysxScene *PhysxActor:: 00430 get_scene() const { 00431 00432 nassertr(_error_type == ET_ok, NULL); 00433 00434 NxScene *scenePtr = &(_ptr->getScene()); 00435 PhysxScene *scene = (PhysxScene *)(scenePtr->userData); 00436 00437 return scene; 00438 } 00439 00440 //////////////////////////////////////////////////////////////////// 00441 // Function: PhysxActor::get_num_shapes 00442 // Access: Published 00443 // Description: Returns the number of shapes assigned to the 00444 // actor. 00445 //////////////////////////////////////////////////////////////////// 00446 unsigned int PhysxActor:: 00447 get_num_shapes() const { 00448 00449 nassertr(_error_type == ET_ok, -1); 00450 00451 return _ptr->getNbShapes(); 00452 } 00453 00454 //////////////////////////////////////////////////////////////////// 00455 // Function: PhysxActor::create_shape 00456 // Access: Published 00457 // Description: Creates a new shape and adds it to the list of 00458 // shapes of this actor. 00459 // 00460 // Mass properties of dynamic actors will not 00461 // automatically be recomputed to reflect the new mass 00462 // distribution implied by the shape. Follow this call 00463 // with a call to update_mass_from_shapes() to do 00464 // that. 00465 //////////////////////////////////////////////////////////////////// 00466 PhysxShape *PhysxActor:: 00467 create_shape(PhysxShapeDesc &desc) { 00468 00469 nassertr(_error_type == ET_ok, NULL); 00470 nassertr(desc.is_valid(),NULL); 00471 00472 PhysxShape *shape = PhysxShape::factory(desc.ptr()->getType()); 00473 nassertr(shape, NULL); 00474 00475 NxShape *shapePtr = _ptr->createShape(*desc.ptr()); 00476 nassertr(shapePtr, NULL); 00477 00478 shape->link(shapePtr); 00479 00480 return shape; 00481 } 00482 00483 //////////////////////////////////////////////////////////////////// 00484 // Function: PhysxActor::get_shape 00485 // Access: Published 00486 // Description: Retrieves an individual shape from the actor's 00487 // array of shapes. Index must be in the range from 00488 // zero to (number-of-shapes minus 1). 00489 //////////////////////////////////////////////////////////////////// 00490 PhysxShape *PhysxActor:: 00491 get_shape(unsigned int idx) const { 00492 00493 nassertr(_error_type == ET_ok, NULL); 00494 nassertr_always(idx < _ptr->getNbShapes(), NULL); 00495 00496 NxShape * const *shapes = _ptr->getShapes(); 00497 NxShape *shapePtr = shapes[idx]; 00498 PhysxShape *shape = (PhysxShape *)(shapePtr->userData); 00499 00500 return shape; 00501 } 00502 00503 //////////////////////////////////////////////////////////////////// 00504 // Function: PhysxActor::get_shape_by_name 00505 // Access: Published 00506 // Description: Retrieves an individual shape from the actor's 00507 // array of shapes. The first shape for which the 00508 // shape's name matches the specified name is 00509 // returned, or NULL if no shape has a matching name. 00510 //////////////////////////////////////////////////////////////////// 00511 PhysxShape *PhysxActor:: 00512 get_shape_by_name(const char *name) const { 00513 00514 nassertr(_error_type == ET_ok, NULL); 00515 00516 NxShape * const *shapes = _ptr->getShapes(); 00517 NxShape *shapePtr = NULL; 00518 NxU32 nShapes = _ptr->getNbShapes(); 00519 00520 for (NxU32 i=0; i < nShapes; i++) { 00521 shapePtr = shapes[i]; 00522 00523 if (strcmp(shapePtr->getName(), name) == 0) { 00524 return (PhysxShape *) shapePtr->userData; 00525 } 00526 } 00527 00528 return NULL; 00529 } 00530 00531 //////////////////////////////////////////////////////////////////// 00532 // Function: PhysxActor::add_force 00533 // Access: Published 00534 // Description: Applies a force (or impulse) defined in the global 00535 // coordinate frame to the actor. 00536 // 00537 // This will not induce a torque. 00538 // 00539 // Mode determines if the torque is to be conventional 00540 // or impulsive. 00541 // 00542 // The actor must be dynamic. 00543 // This call wakes the actor if it is sleeping and the 00544 // wakeup parameter is true (default). 00545 //////////////////////////////////////////////////////////////////// 00546 void PhysxActor:: 00547 add_force(const LVector3f force, PhysxForceMode mode, bool wakeup) { 00548 00549 nassertv(_error_type == ET_ok); 00550 nassertv_always(!force.is_nan()); 00551 00552 _ptr->addForce(PhysxManager::vec3_to_nxVec3(force), (NxForceMode)mode, wakeup); 00553 } 00554 00555 //////////////////////////////////////////////////////////////////// 00556 // Function: PhysxActor::add_force_at_pos 00557 // Access: Published 00558 // Description: Applies a force (or impulse) defined in the global 00559 // coordinate frame, acting at a particular point in 00560 // global coordinates, to the actor. 00561 // 00562 // Note that if the force does not act along the 00563 // center of mass of the actor, this will also add the 00564 // corresponding torque. Because forces are reset at 00565 // the end of every timestep, you can maintain a total 00566 // external force on an object by calling this once 00567 // every frame. 00568 // 00569 // Mode determines if the torque is to be conventional 00570 // or impulsive. 00571 // 00572 // The actor must be dynamic. 00573 // This call wakes the actor if it is sleeping and the 00574 // wakeup parameter is true (default). 00575 //////////////////////////////////////////////////////////////////// 00576 void PhysxActor:: 00577 add_force_at_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { 00578 00579 nassertv(_error_type == ET_ok); 00580 nassertv_always(!force.is_nan()); 00581 nassertv_always(!pos.is_nan()); 00582 00583 _ptr->addForceAtPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); 00584 } 00585 00586 //////////////////////////////////////////////////////////////////// 00587 // Function: PhysxActor::add_force_at_local_pos 00588 // Access: Published 00589 // Description: Applies a force (or impulse) defined in the global 00590 // coordinate frame, acting at a particular point in 00591 // local coordinates, to the actor. 00592 // 00593 // Note that if the force does not act along the 00594 // center of mass of the actor, this will also add 00595 // the corresponding torque. Because forces are reset 00596 // at the end of every timestep, you can maintain a 00597 // total external force on an object by calling this 00598 // once every frame. 00599 // 00600 // Mode determines if the torque is to be conventional 00601 // or impulsive. 00602 // 00603 // The actor must be dynamic. 00604 // This call wakes the actor if it is sleeping and the 00605 // wakeup parameter is true (default). 00606 //////////////////////////////////////////////////////////////////// 00607 void PhysxActor:: 00608 add_force_at_local_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { 00609 00610 nassertv(_error_type == ET_ok); 00611 nassertv_always(!force.is_nan()); 00612 nassertv_always(!pos.is_nan()); 00613 00614 _ptr->addForceAtLocalPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); 00615 } 00616 00617 //////////////////////////////////////////////////////////////////// 00618 // Function: PhysxActor::add_torque 00619 // Access: Published 00620 // Description: Applies an impulsive torque defined in the global 00621 // coordinate frame to the actor. 00622 // 00623 // Mode determines if the torque is to be conventional 00624 // or impulsive. 00625 // 00626 // The actor must be dynamic. 00627 // This call wakes the actor if it is sleeping and the 00628 // wakeup parameter is true (default). 00629 //////////////////////////////////////////////////////////////////// 00630 void PhysxActor:: 00631 add_torque(const LVector3f torque, PhysxForceMode mode, bool wakeup) { 00632 00633 nassertv(_error_type == ET_ok); 00634 nassertv_always(!torque.is_nan()); 00635 00636 _ptr->addTorque(PhysxManager::vec3_to_nxVec3(torque), (NxForceMode)mode, wakeup); 00637 } 00638 00639 //////////////////////////////////////////////////////////////////// 00640 // Function: PhysxActor::add_local_force 00641 // Access: Published 00642 // Description: Applies a force (or impulse) defined in the actor 00643 // local coordinate frame to the actor. 00644 // This will not induce a torque. 00645 // 00646 // Mode determines if the torque is to be conventional 00647 // or impulsive. 00648 // 00649 // The actor must be dynamic. 00650 // This call wakes the actor if it is sleeping and the 00651 // wakeup parameter is true (default). 00652 //////////////////////////////////////////////////////////////////// 00653 void PhysxActor:: 00654 add_local_force(const LVector3f force, PhysxForceMode mode, bool wakeup) { 00655 00656 nassertv(_error_type == ET_ok); 00657 nassertv_always(!force.is_nan()); 00658 00659 _ptr->addLocalForce(PhysxManager::vec3_to_nxVec3(force), (NxForceMode)mode, wakeup); 00660 } 00661 00662 //////////////////////////////////////////////////////////////////// 00663 // Function: PhysxActor::add_local_force_at_pos 00664 // Access: Published 00665 // Description: Applies a force (or impulse) defined in the actor 00666 // local coordinate frame, acting at a particular 00667 // point in global coordinates, to the actor. 00668 // 00669 // Note that if the force does not act along the 00670 // center of mass of the actor, this will also add 00671 // the corresponding torque. Because forces are reset 00672 // at the end of every timestep, you can maintain a 00673 // total external force on an object by calling this 00674 // once every frame. 00675 // 00676 // Mode determines if the torque is to be conventional 00677 // or impulsive. 00678 // 00679 // The actor must be dynamic. 00680 // This call wakes the actor if it is sleeping and the 00681 // wakeup parameter is true (default). 00682 //////////////////////////////////////////////////////////////////// 00683 void PhysxActor:: 00684 add_local_force_at_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { 00685 00686 nassertv(_error_type == ET_ok); 00687 nassertv_always(!force.is_nan()); 00688 nassertv_always(!pos.is_nan()); 00689 00690 _ptr->addLocalForceAtPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); 00691 } 00692 00693 //////////////////////////////////////////////////////////////////// 00694 // Function: PhysxActor::add_local_force_at_local_pos 00695 // Access: Published 00696 // Description: Applies a force (or impulse) defined in the actor 00697 // local coordinate frame, acting at a particular 00698 // point in local coordinates, to the actor. 00699 // 00700 // Note that if the force does not act along the 00701 // center of mass of the actor, this will also add the 00702 // corresponding torque. Because forces are reset at 00703 // the end of every timestep, you can maintain a total 00704 // external force on an object by calling this once 00705 // every frame. 00706 // 00707 // Mode determines if the torque is to be conventional 00708 // or impulsive. 00709 // 00710 // The actor must be dynamic. 00711 // This call wakes the actor if it is sleeping and the 00712 // wakeup parameter is true (default). 00713 //////////////////////////////////////////////////////////////////// 00714 void PhysxActor:: 00715 add_local_force_at_local_pos(const LVector3f force, const LPoint3f &pos, PhysxForceMode mode, bool wakeup) { 00716 00717 nassertv(_error_type == ET_ok); 00718 nassertv_always(!force.is_nan()); 00719 nassertv_always(!pos.is_nan()); 00720 00721 _ptr->addLocalForceAtLocalPos(PhysxManager::vec3_to_nxVec3(force), PhysxManager::point3_to_nxVec3(pos), (NxForceMode)mode, wakeup); 00722 } 00723 00724 //////////////////////////////////////////////////////////////////// 00725 // Function: PhysxActor::add_local_torque 00726 // Access: Published 00727 // Description: Applies an impulsive torque defined in the actor 00728 // local coordinate frame to the actor. 00729 // 00730 // Mode determines if the torque is to be conventional 00731 // or impulsive. 00732 // 00733 // The actor must be dynamic. 00734 // This call wakes the actor if it is sleeping and the 00735 // wakeup parameter is true (default). 00736 //////////////////////////////////////////////////////////////////// 00737 void PhysxActor:: 00738 add_local_torque(const LVector3f torque, PhysxForceMode mode, bool wakeup) { 00739 00740 nassertv(_error_type == ET_ok); 00741 nassertv_always(!torque.is_nan()); 00742 00743 _ptr->addLocalTorque(PhysxManager::vec3_to_nxVec3(torque), (NxForceMode)mode, wakeup); 00744 } 00745 00746 //////////////////////////////////////////////////////////////////// 00747 // Function: PhysxActor::update_mass_from_shapes 00748 // Access: Published 00749 // Description: Recomputes a dynamic actor's mass properties from 00750 // its shapes. 00751 // 00752 // Given a constant density or total mass, the actors 00753 // mass properties can be recomputed using the shapes 00754 // attached to the actor. If the actor has no shapes, 00755 // then only the totalMass parameter can be used. If 00756 // all shapes in the actor are trigger shapes 00757 // (non-physical), the call will fail. 00758 // 00759 // The mass of each shape is either the shape's local 00760 // density (as specified in the PhysxShapeDesc; 00761 // default 1.0) multiplied by the shape's volume or a 00762 // directly specified shape mass. 00763 // 00764 // The inertia tensor, mass frame and center of mass 00765 // will always be recomputed. If there are no shapes 00766 // in the actor, the mass will be totalMass, and the 00767 // mass frame will be set to the center of the actor. 00768 // 00769 // If you supply a non-zero total mass, the actor's 00770 // mass and inertia will first be computed as above 00771 // and then scaled to fit this total mass. 00772 // 00773 // If you supply a non-zero density, the actor's mass 00774 // and inertia will first be computed as above and 00775 // then scaled by this factor. 00776 // 00777 // Either totalMass or density must be non-zero. 00778 // 00779 // The actor must be dynamic. 00780 //////////////////////////////////////////////////////////////////// 00781 bool PhysxActor:: 00782 update_mass_from_shapes(float density, float totalMass) { 00783 00784 nassertr(_error_type == ET_ok, false); 00785 return _ptr->updateMassFromShapes(density, totalMass); 00786 } 00787 00788 //////////////////////////////////////////////////////////////////// 00789 // Function: PhysxActor::compute_kinetic_energy 00790 // Access: Published 00791 // Description: Computes the total kinetic (rotational and 00792 // translational) energy of the object. 00793 // The actor must be dynamic. 00794 //////////////////////////////////////////////////////////////////// 00795 float PhysxActor:: 00796 compute_kinetic_energy() const { 00797 00798 nassertr(_error_type == ET_ok, 0.0f); 00799 return _ptr->computeKineticEnergy(); 00800 } 00801 00802 //////////////////////////////////////////////////////////////////// 00803 // Function: PhysxActor::is_dynamic 00804 // Access: Published 00805 // Description: Returns true if the actor is dynamic. 00806 //////////////////////////////////////////////////////////////////// 00807 bool PhysxActor:: 00808 is_dynamic() const { 00809 00810 nassertr(_error_type == ET_ok, false); 00811 return _ptr->isDynamic(); 00812 } 00813 00814 //////////////////////////////////////////////////////////////////// 00815 // Function: PhysxActor::set_shape_group 00816 // Access: Published 00817 // Description: Sets the collision group for all shapes of this 00818 // actor. See PhysxShape.setGroup(). 00819 //////////////////////////////////////////////////////////////////// 00820 void PhysxActor:: 00821 set_shape_group(unsigned int group) { 00822 00823 nassertv(_error_type == ET_ok); 00824 nassertv(group >= 0 && group < 32); 00825 00826 NxShape * const *shapes = _ptr->getShapes(); 00827 NxU32 nShapes = _ptr->getNbShapes(); 00828 00829 for (NxU32 i=0; i < nShapes; i++) { 00830 shapes[i]->setGroup( group ); 00831 } 00832 } 00833 00834 //////////////////////////////////////////////////////////////////// 00835 // Function: PhysxActor::set_body_flag 00836 // Access: Published 00837 // Description: Raise or lower individual BodyFlag flags. 00838 //////////////////////////////////////////////////////////////////// 00839 void PhysxActor:: 00840 set_body_flag(PhysxBodyFlag flag, bool value) { 00841 00842 if (value == true) { 00843 _ptr->raiseBodyFlag((NxBodyFlag)flag); 00844 } 00845 else { 00846 _ptr->clearBodyFlag((NxBodyFlag)flag); 00847 } 00848 } 00849 00850 //////////////////////////////////////////////////////////////////// 00851 // Function: PhysxActor::get_body_flag 00852 // Access: Published 00853 // Description: Return the specified BodyFlag flag. 00854 //////////////////////////////////////////////////////////////////// 00855 bool PhysxActor:: 00856 get_body_flag(PhysxBodyFlag flag) const { 00857 00858 nassertr(_error_type == ET_ok, false); 00859 return ptr()->readBodyFlag((NxBodyFlag)flag); 00860 } 00861 00862 //////////////////////////////////////////////////////////////////// 00863 // Function: PhysxActor::set_actor_flag 00864 // Access: Published 00865 // Description: Raise or lower individual ActorFlag flags. 00866 //////////////////////////////////////////////////////////////////// 00867 void PhysxActor:: 00868 set_actor_flag(PhysxActorFlag flag, bool value) { 00869 00870 if (value == true) { 00871 _ptr->raiseActorFlag((NxActorFlag)flag); 00872 } 00873 else { 00874 _ptr->clearActorFlag((NxActorFlag)flag); 00875 } 00876 } 00877 00878 //////////////////////////////////////////////////////////////////// 00879 // Function: PhysxActor::get_actor_flag 00880 // Access: Published 00881 // Description: Return the specified ActorFlag flag. 00882 //////////////////////////////////////////////////////////////////// 00883 bool PhysxActor:: 00884 get_actor_flag(PhysxActorFlag flag) const { 00885 00886 nassertr(_error_type == ET_ok, false); 00887 return ptr()->readActorFlag((NxActorFlag)flag); 00888 } 00889 00890 //////////////////////////////////////////////////////////////////// 00891 // Function: PhysxActor::set_contact_report_flag 00892 // Access: Published 00893 // Description: Sets the actor's contact report flags. 00894 // 00895 // These flags are used to determine the kind of 00896 // report that is generated for interactions with 00897 // other actors. 00898 // 00899 // Please note: If the actor is part of an interacting 00900 // pair for which the contact report generation is 00901 // controlled already through any other mechanism 00902 // (for example by use of 00903 // PhysxScene::set_actor_pair_flags) 00904 // then the union of all the specified contact report 00905 // flags will be used to generate the report. 00906 //////////////////////////////////////////////////////////////////// 00907 void PhysxActor:: 00908 set_contact_report_flag(PhysxContactPairFlag flag, bool value) { 00909 00910 nassertv(_error_type == ET_ok); 00911 00912 NxU32 flags = _ptr->getContactReportFlags(); 00913 00914 if (value == true) { 00915 flags |= flag; 00916 } 00917 else { 00918 flags &= ~(flag); 00919 } 00920 00921 _ptr->setContactReportFlags(flags); 00922 } 00923 00924 //////////////////////////////////////////////////////////////////// 00925 // Function: PhysxActor::set_contact_report_threshold 00926 // Access: Published 00927 // Description: Sets the force threshold for contact reports. 00928 // The actor must be dynamic. 00929 //////////////////////////////////////////////////////////////////// 00930 void PhysxActor:: 00931 set_contact_report_threshold(float threshold) { 00932 00933 nassertv(_error_type == ET_ok); 00934 nassertv(threshold >= 0.0f); 00935 00936 _ptr->setContactReportThreshold(threshold); 00937 } 00938 00939 //////////////////////////////////////////////////////////////////// 00940 // Function: PhysxActor::set_group 00941 // Access: Published 00942 // Description: Assigns the actor to a user defined group of 00943 // actors. The actor group must be an integer in 00944 // between 0 and 0x7fff (32767). 00945 // 00946 // This is similar to NxShape groups, except those are 00947 // only five bits and serve a different purpose. 00948 // 00949 // The PhysxScene::set_actor_group_pair_flags() lets 00950 // you set certain behaviors for pairs of actor 00951 // groups. 00952 // 00953 // By default every actor is created in group 0. 00954 //////////////////////////////////////////////////////////////////// 00955 void PhysxActor:: 00956 set_group(unsigned int group) { 00957 00958 nassertv(_error_type == ET_ok); 00959 nassertv(group >= 0 && group < 0x8000); 00960 00961 ptr()->setGroup(group); 00962 } 00963 00964 //////////////////////////////////////////////////////////////////// 00965 // Function: PhysxActor::get_group 00966 // Access: Published 00967 // Description: Retrieves the actor group this actor is assigned 00968 // to. 00969 //////////////////////////////////////////////////////////////////// 00970 unsigned int PhysxActor:: 00971 get_group() const { 00972 00973 nassertr(_error_type == ET_ok, 0); 00974 00975 return ptr()->getGroup(); 00976 } 00977 00978 //////////////////////////////////////////////////////////////////// 00979 // Function: PhysxActor::set_dominance_group 00980 // Access: Published 00981 // Description: Assigns dynamic actors a dominance group 00982 // identifier. Dominance groups are integere in the 00983 // range from 0 to 31. 00984 // 00985 // This is similar to shape groups, except those serve 00986 // a different purpose. 00987 // 00988 // The PhysxScene::set_dominance_group_pair() lets you 00989 // set certain behaviors for pairs of dominance 00990 // groups. 00991 // 00992 // By default every actor is created in group 0. 00993 // Static actors must stay in group 0; thus you can 00994 // only call this on dynamic actors. 00995 //////////////////////////////////////////////////////////////////// 00996 void PhysxActor:: 00997 set_dominance_group(unsigned int group) { 00998 00999 nassertv(_error_type == ET_ok); 01000 nassertv(group >= 0 && group < 32); 01001 nassertv(is_dynamic() == true); 01002 01003 _ptr->setDominanceGroup(group); 01004 } 01005 01006 //////////////////////////////////////////////////////////////////// 01007 // Function: PhysxActor::get_dominance_group 01008 // Access: Published 01009 // Description: Retrieves the dominance group of this actor. 01010 //////////////////////////////////////////////////////////////////// 01011 unsigned int PhysxActor:: 01012 get_dominance_group() const { 01013 01014 nassertr(_error_type == ET_ok, 0); 01015 01016 return ptr()->getDominanceGroup(); 01017 } 01018 01019 //////////////////////////////////////////////////////////////////// 01020 // Function: PhysxActor::set_angular_damping 01021 // Access: Published 01022 // Description: Sets the angular damping coefficient. Zero 01023 // represents no damping. The angular damping 01024 // coefficient must be nonnegative. The actor must be 01025 // dynamic. 01026 // Default: 0.05 01027 //////////////////////////////////////////////////////////////////// 01028 void PhysxActor:: 01029 set_angular_damping(float angDamp) { 01030 01031 nassertv(_error_type == ET_ok); 01032 nassertv(angDamp >= 0.0f); 01033 01034 _ptr->setAngularDamping(angDamp); 01035 } 01036 01037 //////////////////////////////////////////////////////////////////// 01038 // Function: PhysxActor::get_angular_damping 01039 // Access: Published 01040 // Description: Returns the angular damping coefficient. 01041 // The actor must be dynamic. 01042 //////////////////////////////////////////////////////////////////// 01043 float PhysxActor:: 01044 get_angular_damping() const { 01045 01046 nassertr(_error_type == ET_ok, 0.0f); 01047 return _ptr->getAngularDamping(); 01048 } 01049 01050 //////////////////////////////////////////////////////////////////// 01051 // Function: PhysxActor::set_linear_damping 01052 // Access: Published 01053 // Description: Sets the linear damping coefficient. Zero 01054 // represents no damping. The damping coefficient must 01055 // be nonnegative. The actor must be dynamic. 01056 // Default: 0 01057 //////////////////////////////////////////////////////////////////// 01058 void PhysxActor:: 01059 set_linear_damping(float linDamp) { 01060 01061 nassertv(_error_type == ET_ok); 01062 nassertv(linDamp >= 0.0f); 01063 01064 _ptr->setLinearDamping(linDamp); 01065 } 01066 01067 //////////////////////////////////////////////////////////////////// 01068 // Function: PhysxActor::get_linear_damping 01069 // Access: Published 01070 // Description: Retrieves the linear damping coefficient. 01071 // The actor must be dynamic. 01072 //////////////////////////////////////////////////////////////////// 01073 float PhysxActor:: 01074 get_linear_damping() const { 01075 01076 nassertr(_error_type == ET_ok, 0.0f); 01077 return _ptr->getLinearDamping(); 01078 } 01079 01080 //////////////////////////////////////////////////////////////////// 01081 // Function: PhysxActor::set_linear_velocity 01082 // Access: Published 01083 // Description: Sets the linear velocity of the actor. 01084 // 01085 // Note that if you continuously set the velocity of 01086 // an actor yourself, forces such as gravity or 01087 // friction will not be able to manifest themselves, 01088 // because forces directly influence only the 01089 // velocity/momentum of an actor. 01090 // 01091 // The actor must be dynamic. 01092 //////////////////////////////////////////////////////////////////// 01093 void PhysxActor:: 01094 set_linear_velocity(const LVector3f &linVel) { 01095 01096 nassertv(_error_type == ET_ok); 01097 nassertv(_ptr->isDynamic()); 01098 01099 _ptr->setLinearVelocity(PhysxManager::vec3_to_nxVec3(linVel)); 01100 } 01101 01102 //////////////////////////////////////////////////////////////////// 01103 // Function: PhysxActor::set_angular_velocity 01104 // Access: Published 01105 // Description: Sets the angular velocity of the actor. 01106 // 01107 // Note that if you continuously set the angular 01108 // velocity of an actor yourself, forces such as 01109 // friction will not be able to rotate the actor, 01110 // because forces directly influence only the 01111 // velocity/momentum. 01112 // 01113 // The actor must be dynamic. 01114 //////////////////////////////////////////////////////////////////// 01115 void PhysxActor:: 01116 set_angular_velocity(const LVector3f &angVel) { 01117 01118 nassertv(_error_type == ET_ok); 01119 nassertv(_ptr->isDynamic()); 01120 01121 _ptr->setAngularVelocity(PhysxManager::vec3_to_nxVec3(angVel)); 01122 } 01123 01124 //////////////////////////////////////////////////////////////////// 01125 // Function: PhysxActor::set_max_angular_velocity 01126 // Access: Published 01127 // Description: Lets you set the maximum angular velocity permitted 01128 // for this actor. 01129 // 01130 // Because for various internal computations, very 01131 // quickly rotating actors introduce error into the 01132 // simulation, which leads to undesired results. 01133 // 01134 // With PhysxManager::set_parameter(PP_max_angular_velocity) 01135 // you can set the default maximum velocity for actors 01136 // created after the call. Bodies' high angular 01137 // velocities are clamped to this value. 01138 // 01139 // However, because some actors, such as car wheels, 01140 // should be able to rotate quickly, you can override 01141 // the default setting on a per-actor basis with the 01142 // below call. Note that objects such as wheels which 01143 // are approximated with spherical or other smooth 01144 // collision primitives can be simulated with 01145 // stability at a much higher angular velocity than, 01146 // say, a box that has corners. 01147 // 01148 // The actor must be dynamic. 01149 //////////////////////////////////////////////////////////////////// 01150 void PhysxActor:: 01151 set_max_angular_velocity(float maxAngVel) { 01152 01153 nassertv(_error_type == ET_ok); 01154 nassertv(_ptr->isDynamic()); 01155 01156 _ptr->setMaxAngularVelocity(maxAngVel); 01157 } 01158 01159 //////////////////////////////////////////////////////////////////// 01160 // Function: PhysxActor::get_linear_velocity 01161 // Access: Published 01162 // Description: Returns the linear velocity of an actor. 01163 // The actor must be dynamic. 01164 //////////////////////////////////////////////////////////////////// 01165 LVector3f PhysxActor:: 01166 get_linear_velocity() const { 01167 01168 nassertr(_error_type == ET_ok, LVector3f::zero()); 01169 return PhysxManager::nxVec3_to_vec3(_ptr->getLinearVelocity()); 01170 } 01171 01172 //////////////////////////////////////////////////////////////////// 01173 // Function: PhysxActor::get_angular_velocity 01174 // Access: Published 01175 // Description: Returns the angular velocity of the actor. 01176 // The actor must be dynamic. 01177 //////////////////////////////////////////////////////////////////// 01178 LVector3f PhysxActor:: 01179 get_angular_velocity() const { 01180 01181 nassertr(_error_type == ET_ok, LVector3f::zero()); 01182 return PhysxManager::nxVec3_to_vec3(_ptr->getAngularVelocity()); 01183 } 01184 01185 //////////////////////////////////////////////////////////////////// 01186 // Function: PhysxActor::get_max_angular_velocity 01187 // Access: Published 01188 // Description: Returns the maximum angular velocity permitted 01189 // for this actor. 01190 //////////////////////////////////////////////////////////////////// 01191 float PhysxActor:: 01192 get_max_angular_velocity() const { 01193 01194 nassertr(_error_type == ET_ok, 0.0f); 01195 return _ptr->getMaxAngularVelocity(); 01196 } 01197 01198 //////////////////////////////////////////////////////////////////// 01199 // Function: PhysxActor::get_point_velocity 01200 // Access: Published 01201 // Description: Computes the velocity of a point given in world 01202 // coordinates if it were attached to the actor and 01203 // moving with it. 01204 // 01205 // The actor must be dynamic. 01206 //////////////////////////////////////////////////////////////////// 01207 LVector3f PhysxActor:: 01208 get_point_velocity(const LPoint3f &point) const { 01209 01210 nassertr(_error_type == ET_ok, LVector3f::zero()); 01211 nassertr_always(!point.is_nan(), LVector3f::zero()); 01212 01213 NxVec3 nPoint = PhysxManager::point3_to_nxVec3(point); 01214 return PhysxManager::nxVec3_to_vec3(_ptr->getPointVelocity(nPoint)); 01215 } 01216 01217 //////////////////////////////////////////////////////////////////// 01218 // Function: PhysxActor::get_local_point_velocity 01219 // Access: Published 01220 // Description: Computes the velocity of a point given in body 01221 // local coordinates as if it were attached to the 01222 // actor and moving with it. 01223 // 01224 // The actor must be dynamic. 01225 //////////////////////////////////////////////////////////////////// 01226 LVector3f PhysxActor:: 01227 get_local_point_velocity(const LPoint3f &point) const { 01228 01229 nassertr(_error_type == ET_ok, LVector3f::zero()); 01230 nassertr_always(!point.is_nan(), LVector3f::zero()); 01231 01232 NxVec3 nPoint = PhysxManager::point3_to_nxVec3(point); 01233 return PhysxManager::nxVec3_to_vec3(_ptr->getLocalPointVelocity(nPoint)); 01234 } 01235 01236 //////////////////////////////////////////////////////////////////// 01237 // Function: PhysxActor::set_linear_momentum 01238 // Access: Published 01239 // Description: Sets the linear momentum of the actor. 01240 // Note that if you continuously set the linear 01241 // momentum of an actor yourself, forces such as 01242 // gravity or friction will not be able to manifest 01243 // themselves, because forces directly influence only 01244 // the velocity/momentum of a actor. 01245 // The actor must be dynamic. 01246 //////////////////////////////////////////////////////////////////// 01247 void PhysxActor:: 01248 set_linear_momentum(const LVector3f &momentum) { 01249 01250 nassertv(_error_type == ET_ok); 01251 _ptr->setLinearMomentum(PhysxManager::vec3_to_nxVec3(momentum)); 01252 } 01253 01254 //////////////////////////////////////////////////////////////////// 01255 // Function: PhysxActor::set_angular_momentum 01256 // Access: Published 01257 // Description: Sets the angular momentum of the actor. 01258 // Note that if you continuously set the angular 01259 // velocity of an actor yourself, forces such as 01260 // friction will not be able to rotate the actor, 01261 // because forces directly influence only the velocity 01262 // of actor. 01263 // The actor must be dynamic. 01264 //////////////////////////////////////////////////////////////////// 01265 void PhysxActor:: 01266 set_angular_momentum(const LVector3f &momentum) { 01267 01268 nassertv(_error_type == ET_ok); 01269 _ptr->setAngularMomentum(PhysxManager::vec3_to_nxVec3(momentum)); 01270 } 01271 01272 //////////////////////////////////////////////////////////////////// 01273 // Function: PhysxActor::get_linear_momentum 01274 // Access: Published 01275 // Description: Retrieves the linear momentum of an actor. 01276 // The momentum is equal to the velocity times the 01277 // mass. 01278 // The actor must be dynamic. 01279 //////////////////////////////////////////////////////////////////// 01280 LVector3f PhysxActor:: 01281 get_linear_momentum() const { 01282 01283 nassertr(_error_type == ET_ok, LVector3f::zero()); 01284 return PhysxManager::nxVec3_to_vec3(_ptr->getLinearMomentum()); 01285 } 01286 01287 //////////////////////////////////////////////////////////////////// 01288 // Function: PhysxActor::get_angular_momentum 01289 // Access: Published 01290 // Description: Retrieves the angular momentum of an actor. 01291 // The angular momentum is equal to the angular 01292 // velocity times the global space inertia tensor. 01293 // The actor must be dynamic. 01294 //////////////////////////////////////////////////////////////////// 01295 LVector3f PhysxActor:: 01296 get_angular_momentum() const { 01297 01298 nassertr(_error_type == ET_ok, LVector3f::zero()); 01299 return PhysxManager::nxVec3_to_vec3(_ptr->getAngularMomentum()); 01300 } 01301 01302 //////////////////////////////////////////////////////////////////// 01303 // Function: PhysxActor::set_sleep_linear_velocity 01304 // Access: Published 01305 // Description: Sets the linear velocity below which an actor may 01306 // go to sleep. Actors whose linear velocity is above 01307 // this threshold will not be put to sleep. 01308 // 01309 // Setting the sleep angular/linear velocity only 01310 // makes sense when the BF_energy_sleep_test is not 01311 // set. 01312 // 01313 // The actor must be dynamic. 01314 //////////////////////////////////////////////////////////////////// 01315 void PhysxActor:: 01316 set_sleep_linear_velocity(float threshold) { 01317 01318 nassertv(_error_type == ET_ok); 01319 _ptr->setSleepLinearVelocity(threshold); 01320 } 01321 01322 //////////////////////////////////////////////////////////////////// 01323 // Function: PhysxActor::set_sleep_angular_velocity 01324 // Access: Published 01325 // Description: Sets the angular velocity below which an actor may 01326 // go to sleep. Actors whose angular velocity is 01327 // above this threshold will not be put to sleep. 01328 // 01329 // Setting the sleep angular/linear velocity only 01330 // makes sense when the BF_energy_sleep_test is not 01331 // set. 01332 // 01333 // The actor must be dynamic. 01334 //////////////////////////////////////////////////////////////////// 01335 void PhysxActor:: 01336 set_sleep_angular_velocity(float threshold) { 01337 01338 nassertv(_error_type == ET_ok); 01339 _ptr->setSleepAngularVelocity(threshold); 01340 } 01341 01342 //////////////////////////////////////////////////////////////////// 01343 // Function: PhysxActor::set_sleep_energy_threshold 01344 // Access: Published 01345 // Description: Sets the energy threshold below which an actor may 01346 // go to sleep. Actors whose kinematic energy is above 01347 // this threshold will not be put to sleep. 01348 // 01349 // Setting the sleep energy threshold only makes sense 01350 // when the BF_energy_sleep_test is set. There are 01351 // also other types of sleeping that uses the linear 01352 // and angular velocities directly instead of the 01353 // energy. 01354 // 01355 // The actor must be dynamic. 01356 //////////////////////////////////////////////////////////////////// 01357 void PhysxActor:: 01358 set_sleep_energy_threshold(float threshold) { 01359 01360 nassertv(_error_type == ET_ok); 01361 _ptr->setSleepEnergyThreshold(threshold); 01362 } 01363 01364 //////////////////////////////////////////////////////////////////// 01365 // Function: PhysxActor::get_sleep_linear_velocity 01366 // Access: Published 01367 // Description: Returns the linear velocity below which an actor 01368 // may go to sleep. Actors whose linear velocity is 01369 // above this threshold will not be put to sleep. 01370 // The actor must be dynamic. 01371 //////////////////////////////////////////////////////////////////// 01372 float PhysxActor:: 01373 get_sleep_linear_velocity() const { 01374 01375 nassertr(_error_type == ET_ok, 0.0f); 01376 return _ptr->getSleepLinearVelocity(); 01377 } 01378 01379 //////////////////////////////////////////////////////////////////// 01380 // Function: PhysxActor::get_sleep_angular_velocity 01381 // Access: Published 01382 // Description: Returns the angular velocity below which an actor 01383 // may go to sleep. Actors whose angular velocity is 01384 // above this threshold will not be put to sleep. 01385 // The actor must be dynamic. 01386 //////////////////////////////////////////////////////////////////// 01387 float PhysxActor:: 01388 get_sleep_angular_velocity() const { 01389 01390 nassertr(_error_type == ET_ok, 0.0f); 01391 return _ptr->getSleepAngularVelocity(); 01392 } 01393 01394 //////////////////////////////////////////////////////////////////// 01395 // Function: PhysxActor::get_sleep_energy_threshold 01396 // Access: Published 01397 // Description: Returns the energy below which an actor may go to 01398 // sleep. Actors whose energy is above this threshold 01399 // will not be put to sleep. The actor must be dynamic. 01400 //////////////////////////////////////////////////////////////////// 01401 float PhysxActor:: 01402 get_sleep_energy_threshold() const { 01403 01404 nassertr(_error_type == ET_ok, 0.0f); 01405 return _ptr->getSleepEnergyThreshold(); 01406 } 01407 01408 //////////////////////////////////////////////////////////////////// 01409 // Function: PhysxActor::is_sleeping 01410 // Access: Published 01411 // Description: Returns true if this body is sleeping. 01412 // 01413 // When an actor does not move for a period of time, 01414 // it is no longer simulated in order to save time. 01415 // This state is called sleeping. However, because the 01416 // object automatically wakes up when it is either 01417 // touched by an awake object, or one of its 01418 // properties is changed by the user, the entire sleep 01419 // mechanism should be transparent to the user. 01420 // 01421 // The actor must be dynamic. 01422 //////////////////////////////////////////////////////////////////// 01423 bool PhysxActor:: 01424 is_sleeping() const { 01425 01426 nassertr(_error_type == ET_ok, false); 01427 return _ptr->isSleeping(); 01428 } 01429 01430 //////////////////////////////////////////////////////////////////// 01431 // Function: PhysxActor::wake_up 01432 // Access: Published 01433 // Description: Wakes up the actor if it is sleeping. 01434 // 01435 // The wakeCounterValue determines how long until the 01436 // body is put to sleep, a value of zero means that 01437 // the body is sleeping. wake_up(0) is equivalent to 01438 // PhysxActor::put_to_sleep(). 01439 // 01440 // The actor must be dynamic. 01441 //////////////////////////////////////////////////////////////////// 01442 void PhysxActor:: 01443 wake_up(float wakeCounterValue) { 01444 01445 nassertv(_error_type == ET_ok); 01446 _ptr->wakeUp(wakeCounterValue); 01447 } 01448 01449 //////////////////////////////////////////////////////////////////// 01450 // Function: PhysxActor::put_to_sleep 01451 // Access: Published 01452 // Description: Forces the actor to sleep. 01453 // 01454 // The actor will stay asleep until the next call to 01455 // simulate, and will not wake up until then even when 01456 // otherwise it would (for example a force is applied 01457 // to it). It can however wake up during the next 01458 // do_physics call. 01459 // 01460 // The actor must be dynamic. 01461 //////////////////////////////////////////////////////////////////// 01462 void PhysxActor:: 01463 put_to_sleep() { 01464 01465 nassertv(_error_type == ET_ok); 01466 _ptr->putToSleep(); 01467 } 01468 01469 //////////////////////////////////////////////////////////////////// 01470 // Function: PhysxActor::set_mass 01471 // Access: Published 01472 // Description: Sets the mass of a dynamic actor. 01473 //////////////////////////////////////////////////////////////////// 01474 void PhysxActor:: 01475 set_mass(float mass) { 01476 01477 nassertv(_error_type == ET_ok); 01478 _ptr->setMass(mass); 01479 } 01480 01481 //////////////////////////////////////////////////////////////////// 01482 // Function: PhysxActor::get_mass 01483 // Access: Published 01484 // Description: Returns the mass of the actor. 01485 //////////////////////////////////////////////////////////////////// 01486 float PhysxActor:: 01487 get_mass() const { 01488 01489 nassertr(_error_type == ET_ok, 0.0f); 01490 return _ptr->getMass(); 01491 } 01492 01493 //////////////////////////////////////////////////////////////////// 01494 // Function: PhysxActor::set_c_mass_offset_local_mat 01495 // Access: Published 01496 // Description: Sets the matrix of the center of mass relative 01497 // to the actor. 01498 //////////////////////////////////////////////////////////////////// 01499 void PhysxActor:: 01500 set_c_mass_offset_local_mat(const LMatrix4f &mat) { 01501 01502 nassertv(_error_type == ET_ok); 01503 _ptr->setCMassOffsetLocalPose(PhysxManager::mat4_to_nxMat34(mat)); 01504 } 01505 01506 //////////////////////////////////////////////////////////////////// 01507 // Function: PhysxActor::set_c_mass_offset_local_pos 01508 // Access: Published 01509 // Description: Sets the position of the center of mass relative 01510 // to the actor. 01511 //////////////////////////////////////////////////////////////////// 01512 void PhysxActor:: 01513 set_c_mass_offset_local_pos(const LPoint3f &pos) { 01514 01515 nassertv(_error_type == ET_ok); 01516 _ptr->setCMassOffsetLocalPosition(PhysxManager::point3_to_nxVec3(pos)); 01517 } 01518 01519 //////////////////////////////////////////////////////////////////// 01520 // Function: PhysxActor::set_c_mass_offset_local_orientation 01521 // Access: Published 01522 // Description: Sets the orientation of the center of mass relative 01523 // to the actor. 01524 //////////////////////////////////////////////////////////////////// 01525 void PhysxActor:: 01526 set_c_mass_offset_local_orientation(const LMatrix3f &mat) { 01527 01528 nassertv(_error_type == ET_ok); 01529 _ptr->setCMassOffsetLocalOrientation(PhysxManager::mat3_to_nxMat33(mat)); 01530 } 01531 01532 //////////////////////////////////////////////////////////////////// 01533 // Function: PhysxActor::set_c_mass_offset_global_mat 01534 // Access: Published 01535 // Description: Sets the matrix of the center of mass relative 01536 // to world space. 01537 //////////////////////////////////////////////////////////////////// 01538 void PhysxActor:: 01539 set_c_mass_offset_global_mat(const LMatrix4f &mat) { 01540 01541 nassertv(_error_type == ET_ok); 01542 _ptr->setCMassOffsetGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); 01543 } 01544 01545 //////////////////////////////////////////////////////////////////// 01546 // Function: PhysxActor::set_c_mass_offset_global_pos 01547 // Access: Published 01548 // Description: Sets the position of the center of mass relative 01549 // to world space. 01550 //////////////////////////////////////////////////////////////////// 01551 void PhysxActor:: 01552 set_c_mass_offset_global_pos(const LPoint3f &pos) { 01553 01554 nassertv(_error_type == ET_ok); 01555 _ptr->setCMassOffsetGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); 01556 } 01557 01558 //////////////////////////////////////////////////////////////////// 01559 // Function: PhysxActor::set_c_mass_offset_global_orientation 01560 // Access: Published 01561 // Description: Sets the orientation of the center of mass relative 01562 // to world space. 01563 //////////////////////////////////////////////////////////////////// 01564 void PhysxActor:: 01565 set_c_mass_offset_global_orientation(const LMatrix3f &mat) { 01566 01567 nassertv(_error_type == ET_ok); 01568 _ptr->setCMassOffsetGlobalOrientation(PhysxManager::mat3_to_nxMat33(mat)); 01569 } 01570 01571 //////////////////////////////////////////////////////////////////// 01572 // Function: PhysxActor::set_c_mass_global_mat 01573 // Access: Published 01574 // Description: Moves the actor by setting the transform of the 01575 // center of mass. 01576 //////////////////////////////////////////////////////////////////// 01577 void PhysxActor:: 01578 set_c_mass_global_mat(const LMatrix4f &mat) { 01579 01580 nassertv(_error_type == ET_ok); 01581 _ptr->setCMassGlobalPose(PhysxManager::mat4_to_nxMat34(mat)); 01582 } 01583 01584 //////////////////////////////////////////////////////////////////// 01585 // Function: PhysxActor::set_c_mass_global_pos 01586 // Access: Published 01587 // Description: Moves the actor by setting the position of the 01588 // center of mass. 01589 //////////////////////////////////////////////////////////////////// 01590 void PhysxActor:: 01591 set_c_mass_global_pos(const LPoint3f &pos) { 01592 01593 nassertv(_error_type == ET_ok); 01594 _ptr->setCMassGlobalPosition(PhysxManager::point3_to_nxVec3(pos)); 01595 } 01596 01597 //////////////////////////////////////////////////////////////////// 01598 // Function: PhysxActor::set_c_mass_global_orientation 01599 // Access: Published 01600 // Description: Moves the actor by setting the orientation of the 01601 // center of mass. 01602 //////////////////////////////////////////////////////////////////// 01603 void PhysxActor:: 01604 set_c_mass_global_orientation(const LMatrix3f &mat) { 01605 01606 nassertv(_error_type == ET_ok); 01607 _ptr->setCMassGlobalOrientation(PhysxManager::mat3_to_nxMat33(mat)); 01608 } 01609 01610 //////////////////////////////////////////////////////////////////// 01611 // Function: PhysxActor::set_mass_space_inertia_tensor 01612 // Access: Published 01613 // Description: Sets the inertia tensor, using a parameter 01614 // specified in mass space coordinates. 01615 //////////////////////////////////////////////////////////////////// 01616 void PhysxActor:: 01617 set_mass_space_inertia_tensor(const LVector3f &m) { 01618 01619 nassertv(_error_type == ET_ok); 01620 _ptr->setMassSpaceInertiaTensor(PhysxManager::vec3_to_nxVec3(m)); 01621 } 01622 01623 //////////////////////////////////////////////////////////////////// 01624 // Function: PhysxActor::get_c_mass_global_mat 01625 // Access: Published 01626 // Description: Returns the center of mass transform in world 01627 // space. 01628 //////////////////////////////////////////////////////////////////// 01629 LMatrix4f PhysxActor:: 01630 get_c_mass_global_mat() const { 01631 01632 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); 01633 return PhysxManager::nxMat34_to_mat4(_ptr->getCMassGlobalPose()); 01634 } 01635 01636 //////////////////////////////////////////////////////////////////// 01637 // Function: PhysxActor::get_c_mass_global_pos 01638 // Access: Published 01639 // Description: Returns the center of mass position in world 01640 // space. 01641 //////////////////////////////////////////////////////////////////// 01642 LPoint3f PhysxActor:: 01643 get_c_mass_global_pos() const { 01644 01645 nassertr(_error_type == ET_ok, LPoint3f::zero()); 01646 return PhysxManager::nxVec3_to_point3(_ptr->getCMassGlobalPosition()); 01647 } 01648 01649 //////////////////////////////////////////////////////////////////// 01650 // Function: PhysxActor::get_c_mass_global_orientation 01651 // Access: Published 01652 // Description: Returns the center of mass orientation in world 01653 // space. 01654 //////////////////////////////////////////////////////////////////// 01655 LMatrix3f PhysxActor:: 01656 get_c_mass_global_orientation() const { 01657 01658 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); 01659 return PhysxManager::nxMat33_to_mat3(_ptr->getCMassGlobalOrientation()); 01660 } 01661 01662 //////////////////////////////////////////////////////////////////// 01663 // Function: PhysxActor::get_c_mass_local_mat 01664 // Access: Published 01665 // Description: Returns the center of mass transform relative 01666 // to the actor. 01667 //////////////////////////////////////////////////////////////////// 01668 LMatrix4f PhysxActor:: 01669 get_c_mass_local_mat() const { 01670 01671 nassertr(_error_type == ET_ok, LMatrix4f::zeros_mat()); 01672 return PhysxManager::nxMat34_to_mat4(_ptr->getCMassLocalPose()); 01673 } 01674 01675 //////////////////////////////////////////////////////////////////// 01676 // Function: PhysxActor::get_c_mass_local_pos 01677 // Access: Published 01678 // Description: Returns the center of mass position relative to 01679 // the actor. 01680 //////////////////////////////////////////////////////////////////// 01681 LPoint3f PhysxActor:: 01682 get_c_mass_local_pos() const { 01683 01684 nassertr(_error_type == ET_ok, LPoint3f::zero()); 01685 return PhysxManager::nxVec3_to_point3(_ptr->getCMassLocalPosition()); 01686 } 01687 01688 //////////////////////////////////////////////////////////////////// 01689 // Function: PhysxActor::get_c_mass_local_orientation 01690 // Access: Published 01691 // Description: Returns the center of mass orientation relative to 01692 // the actor. 01693 //////////////////////////////////////////////////////////////////// 01694 LMatrix3f PhysxActor:: 01695 get_c_mass_local_orientation() const { 01696 01697 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); 01698 return PhysxManager::nxMat33_to_mat3(_ptr->getCMassLocalOrientation()); 01699 } 01700 01701 //////////////////////////////////////////////////////////////////// 01702 // Function: PhysxActor::get_mass_space_inertia_tensor 01703 // Access: Published 01704 // Description: Returns the diagonal inertia tensor of the actor 01705 // relative to the mass coordinate frame. 01706 //////////////////////////////////////////////////////////////////// 01707 LVector3f PhysxActor:: 01708 get_mass_space_inertia_tensor() const { 01709 01710 nassertr(_error_type == ET_ok, LVector3f::zero()); 01711 return PhysxManager::nxVec3_to_vec3(_ptr->getMassSpaceInertiaTensor()); 01712 } 01713 01714 //////////////////////////////////////////////////////////////////// 01715 // Function: PhysxActor::get_global_inertia_tensor 01716 // Access: Published 01717 // Description: Returns the inertia tensor of the actor relative 01718 // to the world coordinate frame. 01719 //////////////////////////////////////////////////////////////////// 01720 LMatrix3f PhysxActor:: 01721 get_global_inertia_tensor() const { 01722 01723 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); 01724 return PhysxManager::nxMat33_to_mat3(_ptr->getGlobalInertiaTensor()); 01725 } 01726 01727 //////////////////////////////////////////////////////////////////// 01728 // Function: PhysxActor::get_global_inertia_tensor_inverse 01729 // Access: Published 01730 // Description: Returns the inverse of the inertia tensor of the 01731 // actor relative to the world coordinate frame. 01732 //////////////////////////////////////////////////////////////////// 01733 LMatrix3f PhysxActor:: 01734 get_global_inertia_tensor_inverse() const { 01735 01736 nassertr(_error_type == ET_ok, LMatrix3f::ident_mat()); 01737 return PhysxManager::nxMat33_to_mat3(_ptr->getGlobalInertiaTensorInverse()); 01738 } 01739