Panda3D
physxWheelShape.h
1 // Filename: physxWheelShape.h
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 #ifndef PHYSXWHEELSHAPE_H
16 #define PHYSXWHEELSHAPE_H
17 
18 #include "pandabase.h"
19 
20 #include "physxShape.h"
21 #include "physx_includes.h"
22 
24 class PhysxSpringDesc;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : PhysxWheelShape
28 // Description : A special shape used for simulating a car wheel.
29 // The -Y axis should be directed toward the ground.
30 //
31 // A ray is cast from the shape's origin along the -Y
32 // axis. When the ray strikes something, and the
33 // distance is:
34 //
35 // - less than wheelRadius from the shape origin:
36 // a hard contact is created
37 // - between wheelRadius and (suspensionTravel +
38 // wheelRadius): a soft suspension contact is
39 // created
40 // - greater than (suspensionTravel + wheelRadius):
41 // no contact is created.
42 //
43 // Thus at the point of greatest possible suspension
44 // compression the wheel axle will pass through at
45 // the shape's origin. At the point greatest
46 // suspension extension the wheel axle will be a
47 // distance of suspensionTravel from the shape's
48 // origin.
49 //
50 // The suspension's targetValue is 0 for real cars,
51 // which means that the suspension tries to extend
52 // all the way. Otherwise one can specify values
53 // [0,1] for suspensions which have a spring to
54 // pull the wheel up when it is extended too far.
55 // 0.5 will then fall halfway along suspensionTravel.
56 //
57 // The +Z axis is the 'forward' direction of travel
58 // for the wheel. -Z is backwards. The wheel rolls
59 // forward when rotating around the positive direction
60 // around the X axis.
61 //
62 // A positive wheel steering angle corresponds to a
63 // positive rotation around the shape's Y axis.
64 // (Castor angles are not modeled.)
65 //
66 // The coordinate frame of the shape is rigidly fixed
67 // on the car.
68 ////////////////////////////////////////////////////////////////////
69 class EXPCL_PANDAPHYSX PhysxWheelShape : public PhysxShape {
70 
71 PUBLISHED:
72  INLINE PhysxWheelShape();
73  INLINE ~PhysxWheelShape();
74 
75  void save_to_desc(PhysxWheelShapeDesc &shapeDesc) const;
76 
77  void set_radius(float radius);
78  void set_suspension_travel(float travel);
79  void set_inverse_wheel_mass(float invMass);
80  void set_motor_torque(float torque);
81  void set_brake_torque(float torque);
82  void set_steer_angle(float angle);
83  void set_steer_angle_rad(float angle);
84  void set_axle_speed(float speed);
85  void set_wheel_flag(PhysxWheelShapeFlag flag, bool value);
86  void set_suspension(const PhysxSpringDesc &spring);
87 
88  float get_radius() const;
89  float get_suspension_travel() const;
90  float get_inverse_wheel_mass() const;
91  float get_motor_torque() const;
92  float get_brake_torque() const;
93  float get_steer_angle() const;
94  float get_steer_angle_rad() const;
95  float get_axle_speed() const;
96  bool get_wheel_flag(PhysxWheelShapeFlag flag) const;
97 
98 ////////////////////////////////////////////////////////////////////
99 public:
100  INLINE NxShape *ptr() const { return (NxShape *)_ptr; };
101 
102  void link(NxShape *shapePtr);
103  void unlink();
104 
105 private:
106  NxWheelShape *_ptr;
107 
108 ////////////////////////////////////////////////////////////////////
109 public:
110  static TypeHandle get_class_type() {
111  return _type_handle;
112  }
113  static void init_type() {
114  PhysxShape::init_type();
115  register_type(_type_handle, "PhysxWheelShape",
116  PhysxShape::get_class_type());
117  }
118  virtual TypeHandle get_type() const {
119  return get_class_type();
120  }
121  virtual TypeHandle force_init_type() {
122  init_type();
123  return get_class_type();
124  }
125 
126 private:
127  static TypeHandle _type_handle;
128 };
129 
130 #include "physxWheelShape.I"
131 
132 #endif // PHYSXWHEELSHAPE_H
Abstract base class for shapes.
Definition: physxShape.h:41
Describes a joint spring.
Descriptor class for PhysxWheelShape.
A special shape used for simulating a car wheel.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85