Panda3D
 All Classes Functions Variables Enumerations
physxBoxController.cxx
1 // Filename: physxBoxController.cxx
2 // Created by: enn0x (24Sep09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "physxBoxController.h"
16 #include "physxManager.h"
17 
18 TypeHandle PhysxBoxController::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: PhysxBoxController::link
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 void PhysxBoxController::
26 link(NxController *controllerPtr) {
27 
28  nassertv(controllerPtr->getType() == NX_CONTROLLER_BOX);
29 
30  // Link self
31  _ptr = (NxBoxController *)controllerPtr;
32  _error_type = ET_ok;
33 
34  PhysxScene *scene = (PhysxScene *)_ptr->getActor()->getScene().userData;
35  scene->_controllers.add(this);
36 
37  // Link actor
38  PT(PhysxActor) actor = new PhysxActor();
39  actor->link(_ptr->getActor());
40  actor->link_controller(this);
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: PhysxBoxController::unlink
45 // Access: Public
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 void PhysxBoxController::
49 unlink() {
50 
51  // Unlink actor
52  PT(PhysxActor) actor = (PhysxActor *)ptr()->getActor()->userData;
53  actor->unlink();
54 
55  // Unlink self
56  _error_type = ET_released;
57 
58  PhysxScene *scene = (PhysxScene *)_ptr->getActor()->getScene().userData;
59  scene->_controllers.remove(this);
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: PhysxBoxController::set_extents
64 // Access: Published
65 // Description: Sets controller's extents.
66 ////////////////////////////////////////////////////////////////////
67 void PhysxBoxController::
68 set_extents(const LVector3f &extents) {
69 
70  nassertv(_error_type == ET_ok);
71  _ptr->setExtents(PhysxManager::vec3_to_nxVec3(extents));
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: PhysxBoxController::get_extents
76 // Access: Published
77 // Description: Returns controller's extents.
78 ////////////////////////////////////////////////////////////////////
80 get_extents() const {
81 
82  nassertr(_error_type == ET_ok, LVector3f::zero());
83  return PhysxManager::nxVec3_to_vec3(_ptr->getExtents());
84 }
85 
static const LVector3f & zero()
Returns a zero-length vector.
Definition: lvector3.h:269
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
LVector3f get_extents() const
Returns controller's extents.
Box character controller.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
Definition: physxManager.I:33
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
Definition: physxManager.I:44
Actors are the main simulation objects.
Definition: physxActor.h:48
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void set_extents(const LVector3f &extents)
Sets controller's extents.