17 #include <core/sim/camera.h> 18 #include <core/sim/accelerometer.h> 19 #include <core/sim/touch_sensor.h> 20 #include <core/sim/compass.h> 21 #include <core/utils.h> 23 #include <third_party/box2d/box2d.h> 32 float camera_fov = 90;
33 int camera_resolution = 64;
34 bool camera_depth =
false;
35 bool touch_sensor =
false;
36 int touch_resolution = 16;
37 bool accelerometer =
false;
39 float max_forward_force = 10.0f;
40 float max_reverse_force = 4.0f;
41 float max_steer_angle = 40.0f;
42 float density = 0.01f;
43 float tire_traction = 1.5f;
44 float friction = 1.0f;
50 Car(b2World* world,
const CarConfig& config);
53 void postStep(
float dt);
57 void accelerate(
float force);
61 void steer(
float steer_wheel_position);
64 void brake(
float intensity);
67 const Camera* camera()
const {
return camera_.get(); }
68 const TouchSensor* touchSensor()
const {
return touch_sensor_.get(); }
69 const Accelerometer* accelerometer()
const {
return accelerometer_.get(); }
70 const Compass* compass()
const {
return compass_.get(); }
72 const b2Vec2& actualVelocity()
const {
return actual_velocity_; }
74 b2Body* body() {
return car_body_; }
75 const b2Body* body()
const {
return car_body_; }
77 const auto& config()
const {
return config_; }
81 void createWheelFixture(b2Body* body,
const b2Vec2& pos);
82 void createLightFixture(
const b2Vec2& pos,
const b2Color& color);
83 b2RevoluteJoint* createTurningWheel(b2World* world,
const b2Vec2& pos);
85 void updateSteering();
86 void applyBrakeImpulse(
float intensity,
87 const b2Vec2& wheel_normal,
88 const b2Vec2& wheel_center);
89 void applyTireLateralImpulse(
const b2Vec2& wheel_normal,
const b2Vec2& wheel_center);
91 float width()
const {
return config_.length * 0.5f; }
92 float frontAxleOffset()
const {
return config_.length * 0.3f; }
93 float rearAxleOffset()
const {
return config_.length * -0.3f; }
96 b2Body* car_body_ =
nullptr;
97 b2RevoluteJoint* left_wheel_joint_ =
nullptr;
98 b2RevoluteJoint* right_wheel_joint_ =
nullptr;
99 b2Vec2 last_position_ = { 0, 0 };
100 b2Vec2 actual_velocity_ = { 0, 0 };
101 float target_steer_ = 0;
102 float brake_pedal_ = 0;
103 unique_ptr<Camera> camera_;
104 unique_ptr<TouchSensor> touch_sensor_;
105 unique_ptr<Accelerometer> accelerometer_;
106 unique_ptr<Compass> compass_;
107 const CarConfig config_;
Definition: accelerometer.cpp:19
Classes derived from this are not copyable or movable.
Definition: utils.h:69