Panda3D
 All Classes Functions Variables Enumerations
physxWheelShape.cxx
1 // Filename: physxWheelShape.cxx
2 // Created by: enn0x (09Nov09)
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 "physxWheelShape.h"
16 #include "physxWheelShapeDesc.h"
17 #include "physxSpringDesc.h"
18 
19 TypeHandle PhysxWheelShape::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: PhysxWheelShape::link
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void PhysxWheelShape::
27 link(NxShape *shapePtr) {
28 
29  _ptr = shapePtr->isWheel();
30  _ptr->userData = this;
31  _error_type = ET_ok;
32 
33  set_name(shapePtr->getName());
34 
35  PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
36  actor->_shapes.add(this);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PhysxWheelShape::unlink
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 void PhysxWheelShape::
45 unlink() {
46 
47  _ptr->userData = NULL;
48  _error_type = ET_released;
49 
50  PhysxActor *actor = (PhysxActor *)_ptr->getActor().userData;
51  actor->_shapes.remove(this);
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function : PhysxWheelShape::save_to_desc
56 // Access : Published
57 // Description : Saves the state of the shape object to a
58 // descriptor.
59 ////////////////////////////////////////////////////////////////////
61 save_to_desc(PhysxWheelShapeDesc &shapeDesc) const {
62 
63  nassertv(_error_type == ET_ok);
64  _ptr->saveToDesc(shapeDesc._desc);
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: PhysxWheelShape::set_radius
69 // Access: Published
70 // Description: Sets the sphere radius.
71 ////////////////////////////////////////////////////////////////////
73 set_radius(float radius) {
74 
75  nassertv(_error_type == ET_ok);
76  _ptr->setRadius(radius);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: PhysxWheelShape::get_radius
81 // Access: Published
82 // Description: Returns the radius of the sphere.
83 ////////////////////////////////////////////////////////////////////
85 get_radius() const {
86 
87  nassertr(_error_type == ET_ok, 0.0f);
88  return _ptr->getRadius();
89 }
90 
91 ////////////////////////////////////////////////////////////////////
92 // Function: PhysxWheelShape::set_suspension_travel
93 // Access: Published
94 // Description: Set the maximum extension distance of suspension
95 // along shape's -Y axis. The minimum extension is
96 // always 0.
97 ////////////////////////////////////////////////////////////////////
99 set_suspension_travel(float travel) {
100 
101  nassertv(_error_type == ET_ok);
102  _ptr->setSuspensionTravel(travel);
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: PhysxWheelShape::get_suspension_travel
107 // Access: Published
108 // Description: Returns the suspension travel
109 ////////////////////////////////////////////////////////////////////
110 float PhysxWheelShape::
112 
113  nassertr(_error_type == ET_ok, 0.0f);
114  return _ptr->getSuspensionTravel();
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: PhysxWheelShape::set_inverse_wheel_mass
119 // Access: Published
120 // Description: Set the inverse mass of the wheel. Determines the
121 // wheel velocity that wheel torques can achieve.
122 ////////////////////////////////////////////////////////////////////
124 set_inverse_wheel_mass(float invMass) {
125 
126  nassertv(_error_type == ET_ok);
127  _ptr->setInverseWheelMass(invMass);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: PhysxWheelShape::get_inverse_wheel_mass
132 // Access: Published
133 // Description: Returns the inverse mass of the wheel. Determines
134 // the wheel velocity that wheel torques can achieve.
135 ////////////////////////////////////////////////////////////////////
136 float PhysxWheelShape::
138 
139  nassertr(_error_type == ET_ok, 0.0f);
140  return _ptr->getInverseWheelMass();
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: PhysxWheelShape::set_motor_torque
145 // Access: Published
146 // Description: Set the sum engine torque on the wheel axle.
147 // Positive or negative depending on direction
148 ////////////////////////////////////////////////////////////////////
150 set_motor_torque(float torque) {
151 
152  nassertv(_error_type == ET_ok);
153  _ptr->setMotorTorque(torque);
154 }
155 
156 ////////////////////////////////////////////////////////////////////
157 // Function: PhysxWheelShape::get_motor_torque
158 // Access: Published
159 // Description: Retrieves the sum engine torque on the wheel axle.
160 // Positive or negative depending on direction
161 ////////////////////////////////////////////////////////////////////
162 float PhysxWheelShape::
164 
165  nassertr(_error_type == ET_ok, 0.0f);
166  return _ptr->getMotorTorque();
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: PhysxWheelShape::set_brake_torque
171 // Access: Published
172 // Description: Must be nonnegative. Very large values should lock
173 // wheel but should be stable.
174 ////////////////////////////////////////////////////////////////////
176 set_brake_torque(float torque) {
177 
178  nassertv(_error_type == ET_ok);
179  _ptr->setBrakeTorque(torque);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: PhysxWheelShape::get_brake_torque
184 // Access: Published
185 // Description: Must be nonnegative. Very large values should lock
186 // wheel but should be stable.
187 ////////////////////////////////////////////////////////////////////
188 float PhysxWheelShape::
190 
191  nassertr(_error_type == ET_ok, 0.0f);
192  return _ptr->getBrakeTorque();
193 }
194 
195 ////////////////////////////////////////////////////////////////////
196 // Function: PhysxWheelShape::set_steer_angle
197 // Access: Published
198 // Description: Set the steering angle, around shape Y axis.
199 // The steering angle is measured in degrees.
200 ////////////////////////////////////////////////////////////////////
202 set_steer_angle(float angle) {
203 
204  nassertv(_error_type == ET_ok);
205  _ptr->setSteerAngle(NxMath::degToRad(-1.0f * angle));
206 }
207 
208 ////////////////////////////////////////////////////////////////////
209 // Function: PhysxWheelShape::get_steer_angle
210 // Access: Published
211 // Description: Retrieves the steering angle, around shape Y axis.
212 // The steering angle is measured in degrees.
213 ////////////////////////////////////////////////////////////////////
214 float PhysxWheelShape::
216 
217  nassertr(_error_type == ET_ok, 0.0f);
218  return -1.0f * NxMath::radToDeg(_ptr->getSteerAngle());
219 }
220 
221 ////////////////////////////////////////////////////////////////////
222 // Function: PhysxWheelShape::set_steer_angle_rad
223 // Access: Published
224 // Description: Set the steering angle, around shape Y axis.
225 // The steering angle is measured in radians.
226 ////////////////////////////////////////////////////////////////////
228 set_steer_angle_rad(float angle) {
229 
230  nassertv(_error_type == ET_ok);
231  _ptr->setSteerAngle(-1.0f * angle);
232 }
233 
234 ////////////////////////////////////////////////////////////////////
235 // Function: PhysxWheelShape::get_steer_angle_rad
236 // Access: Published
237 // Description: Retrieves the steering angle, around shape Y axis.
238 // The steering angle is measured in radians.
239 ////////////////////////////////////////////////////////////////////
240 float PhysxWheelShape::
242 
243  nassertr(_error_type == ET_ok, 0.0f);
244  return -1.0f * _ptr->getSteerAngle();
245 }
246 
247 ////////////////////////////////////////////////////////////////////
248 // Function: PhysxWheelShape::set_axle_speed
249 // Access: Published
250 // Description: Set the current axle rotation speed.
251 // Note: WSF_axle_speed_override flag must be raised
252 // for this to have effect!
253 ////////////////////////////////////////////////////////////////////
255 set_axle_speed(float speed) {
256 
257  nassertv(_error_type == ET_ok);
258  _ptr->setAxleSpeed(speed);
259 }
260 
261 ////////////////////////////////////////////////////////////////////
262 // Function: PhysxWheelShape::get_axle_speed
263 // Access: Published
264 // Description: Retrieves the current axle rotation speed.
265 ////////////////////////////////////////////////////////////////////
266 float PhysxWheelShape::
267 get_axle_speed() const {
268 
269  nassertr(_error_type == ET_ok, 0.0f);
270  return _ptr->getAxleSpeed();
271 }
272 
273 ////////////////////////////////////////////////////////////////////
274 // Function: PhysxWheelShape::set_wheel_flag
275 // Access: Published
276 // Description: Turns the specified wheel shape flag on or off.
277 ////////////////////////////////////////////////////////////////////
279 set_wheel_flag(PhysxWheelShapeFlag flag, bool value) {
280 
281  nassertv(_error_type == ET_ok);
282  NxU32 flags = _ptr->getWheelFlags();
283 
284  if (value == true) {
285  flags |= flag;
286  } else {
287  flags &= ~(flag);
288  }
289 
290  _ptr->setWheelFlags(flags);
291 }
292 
293 ////////////////////////////////////////////////////////////////////
294 // Function: PhysxWheelShape::get_wheel_flag
295 // Access: Published
296 // Description: Returns the value of the specified wheel shape
297 // flag.
298 ////////////////////////////////////////////////////////////////////
300 get_wheel_flag(PhysxWheelShapeFlag flag) const {
301 
302  nassertr(_error_type == ET_ok, false);
303  return (_ptr->getWheelFlags() & flag) ? true : false;
304 }
305 
306 ////////////////////////////////////////////////////////////////////
307 // Function: PhysxWheelShape::set_suspension
308 // Access: Published
309 // Description: Set the data intended for car wheel suspension
310 // effects.
311 ////////////////////////////////////////////////////////////////////
314 
315  nassertv(_error_type == ET_ok);
316  return _ptr->setSuspension(spring._desc);
317 }
318 
float get_steer_angle_rad() const
Retrieves the steering angle, around shape Y axis.
void set_suspension_travel(float travel)
Set the maximum extension distance of suspension along shape's -Y axis.
float get_axle_speed() const
Retrieves the current axle rotation speed.
float get_motor_torque() const
Retrieves the sum engine torque on the wheel axle.
float get_brake_torque() const
Must be nonnegative.
Describes a joint spring.
void save_to_desc(PhysxWheelShapeDesc &shapeDesc) const
Saves the state of the shape object to a descriptor.
void set_inverse_wheel_mass(float invMass)
Set the inverse mass of the wheel.
void set_brake_torque(float torque)
Must be nonnegative.
void set_radius(float radius)
Sets the sphere radius.
bool get_wheel_flag(PhysxWheelShapeFlag flag) const
Returns the value of the specified wheel shape flag.
void set_wheel_flag(PhysxWheelShapeFlag flag, bool value)
Turns the specified wheel shape flag on or off.
Descriptor class for PhysxWheelShape.
float get_steer_angle() const
Retrieves the steering angle, around shape Y axis.
Actors are the main simulation objects.
Definition: physxActor.h:48
void set_motor_torque(float torque)
Set the sum engine torque on the wheel axle.
void set_suspension(const PhysxSpringDesc &spring)
Set the data intended for car wheel suspension effects.
void set_name(const char *name)
Sets a name string for this object.
Definition: physxShape.cxx:112
float get_inverse_wheel_mass() const
Returns the inverse mass of the wheel.
float get_suspension_travel() const
Returns the suspension travel.
void set_steer_angle(float angle)
Set the steering angle, around shape Y axis.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
float get_radius() const
Returns the radius of the sphere.
void set_steer_angle_rad(float angle)
Set the steering angle, around shape Y axis.
void set_axle_speed(float speed)
Set the current axle rotation speed.