Panda3D
bulletVehicle.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file bulletVehicle.h
10  * @author enn0x
11  * @date 2010-02-16
12  */
13 
14 #ifndef __BULLET_VEHICLE_H__
15 #define __BULLET_VEHICLE_H__
16 
17 #include "pandabase.h"
18 
19 #include "bullet_includes.h"
20 #include "bullet_utils.h"
21 
22 #include "typedReferenceCount.h"
23 #include "luse.h"
24 
25 class BulletWorld;
27 class BulletWheel;
28 
29 /**
30  *
31  */
32 class EXPCL_PANDABULLET BulletVehicleTuning {
33 
34 PUBLISHED:
35  void set_suspension_stiffness(PN_stdfloat value);
36  void set_suspension_compression(PN_stdfloat value);
37  void set_suspension_damping(PN_stdfloat value);
38  void set_max_suspension_travel_cm(PN_stdfloat value);
39  void set_friction_slip(PN_stdfloat value);
40  void set_max_suspension_force(PN_stdfloat value);
41 
42  PN_stdfloat get_suspension_stiffness() const;
43  PN_stdfloat get_suspension_compression() const;
44  PN_stdfloat get_suspension_damping() const;
45  PN_stdfloat get_max_suspension_travel_cm() const;
46  PN_stdfloat get_friction_slip() const;
47  PN_stdfloat get_max_suspension_force() const;
48 
49  MAKE_PROPERTY(suspension_stiffness, get_suspension_stiffness, set_suspension_stiffness);
50  MAKE_PROPERTY(suspension_compression, get_suspension_compression, set_suspension_compression);
51  MAKE_PROPERTY(suspension_damping, get_suspension_damping, set_suspension_damping);
52  MAKE_PROPERTY(max_suspension_travel_cm, get_max_suspension_travel_cm, set_max_suspension_travel_cm);
53  MAKE_PROPERTY(friction_slip, get_friction_slip, set_friction_slip);
54  MAKE_PROPERTY(max_suspension_force, get_max_suspension_force, set_max_suspension_force);
55 
56 private:
57  btRaycastVehicle::btVehicleTuning _;
58 
59  friend class BulletVehicle;
60 };
61 
62 /**
63  * Simulates a raycast vehicle which casts a ray per wheel at the ground as a
64  * cheap replacement for complex suspension simulation. The suspension can be
65  * tuned in various ways. It is possible to add a (probably) arbitrary number
66  * of wheels.
67  */
68 class EXPCL_PANDABULLET BulletVehicle : public TypedReferenceCount {
69 
70 PUBLISHED:
72  INLINE ~BulletVehicle();
73 
74  void set_coordinate_system(BulletUpAxis up);
75  void set_steering_value(PN_stdfloat steering, int idx);
76  void set_brake(PN_stdfloat brake, int idx);
77  void set_pitch_control(PN_stdfloat pitch);
78 
79  BulletRigidBodyNode *get_chassis();
80  PN_stdfloat get_current_speed_km_hour() const;
81  PN_stdfloat get_steering_value(int idx) const;
82  LVector3 get_forward_vector() const;
83 
84  void reset_suspension();
85  void apply_engine_force(PN_stdfloat force, int idx);
86 
87  // Wheels
88  BulletWheel create_wheel();
89 
90  int get_num_wheels() const;
91  BulletWheel get_wheel(int idx) const;
92  MAKE_SEQ(get_wheels, get_num_wheels, get_wheel);
93 
94  // Tuning
95  INLINE BulletVehicleTuning &get_tuning();
96 
97  MAKE_PROPERTY(chassis, get_chassis);
98  MAKE_PROPERTY(current_speed_km_hour, get_current_speed_km_hour);
99  MAKE_PROPERTY(forward_vector, get_forward_vector);
100  MAKE_SEQ_PROPERTY(wheels, get_num_wheels, get_wheel);
101  MAKE_PROPERTY(tuning, get_tuning);
102 
103 public:
104  INLINE btRaycastVehicle *get_vehicle() const;
105  BulletRigidBodyNode *do_get_chassis();
106 
107  void do_sync_b2p();
108 
109 private:
110  btRaycastVehicle *_vehicle;
111  btVehicleRaycaster *_raycaster;
112 
113  BulletVehicleTuning _tuning;
114 
115  static btVector3 get_axis(int idx);
116 
117 public:
118  static TypeHandle get_class_type() {
119  return _type_handle;
120  }
121  static void init_type() {
122  TypedReferenceCount::init_type();
123  register_type(_type_handle, "BulletVehicle",
124  TypedReferenceCount::get_class_type());
125  }
126  virtual TypeHandle get_type() const {
127  return get_class_type();
128  }
129  virtual TypeHandle force_init_type() {
130  init_type();
131  return get_class_type();
132  }
133 
134 private:
135  static TypeHandle _type_handle;
136 };
137 
138 #include "bulletVehicle.I"
139 
140 #endif // __BULLET_VEHICLE_H__
BulletRigidBodyNode
Definition: bulletRigidBodyNode.h:31
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
bullet_includes.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
bulletVehicle.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
BulletVehicle
Simulates a raycast vehicle which casts a ray per wheel at the ground as a cheap replacement for comp...
Definition: bulletVehicle.h:68
bullet_utils.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BulletWheel
One wheel of a BulletVehicle.
Definition: bulletWheel.h:62
BulletVehicleTuning
Definition: bulletVehicle.h:32
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BulletWorld
Definition: bulletWorld.h:51