Panda3D
physxSphericalJoint.cxx
1 // Filename: physxSphericalJoint.cxx
2 // Created by: enn0x (02Oct09)
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 "physxSphericalJoint.h"
16 #include "physxSphericalJointDesc.h"
17 
18 TypeHandle PhysxSphericalJoint::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: PhysxSphericalJoint::link
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 void PhysxSphericalJoint::
26 link(NxJoint *jointPtr) {
27 
28  _ptr = jointPtr->isSphericalJoint();
29  _ptr->userData = this;
30  _error_type = ET_ok;
31 
32  set_name(jointPtr->getName());
33 
34  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
35  scene->_joints.add(this);
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: PhysxSphericalJoint::unlink
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 void PhysxSphericalJoint::
44 unlink() {
45 
46  _ptr->userData = NULL;
47  _error_type = ET_released;
48 
49  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
50  scene->_joints.remove(this);
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function : PhysxSphericalJoint::save_to_desc
55 // Access : Published
56 // Description : Saves the state of the joint object to a
57 // descriptor.
58 ////////////////////////////////////////////////////////////////////
61 
62  nassertv(_error_type == ET_ok);
63  _ptr->saveToDesc(jointDesc._desc);
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function : PhysxSphericalJoint::load_from_desc
68 // Access : Published
69 // Description : Loads the entire state of the joint from a
70 // descriptor with a single call.
71 ////////////////////////////////////////////////////////////////////
74 
75  nassertv(_error_type == ET_ok);
76  _ptr->loadFromDesc(jointDesc._desc);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: PhysxSphericalJoint::set_projection_mode
81 // Access: Published
82 // Description: Sets the joint projection mode.
83 ////////////////////////////////////////////////////////////////////
85 set_projection_mode(PhysxProjectionMode mode) {
86 
87  nassertv(_error_type == ET_ok);
88  _ptr->setProjectionMode((NxJointProjectionMode)mode);
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: PhysxSphericalJoint::get_projection_mode
93 // Access: Published
94 // Description: Returns the current projection mode settings.
95 ////////////////////////////////////////////////////////////////////
96 PhysxEnums::PhysxProjectionMode PhysxSphericalJoint::
98 
99  nassertr(_error_type == ET_ok, PM_none);
100  return (PhysxProjectionMode)_ptr->getProjectionMode();
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: PhysxSphericalJoint::set_flag
105 // Access: Published
106 // Description: Sets or clears a single SphericalJointFlag.
107 ////////////////////////////////////////////////////////////////////
109 set_flag(PhysxSphericalJointFlag flag, bool value) {
110 
111  nassertv(_error_type == ET_ok);
112  NxU32 flags = _ptr->getFlags();
113 
114  if (value == true) {
115  flags |= flag;
116  }
117  else {
118  flags &= ~(flag);
119  }
120 
121  _ptr->setFlags(flags);
122 }
123 
124 ////////////////////////////////////////////////////////////////////
125 // Function: PhysxSphericalJoint::get_flag
126 // Access: Published
127 // Description: Returns the value of a single SphericalJointFlag.
128 ////////////////////////////////////////////////////////////////////
130 get_flag(PhysxSphericalJointFlag flag) const {
131 
132  nassertr(_error_type == ET_ok, false);
133  return (_ptr->getFlags() & flag) ? true : false;
134 }
135 
void save_to_desc(PhysxSphericalJointDesc &jointDesc) const
Saves the state of the joint object to a descriptor.
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
Descriptor class for distance joint.
bool get_flag(PhysxSphericalJointFlag flag) const
Returns the value of a single SphericalJointFlag.
PhysxProjectionMode get_projection_mode() const
Returns the current projection mode settings.
void set_projection_mode(PhysxProjectionMode mode)
Sets the joint projection mode.
void set_name(const char *name)
Sets a name string for this object.
Definition: physxJoint.cxx:100
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void load_from_desc(const PhysxSphericalJointDesc &jointDesc)
Loads the entire state of the joint from a descriptor with a single call.
void set_flag(PhysxSphericalJointFlag flag, bool value)
Sets or clears a single SphericalJointFlag.