Panda3D
bulletWheel.cxx
1 // Filename: bulletWheel.cxx
2 // Created by: enn0x (17Feb10)
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 "bulletWheel.h"
16 
17 ////////////////////////////////////////////////////////////////////
18 // Function: BulletWheel::Constructor
19 // Access: Public
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 BulletWheel::
23 BulletWheel(btWheelInfo &info) : _info(info) {
24 
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: BulletWheelRaycastInfo::Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 BulletWheelRaycastInfo::
33 BulletWheelRaycastInfo(btWheelInfo::RaycastInfo &info) : _info(info) {
34 
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: BulletWheel::get_raycast_info
39 // Access: Published
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 BulletWheelRaycastInfo BulletWheel::
43 get_raycast_info() const {
44 
45  return BulletWheelRaycastInfo(_info.m_raycastInfo);
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: BulletWheel::get_suspension_rest_length
50 // Access: Published
51 // Description: Returns the length of the suspension when the
52 // vehicle is standing still.
53 ////////////////////////////////////////////////////////////////////
54 PN_stdfloat BulletWheel::
56 
57  return (PN_stdfloat)_info.getSuspensionRestLength();
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: BulletWheel::set_suspension_stiffness
62 // Access: Published
63 // Description: Sets how stiff the suspension shall be.
64 ////////////////////////////////////////////////////////////////////
65 void BulletWheel::
66 set_suspension_stiffness(PN_stdfloat value) {
67 
68  _info.m_suspensionStiffness = (btScalar)value;
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: BulletWheel::get_suspension_stiffness
73 // Access: Published
74 // Description: Returns the stiffness of the suspension.
75 ////////////////////////////////////////////////////////////////////
76 PN_stdfloat BulletWheel::
78 
79  return (PN_stdfloat)_info.m_suspensionStiffness;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: BulletWheel::set_max_suspension_travel_cm
84 // Access: Published
85 // Description: Sets the maximum distance the suspension can travel
86 // out of the resting position in centimeters.
87 ////////////////////////////////////////////////////////////////////
88 void BulletWheel::
89 set_max_suspension_travel_cm(PN_stdfloat value) {
90 
91  _info.m_maxSuspensionTravelCm = (btScalar)value;
92 }
93 
94 ////////////////////////////////////////////////////////////////////
95 // Function: BulletWheel::get_max_suspension_travel_cm
96 // Access: Published
97 // Description:
98 ////////////////////////////////////////////////////////////////////
99 PN_stdfloat BulletWheel::
100 get_max_suspension_travel_cm() const {
101 
102  return (PN_stdfloat)_info.m_maxSuspensionTravelCm;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: BulletWheel::set_friction_slip
107 // Access: Published
108 // Description: Sets the slipperyness of the tyre.
109 ////////////////////////////////////////////////////////////////////
110 void BulletWheel::
111 set_friction_slip(PN_stdfloat value) {
112 
113  _info.m_frictionSlip = (btScalar)value;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: BulletWheel::get_friction_slip
118 // Access: Published
119 // Description: Returns how slippery the tyres are.
120 ////////////////////////////////////////////////////////////////////
121 PN_stdfloat BulletWheel::
123 
124  return (PN_stdfloat)_info.m_frictionSlip;
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: BulletWheel::set_max_suspension_force
129 // Access: Published
130 // Description: Sets the maximum suspension force the wheel can
131 // handle.
132 ////////////////////////////////////////////////////////////////////
133 void BulletWheel::
134 set_max_suspension_force(PN_stdfloat value) {
135 
136  _info.m_maxSuspensionForce = (btScalar)value;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: BulletWheel::get_max_suspension_force
141 // Access: Published
142 // Description: Returns the maximum force (weight) the suspension
143 // can handle.
144 ////////////////////////////////////////////////////////////////////
145 PN_stdfloat BulletWheel::
147 
148  return (PN_stdfloat)_info.m_maxSuspensionForce;
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: BulletWheel::set_wheels_damping_compression
153 // Access: Published
154 // Description: Sets the damping forces applied when the suspension
155 // gets compressed.
156 ////////////////////////////////////////////////////////////////////
157 void BulletWheel::
158 set_wheels_damping_compression(PN_stdfloat value) {
159 
160  _info.m_wheelsDampingCompression = (btScalar)value;
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function: BulletWheel::get_wheels_damping_compression
165 // Access: Published
166 // Description: Returns the damping applied to the compressing
167 // suspension.
168 ////////////////////////////////////////////////////////////////////
169 PN_stdfloat BulletWheel::
171 
172  return (PN_stdfloat)_info.m_wheelsDampingCompression;
173 }
174 
175 ////////////////////////////////////////////////////////////////////
176 // Function: BulletWheel::set_wheels_damping_relaxation
177 // Access: Published
178 // Description: Sets the damping forces applied when the suspension
179 // relaxes.
180 ////////////////////////////////////////////////////////////////////
181 void BulletWheel::
182 set_wheels_damping_relaxation(PN_stdfloat value) {
183 
184  _info.m_wheelsDampingRelaxation = (btScalar)value;
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: BulletWheel::get_wheels_damping_relaxation
189 // Access: Published
190 // Description: Returns the damping applied to the relaxing
191 // suspension.
192 ////////////////////////////////////////////////////////////////////
193 PN_stdfloat BulletWheel::
195 
196  return (PN_stdfloat)_info.m_wheelsDampingRelaxation;
197 }
198 
199 ////////////////////////////////////////////////////////////////////
200 // Function: BulletWheel::set_roll_influence
201 // Access: Published
202 // Description: Defines a scaling factor for roll forces that affect
203 // the chassis. 0.0 means no roll - the chassis won't
204 // ever flip over - while 1.0 means original physical
205 // behaviour. Basically, this allows moving the center
206 // of mass up and down.
207 ////////////////////////////////////////////////////////////////////
208 void BulletWheel::
209 set_roll_influence(PN_stdfloat value) {
210 
211  _info.m_rollInfluence = (btScalar)value;
212 }
213 
214 ////////////////////////////////////////////////////////////////////
215 // Function: BulletWheel::get_roll_influence
216 // Access: Published
217 // Description: Returns the factor by which roll forces are scaled.
218 // See set_roll_influence.
219 ////////////////////////////////////////////////////////////////////
220 PN_stdfloat BulletWheel::
222 
223  return (PN_stdfloat)_info.m_rollInfluence;
224 }
225 
226 ////////////////////////////////////////////////////////////////////
227 // Function: BulletWheel::set_wheel_radius
228 // Access: Published
229 // Description: Sets the wheel radius.
230 ////////////////////////////////////////////////////////////////////
231 void BulletWheel::
232 set_wheel_radius(PN_stdfloat value) {
233 
234  _info.m_wheelsRadius = (btScalar)value;
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: BulletWheel::get_wheel_radius
239 // Access: Published
240 // Description: Returns the wheel radius.
241 ////////////////////////////////////////////////////////////////////
242 PN_stdfloat BulletWheel::
244 
245  return (PN_stdfloat)_info.m_wheelsRadius;
246 }
247 
248 ////////////////////////////////////////////////////////////////////
249 // Function: BulletWheel::set_steering
250 // Access: Published
251 // Description: Sets the steering angle.
252 ////////////////////////////////////////////////////////////////////
253 void BulletWheel::
254 set_steering(PN_stdfloat value) {
255 
256  _info.m_steering = (btScalar)value;
257 }
258 
259 ////////////////////////////////////////////////////////////////////
260 // Function: BulletWheel::get_steering
261 // Access: Published
262 // Description: Returns the steering angle in degrees.
263 ////////////////////////////////////////////////////////////////////
264 PN_stdfloat BulletWheel::
265 get_steering() const {
266 
267  return (PN_stdfloat)_info.m_steering;
268 }
269 
270 ////////////////////////////////////////////////////////////////////
271 // Function: BulletWheel::set_rotation
272 // Access: Published
273 // Description:
274 ////////////////////////////////////////////////////////////////////
275 void BulletWheel::
276 set_rotation(PN_stdfloat value) {
277 
278  _info.m_rotation = (btScalar)value;
279 }
280 
281 ////////////////////////////////////////////////////////////////////
282 // Function: BulletWheel::get_rotation
283 // Access: Published
284 // Description:
285 ////////////////////////////////////////////////////////////////////
286 PN_stdfloat BulletWheel::
287 get_rotation() const {
288 
289  return (PN_stdfloat)_info.m_rotation;
290 }
291 
292 ////////////////////////////////////////////////////////////////////
293 // Function: BulletWheel::set_delta_rotation
294 // Access: Published
295 // Description:
296 ////////////////////////////////////////////////////////////////////
297 void BulletWheel::
298 set_delta_rotation(PN_stdfloat value) {
299 
300  _info.m_deltaRotation = (btScalar)value;
301 }
302 
303 ////////////////////////////////////////////////////////////////////
304 // Function: BulletWheel::get_delta_rotation
305 // Access: Published
306 // Description:
307 ////////////////////////////////////////////////////////////////////
308 PN_stdfloat BulletWheel::
309 get_delta_rotation() const {
310 
311  return (PN_stdfloat)_info.m_deltaRotation;
312 }
313 
314 ////////////////////////////////////////////////////////////////////
315 // Function: BulletWheel::set_engine_force
316 // Access: Published
317 // Description: Defines how much force should be used to rotate the
318 // wheel.
319 ////////////////////////////////////////////////////////////////////
320 void BulletWheel::
321 set_engine_force(PN_stdfloat value) {
322 
323  _info.m_engineForce = (btScalar)value;
324 }
325 
326 ////////////////////////////////////////////////////////////////////
327 // Function: BulletWheel::get_engine_force
328 // Access: Published
329 // Description: Returns the amount of accelleration force currently
330 // applied.
331 ////////////////////////////////////////////////////////////////////
332 PN_stdfloat BulletWheel::
334 
335  return (PN_stdfloat)_info.m_engineForce;
336 }
337 
338 ////////////////////////////////////////////////////////////////////
339 // Function: BulletWheel::set_brake
340 // Access: Published
341 // Description:
342 ////////////////////////////////////////////////////////////////////
343 void BulletWheel::
344 set_brake(PN_stdfloat value) {
345 
346  _info.m_brake = (btScalar)value;
347 }
348 
349 ////////////////////////////////////////////////////////////////////
350 // Function: BulletWheel::get_brake
351 // Access: Published
352 // Description: Returns the amount of braking force currently
353 // applied.
354 ////////////////////////////////////////////////////////////////////
355 PN_stdfloat BulletWheel::
356 get_brake() const {
357 
358  return (PN_stdfloat)_info.m_brake;
359 }
360 
361 ////////////////////////////////////////////////////////////////////
362 // Function: BulletWheel::set_skid_info
363 // Access: Published
364 // Description:
365 ////////////////////////////////////////////////////////////////////
366 void BulletWheel::
367 set_skid_info(PN_stdfloat value) {
368 
369  _info.m_skidInfo = (btScalar)value;
370 }
371 
372 ////////////////////////////////////////////////////////////////////
373 // Function: BulletWheel::get_skid_info
374 // Access: Published
375 // Description:
376 ////////////////////////////////////////////////////////////////////
377 PN_stdfloat BulletWheel::
378 get_skid_info() const {
379 
380  return (PN_stdfloat)_info.m_skidInfo;
381 }
382 
383 ////////////////////////////////////////////////////////////////////
384 // Function: BulletWheel::set_wheels_suspension_force
385 // Access: Published
386 // Description:
387 ////////////////////////////////////////////////////////////////////
388 void BulletWheel::
389 set_wheels_suspension_force(PN_stdfloat value) {
390 
391  _info.m_wheelsSuspensionForce = (btScalar)value;
392 }
393 
394 ////////////////////////////////////////////////////////////////////
395 // Function: BulletWheel::get_wheels_suspension_force
396 // Access: Published
397 // Description:
398 ////////////////////////////////////////////////////////////////////
399 PN_stdfloat BulletWheel::
400 get_wheels_suspension_force() const {
401 
402  return (PN_stdfloat)_info.m_wheelsSuspensionForce;
403 }
404 
405 ////////////////////////////////////////////////////////////////////
406 // Function: BulletWheel::set_suspension_relative_velocity
407 // Access: Published
408 // Description:
409 ////////////////////////////////////////////////////////////////////
410 void BulletWheel::
411 set_suspension_relative_velocity(PN_stdfloat value) {
412 
413  _info.m_suspensionRelativeVelocity = (btScalar)value;
414 }
415 
416 ////////////////////////////////////////////////////////////////////
417 // Function: BulletWheel::get_suspension_relative_velocity
418 // Access: Published
419 // Description:
420 ////////////////////////////////////////////////////////////////////
421 PN_stdfloat BulletWheel::
422 get_suspension_relative_velocity() const {
423 
424  return (PN_stdfloat)_info.m_suspensionRelativeVelocity;
425 }
426 
427 ////////////////////////////////////////////////////////////////////
428 // Function: BulletWheel::set_clipped_inv_connection_point_cs
429 // Access: Published
430 // Description:
431 ////////////////////////////////////////////////////////////////////
432 void BulletWheel::
433 set_clipped_inv_connection_point_cs(PN_stdfloat value) {
434 
435  _info.m_clippedInvContactDotSuspension = (btScalar)value;
436 }
437 
438 ////////////////////////////////////////////////////////////////////
439 // Function: BulletWheel::get_clipped_inv_connection_point_cs
440 // Access: Published
441 // Description:
442 ////////////////////////////////////////////////////////////////////
443 PN_stdfloat BulletWheel::
444 get_clipped_inv_connection_point_cs() const {
445 
446  return (PN_stdfloat)_info.m_clippedInvContactDotSuspension;
447 }
448 
449 ////////////////////////////////////////////////////////////////////
450 // Function: BulletWheel::set_chassis_connection_point_cs
451 // Access: Published
452 // Description: Sets the point where the wheel is connected to the
453 // chassis.
454 ////////////////////////////////////////////////////////////////////
455 void BulletWheel::
457 
458  nassertv(!pos.is_nan());
459  _info.m_chassisConnectionPointCS = LVecBase3_to_btVector3(pos);
460 }
461 
462 ////////////////////////////////////////////////////////////////////
463 // Function: BulletWheel::get_chassis_connection_point_cs
464 // Access: Published
465 // Description: Returns the point where the wheel is connected to
466 // the chassis.
467 ////////////////////////////////////////////////////////////////////
470 
471  return btVector3_to_LPoint3(_info.m_chassisConnectionPointCS);
472 }
473 
474 ////////////////////////////////////////////////////////////////////
475 // Function: BulletWheel::set_wheel_direction_cs
476 // Access: Published
477 // Description: Sets the wheel's forward vector. (Most likely
478 // orthogonal to the axle vector.)
479 ////////////////////////////////////////////////////////////////////
480 void BulletWheel::
482 
483  nassertv(!dir.is_nan());
484  _info.m_wheelDirectionCS = LVecBase3_to_btVector3(dir);
485 }
486 
487 ////////////////////////////////////////////////////////////////////
488 // Function: BulletWheel::get_wheel_direction_cs
489 // Access: Published
490 // Description: Returns the wheel's forward vector relative to the
491 // chassis.
492 ////////////////////////////////////////////////////////////////////
495 
496  return btVector3_to_LVector3(_info.m_wheelDirectionCS);
497 }
498 
499 ////////////////////////////////////////////////////////////////////
500 // Function: BulletWheel::set_wheel_axle_cs
501 // Access: Published
502 // Description: Determines the wheel axle normal vector.
503 ////////////////////////////////////////////////////////////////////
504 void BulletWheel::
506 
507  nassertv(!axle.is_nan());
508  _info.m_wheelAxleCS = LVecBase3_to_btVector3(axle);
509 }
510 
511 ////////////////////////////////////////////////////////////////////
512 // Function: BulletWheel::get_wheel_axle_cs
513 // Access: Published
514 // Description: Returns the normal vector of the wheel axle.
515 ////////////////////////////////////////////////////////////////////
518 
519  return btVector3_to_LVector3(_info.m_wheelAxleCS);
520 }
521 
522 ////////////////////////////////////////////////////////////////////
523 // Function: BulletWheel::set_world_transform
524 // Access: Published
525 // Description:
526 ////////////////////////////////////////////////////////////////////
527 void BulletWheel::
528 set_world_transform(const LMatrix4 &mat) {
529 
530  nassertv(!mat.is_nan());
531  _info.m_worldTransform = LMatrix4_to_btTrans(mat);
532 }
533 
534 ////////////////////////////////////////////////////////////////////
535 // Function: BulletWheel::get_world_transform
536 // Access: Published
537 // Description:
538 ////////////////////////////////////////////////////////////////////
539 LMatrix4 BulletWheel::
540 get_world_transform() const {
541 
542  return btTrans_to_LMatrix4(_info.m_worldTransform);
543 }
544 
545 ////////////////////////////////////////////////////////////////////
546 // Function: BulletWheel::set_front_wheel
547 // Access: Published
548 // Description: Sets if the wheel is steerable.
549 ////////////////////////////////////////////////////////////////////
550 void BulletWheel::
551 set_front_wheel(bool value) {
552 
553  _info.m_bIsFrontWheel = value;
554 }
555 
556 ////////////////////////////////////////////////////////////////////
557 // Function: BulletWheel::is_front_wheel
558 // Access: Published
559 // Description: Determines if a wheel is steerable.
560 ////////////////////////////////////////////////////////////////////
561 bool BulletWheel::
562 is_front_wheel() const {
563 
564  return _info.m_bIsFrontWheel;
565 }
566 
567 ////////////////////////////////////////////////////////////////////
568 // Function: BulletWheel::set_node
569 // Access: Published
570 // Description: Sets the PandaNode which representates the visual
571 // appearance of this wheel.
572 ////////////////////////////////////////////////////////////////////
573 void BulletWheel::
575 
576  _info.m_clientInfo = (void *)node;
577 }
578 
579 ////////////////////////////////////////////////////////////////////
580 // Function: BulletWheel::get_node
581 // Access: Published
582 // Description: Returns the PandaNode which representates the
583 // visual appearance of this wheel, if such a
584 // representation has been set previously.
585 ////////////////////////////////////////////////////////////////////
587 get_node() const {
588 
589  return (_info.m_clientInfo == NULL) ? NULL : (PandaNode *)_info.m_clientInfo;
590 }
591 
void set_wheel_direction_cs(const LVector3 &dir)
Sets the wheel's forward vector.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
PN_stdfloat get_suspension_stiffness() const
Returns the stiffness of the suspension.
Definition: bulletWheel.cxx:77
PN_stdfloat get_engine_force() const
Returns the amount of accelleration force currently applied.
PN_stdfloat get_suspension_rest_length() const
Returns the length of the suspension when the vehicle is standing still.
Definition: bulletWheel.cxx:55
void set_wheel_axle_cs(const LVector3 &axle)
Determines the wheel axle normal vector.
void set_chassis_connection_point_cs(const LPoint3 &pos)
Sets the point where the wheel is connected to the chassis.
void set_engine_force(PN_stdfloat value)
Defines how much force should be used to rotate the wheel.
void set_steering(PN_stdfloat value)
Sets the steering angle.
LVector3 get_wheel_direction_cs() const
Returns the wheel's forward vector relative to the chassis.
PN_stdfloat get_wheels_damping_relaxation() const
Returns the damping applied to the relaxing suspension.
void set_wheel_radius(PN_stdfloat value)
Sets the wheel radius.
LVector3 get_wheel_axle_cs() const
Returns the normal vector of the wheel axle.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
PN_stdfloat get_wheels_damping_compression() const
Returns the damping applied to the compressing suspension.
void set_max_suspension_travel_cm(PN_stdfloat value)
Sets the maximum distance the suspension can travel out of the resting position in centimeters...
Definition: bulletWheel.cxx:89
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:464
PN_stdfloat get_brake() const
Returns the amount of braking force currently applied.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
Definition: lmatrix.h:1417
void set_suspension_stiffness(PN_stdfloat value)
Sets how stiff the suspension shall be.
Definition: bulletWheel.cxx:66
PN_stdfloat get_friction_slip() const
Returns how slippery the tyres are.
void set_roll_influence(PN_stdfloat value)
Defines a scaling factor for roll forces that affect the chassis.
void set_max_suspension_force(PN_stdfloat value)
Sets the maximum suspension force the wheel can handle.
void set_friction_slip(PN_stdfloat value)
Sets the slipperyness of the tyre.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
void set_front_wheel(bool value)
Sets if the wheel is steerable.
void set_wheels_damping_relaxation(PN_stdfloat value)
Sets the damping forces applied when the suspension relaxes.
void set_node(PandaNode *node)
Sets the PandaNode which representates the visual appearance of this wheel.
void set_wheels_damping_compression(PN_stdfloat value)
Sets the damping forces applied when the suspension gets compressed.
bool is_front_wheel() const
Determines if a wheel is steerable.
PN_stdfloat get_roll_influence() const
Returns the factor by which roll forces are scaled.
PN_stdfloat get_steering() const
Returns the steering angle in degrees.
LPoint3 get_chassis_connection_point_cs() const
Returns the point where the wheel is connected to the chassis.
PandaNode * get_node() const
Returns the PandaNode which representates the visual appearance of this wheel, if such a representati...
PN_stdfloat get_max_suspension_force() const
Returns the maximum force (weight) the suspension can handle.
PN_stdfloat get_wheel_radius() const
Returns the wheel radius.