Panda3D
 All Classes Functions Variables Enumerations
physxPulleyJoint.cxx
1 // Filename: physxPulleyJoint.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 "physxPulleyJoint.h"
16 #include "physxPulleyJointDesc.h"
17 #include "physxMotorDesc.h"
18 
19 TypeHandle PhysxPulleyJoint::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: PhysxPulleyJoint::link
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void PhysxPulleyJoint::
27 link(NxJoint *jointPtr) {
28 
29  _ptr = jointPtr->isPulleyJoint();
30  _ptr->userData = this;
31  _error_type = ET_ok;
32 
33  set_name(jointPtr->getName());
34 
35  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
36  scene->_joints.add(this);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PhysxPulleyJoint::unlink
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 void PhysxPulleyJoint::
45 unlink() {
46 
47  _ptr->userData = NULL;
48  _error_type = ET_released;
49 
50  PhysxScene *scene = (PhysxScene *)_ptr->getScene().userData;
51  scene->_joints.remove(this);
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function : PhysxPulleyJoint::save_to_desc
56 // Access : Published
57 // Description : Saves the state of the joint object to a
58 // descriptor.
59 ////////////////////////////////////////////////////////////////////
62 
63  nassertv(_error_type == ET_ok);
64  _ptr->saveToDesc(jointDesc._desc);
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function : PhysxPulleyJoint::load_from_desc
69 // Access : Published
70 // Description : Loads the entire state of the joint from a
71 // descriptor with a single call.
72 ////////////////////////////////////////////////////////////////////
75 
76  nassertv(_error_type == ET_ok);
77  _ptr->loadFromDesc(jointDesc._desc);
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: PhysxPulleyJoint::set_motor
82 // Access: Published
83 // Description: Sets motor parameters for the joint.
84 //
85 // For a positive velTarget, the motor pulls the first
86 // body towards its pulley, for a negative velTarget,
87 // the motor pulls the second body towards its pulley.
88 //
89 // velTarget - the relative velocity the motor is
90 // trying to achieve. The motor will only be able to
91 // reach this velocity if the maxForce is sufficiently
92 // large. If the joint is moving faster than this
93 // velocity, the motor will actually try to brake. If
94 // you set this to infinity then the motor will keep
95 // speeding up, unless there is some sort of
96 // resistance on the attached bodies.
97 //
98 // maxForce - the maximum force the motor can exert.
99 // Zero disables the motor. Default is 0, should
100 // be >= 0. Setting this to a very large value if
101 // velTarget is also very large may not be a good
102 // idea.
103 //
104 // freeSpin - if this flag is set, and if the joint
105 // is moving faster than velTarget, then neither
106 // braking nor additional acceleration will result.
107 // default: false.
108 //
109 // This automatically enables the motor.
110 ////////////////////////////////////////////////////////////////////
112 set_motor(const PhysxMotorDesc &motor) {
113 
114  nassertv(_error_type == ET_ok);
115  _ptr->setMotor(motor._desc);
116 }
117 
118 ////////////////////////////////////////////////////////////////////
119 // Function: PhysxPulleyJoint::set_flag
120 // Access: Published
121 // Description: Sets or clear a single pulley joint flag.
122 ////////////////////////////////////////////////////////////////////
124 set_flag(PhysxPulleyJointFlag flag, bool value) {
125 
126  nassertv(_error_type == ET_ok);
127  NxU32 flags = _ptr->getFlags();
128 
129  if (value == true) {
130  flags |= flag;
131  }
132  else {
133  flags &= ~(flag);
134  }
135 
136  _ptr->setFlags(flags);
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: PhysxPulleyJoint::get_flag
141 // Access: Published
142 // Description: Retrieves the value of a single PulleyJointFlag.
143 ////////////////////////////////////////////////////////////////////
145 get_flag(PhysxPulleyJointFlag flag) const {
146 
147  nassertr(_error_type == ET_ok, false);
148  return (_ptr->getFlags() & flag) ? true : false;
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: PhysxPulleyJoint::get_motor
153 // Access: Published
154 // Description:
155 ////////////////////////////////////////////////////////////////////
156 PhysxMotorDesc PhysxPulleyJoint::
157 get_motor() const {
158 
159  nassertr(_error_type == ET_ok, false);
160 
161  PhysxMotorDesc value;
162  _ptr->getMotor(value._desc);
163  return value;
164 }
165 
void set_motor(const PhysxMotorDesc &motor)
Sets motor parameters for the joint.
void load_from_desc(const PhysxPulleyJointDesc &jointDesc)
Loads the entire state of the joint from a descriptor with a single call.
void save_to_desc(PhysxPulleyJointDesc &jointDesc) const
Saves the state of the joint object to a descriptor.
Descriptor class for distance joint.
Describes a joint motor.
void set_flag(PhysxPulleyJointFlag flag, bool value)
Sets or clear a single pulley joint flag.
bool get_flag(PhysxPulleyJointFlag flag) const
Retrieves the value of a single PulleyJointFlag.
A scene is a collection of bodies, constraints, and effectors which can interact. ...
Definition: physxScene.h:73
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