Panda3D
 All Classes Functions Variables Enumerations
bulletVehicle.h
1 // Filename: bulletVehicle.h
2 // Created by: enn0x (16Feb10)
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 __BULLET_VEHICLE_H__
16 #define __BULLET_VEHICLE_H__
17 
18 #include "pandabase.h"
19 
20 #include "bullet_includes.h"
21 #include "bullet_utils.h"
22 
23 #include "typedReferenceCount.h"
24 #include "luse.h"
25 
26 class BulletWorld;
28 class BulletWheel;
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : BulletVehicleTuning
32 // Description :
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDABULLET BulletVehicleTuning {
35 
36 PUBLISHED:
37  INLINE void set_suspension_stiffness(PN_stdfloat value);
38  INLINE void set_suspension_compression(PN_stdfloat value);
39  INLINE void set_suspension_damping(PN_stdfloat value);
40  INLINE void set_max_suspension_travel_cm(PN_stdfloat value);
41  INLINE void set_friction_slip(PN_stdfloat value);
42  INLINE void set_max_suspension_force(PN_stdfloat value);
43 
44  INLINE PN_stdfloat get_suspension_stiffness() const;
45  INLINE PN_stdfloat get_suspension_compression() const;
46  INLINE PN_stdfloat get_suspension_damping() const;
47  INLINE PN_stdfloat get_max_suspension_travel_cm() const;
48  INLINE PN_stdfloat get_friction_slip() const;
49  INLINE PN_stdfloat get_max_suspension_force() const;
50 
51 private:
52  btRaycastVehicle::btVehicleTuning _;
53 
54  friend class BulletVehicle;
55 };
56 
57 ////////////////////////////////////////////////////////////////////
58 // Class : BulletVehicle
59 // Description : Simulates a raycast vehicle which casts a ray per
60 // wheel at the ground as a cheap replacement for
61 // complex suspension simulation. The suspension can
62 // be tuned in various ways. It is possible to add a
63 // (probably) arbitrary number of wheels.
64 ////////////////////////////////////////////////////////////////////
65 class EXPCL_PANDABULLET BulletVehicle : public TypedReferenceCount {
66 
67 PUBLISHED:
69  INLINE ~BulletVehicle();
70 
71  void set_coordinate_system(BulletUpAxis up);
72  void set_steering_value(PN_stdfloat steering, int idx);
73  void set_brake(PN_stdfloat brake, int idx);
74  void set_pitch_control(PN_stdfloat pitch);
75 
76  BulletRigidBodyNode *get_chassis();
77  PN_stdfloat get_current_speed_km_hour() const;
78  PN_stdfloat get_steering_value(int idx) const;
79  LVector3 get_forward_vector() const;
80 
81  void reset_suspension();
82  void apply_engine_force(PN_stdfloat force, int idx);
83 
84  // Wheels
85  BulletWheel create_wheel();
86 
87  INLINE int get_num_wheels() const;
88  BulletWheel get_wheel(int idx) const;
89  MAKE_SEQ(get_wheels, get_num_wheels, get_wheel);
90 
91  // Tuning
92  INLINE BulletVehicleTuning &get_tuning();
93 
94 public:
95  INLINE btRaycastVehicle *get_vehicle() const;
96 
97  void sync_b2p();
98 
99 private:
100  btRaycastVehicle *_vehicle;
101  btVehicleRaycaster *_raycaster;
102 
103  BulletVehicleTuning _tuning;
104 
105  static btVector3 get_axis(int idx);
106 
107 ////////////////////////////////////////////////////////////////////
108 public:
109  static TypeHandle get_class_type() {
110  return _type_handle;
111  }
112  static void init_type() {
113  TypedReferenceCount::init_type();
114  register_type(_type_handle, "BulletVehicle",
115  TypedReferenceCount::get_class_type());
116  }
117  virtual TypeHandle get_type() const {
118  return get_class_type();
119  }
120  virtual TypeHandle force_init_type() {
121  init_type();
122  return get_class_type();
123  }
124 
125 private:
126  static TypeHandle _type_handle;
127 };
128 
129 #include "bulletVehicle.I"
130 
131 #endif // __BULLET_VEHICLE_H__
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
Simulates a raycast vehicle which casts a ray per wheel at the ground as a cheap replacement for comp...
Definition: bulletVehicle.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
One wheel of a BulletVehicle.
Definition: bulletWheel.h:57