Panda3D
Loading...
Searching...
No Matches
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
25class BulletWorld;
27class BulletWheel;
28
29/**
30 *
31 */
32class EXPCL_PANDABULLET BulletVehicleTuning {
33
34PUBLISHED:
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
56private:
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 */
68class EXPCL_PANDABULLET BulletVehicle : public TypedReferenceCount {
69
70PUBLISHED:
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
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
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
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
103public:
104 INLINE btRaycastVehicle *get_vehicle() const;
106
107 void do_sync_b2p();
108
109private:
110 btRaycastVehicle *_vehicle;
111 btVehicleRaycaster *_raycaster;
112
113 BulletVehicleTuning _tuning;
114
115 static btVector3 get_axis(int idx);
116
117public:
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
134private:
135 static TypeHandle _type_handle;
136};
137
138#include "bulletVehicle.I"
139
140#endif // __BULLET_VEHICLE_H__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_tuning
Returns a reference to the BulletVehicleTuning object of this vehicle which offers various vehicle-gl...
void do_sync_b2p()
Assumes the lock(bullet global lock) is held by the caller.
void set_steering_value(PN_stdfloat steering, int idx)
Sets the steering value (in degrees) of the wheel with index idx.
get_wheel
Returns the BulletWheel with index idx.
get_forward_vector
Returns the forward vector representing the car's actual direction of movement.
PN_stdfloat get_steering_value(int idx) const
Returns the steering angle of the wheel with index idx in degrees.
BulletRigidBodyNode * do_get_chassis()
Returns the chassis of this vehicle.
get_num_wheels
Returns the number of wheels this vehicle has.
void apply_engine_force(PN_stdfloat force, int idx)
Applies force at the wheel with index idx for acceleration.
get_chassis
Returns the chassis of this vehicle.
void reset_suspension()
Resets the vehicle's suspension.
get_current_speed_km_hour
Returns the current speed in kilometers per hour.
BulletVehicle(BulletWorld *world, BulletRigidBodyNode *chassis)
Creates a new BulletVehicle instance in the given world and with a chassis node.
void set_brake(PN_stdfloat brake, int idx)
Applies braking force to the wheel with index idx.
void set_coordinate_system(BulletUpAxis up)
Specifies which axis is "up".
BulletWheel create_wheel()
Factory method for creating wheels for this vehicle instance.
One wheel of a BulletVehicle.
Definition bulletWheel.h:62
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.