Engine::GameObjects::Car Class Reference

A vehicle that can be controled by a player using an input device. More...

#include <Car.h>

Inheritance diagram for Engine::GameObjects::Car:

Track::AABBDrawable Engine::Physics::TickObserver Track::NearTrack Track::Drawable Track::AABBBounded List of all members.

Public Member Functions

 Car (Physics::World &world, btTransform start, InputDevice *input_device, unsigned int car_model, const btVector3 &plane_normal, const btScalar &plane_distance, const btVector3 &start_point)
 Construct the car and place it into the game.
virtual ~Car ()
virtual void draw () const
 Draw the object.
virtual Track::AxisAlignedBoundingBox get_bounds () const
 Get the Axis aligned bounding box of the object.
void take_input (InputReport &report)
 Take input from a device.
virtual void set_forces ()
 apply driving forces to the physics engine's representation of the car.
virtual void posttick ()
 update the physics
void get_transform (btTransform &transform)
signed int get_lap ()
 Return the lap the car is on.
unsigned long int get_last_lap_ticks ()
 Return the number of ticks taken to complete the last lap.
unsigned long int get_best_lap_ticks ()
 Return the number of ticks taken to complete the fastest lap.
btScalar get_speed ()
 Return the speed the car is travelling at in decimeters per second.
btScalar get_lap_distance () const
 Return the distance from the start of the lap.
bool get_finished () const
 Return true if three laps have been completed.
bool get_disqualified () const
 Return true if the car has been disqualifed.
unsigned long int get_finish_time () const
 Return the time taken to complete the course or get disqualified.
int get_facing_backwards () const
 Find if car is facing the wrong way.
btScalar get_camera_height () const
 Find a suitable height for a camera.
void get_sensors (float results[NUM_SENSORS]) const
 Return the relative distance to the goal in various directions.

Static Public Attributes

static const unsigned int NUM_SENSORS_FEELERS = 8
 The number of directions the cpu car directional sensors read.
static const unsigned int NUM_FEELER_PROPERTIES = Track::SENSOR_COUNT
 The number of values of data each directional feeler has.
static const unsigned int NUM_SENSORS = NUM_SENSORS_FEELERS * NUM_FEELER_PROPERTIES + 14
 The total number of sensor values.

Private Member Functions

 Car (Car &car)
Caroperator= (Car &car)
void remove ()
 Remove the car from the course.
void update_sounds ()
 Set the volume, pitch, position and velocity of the sound sources.

Private Attributes

Track::Texturetexture
Track::BulletMeshmesh
Track::Textureflame_texture
 The texture used for the engine flame effect.
Track::BulletMeshflame_mesh
 The mesh used for the engine flame effect.
Physics::Worldworld
btRigidBody * rigid_body
InputDeviceinput_device
btVector3 force
btVector3 torque
btVector3 local_force
btVector3 local_torque
bool floor_stick
 True when sticking to a floor, false if falling.
unsigned int car_model
 Which car mesh and texture to use.
signed int lap
 the lap the car is on
signed int max_lap
 The highest numbered lap ever reached.
unsigned long int lap_start_ticks
 The tick number when starting the last lap.
unsigned long int last_lap_ticks
 The number of ticks taken to complete the last lap.
unsigned long int best_lap_ticks
 The number of ticks taken to complete the fastest lap.
bool infront_of_start
 True if infront of the start line.
const btVector3 & plane_normal
const btScalar & plane_distance
const btVector3 & start_point
btScalar elastic_potential_energy
 energy built up when breaking.
btScalar tick_energy_absorbed
 amount of energy built up while breaking in the last frame.
btScalar used_energy_boost
 The amount stored of enery released last tick.
unsigned int boost_timer
 number of ticks since last boost.
bool m_course_complete
 True if 3 laps have been completed.
unsigned long int m_course_complete_time
 The time in ticks taken to complete three laps.
bool m_removed
 True if the car has been removed from the course.
btTransform m_last_transform
 The transformation used when the car crossed the finish line.
boost::shared_ptr< SoundSourcem_engine_sound_source
 The sound effect for the engine accelerating noise.
boost::shared_ptr< SoundSourcem_drag_sound_source
 The sound effect when the car is moving independant of acceleration.
boost::shared_ptr< SoundSourcem_break_sound_source
 The sound effect when the car is braking.
boost::shared_ptr< SoundSourcem_boost_sound_source
 The sound effect for the booster noise.
boost::shared_ptr< SoundSourcem_release_energy_sound_source
 The sound effect for releasing energy stored while breaking.
boost::shared_ptr< SoundSourcem_slide_sound_source
 The sound effect for sliding sideways.

Detailed Description

A vehicle that can be controled by a player using an input device.

Definition at line 36 of file Car.h.


Constructor & Destructor Documentation

Engine::GameObjects::Car::Car ( Car car  )  [private]

Engine::GameObjects::Car::Car ( Physics::World world,
btTransform  start,
InputDevice input_device,
unsigned int  car_model,
const btVector3 &  plane_normal,
const btScalar &  plane_distance,
const btVector3 &  start_point 
)

Construct the car and place it into the game.

Parameters:
world The Physics world of the game.
start The transformation for the starting position.
Todo:
Get a proper starting position.
Parameters:
input_device The input device to bind the car to.
car_model The mesh and texture of the car. Must be 0 or 1.
plane_normal The unit normal of the start/finish plane.
plane_distance The signed distance between the start/finish plane and the origin.
start_point The centre of the start/finish line.

Definition at line 120 of file Car.cpp.

Engine::GameObjects::Car::~Car (  )  [virtual]

Definition at line 244 of file Car.cpp.


Member Function Documentation

void Engine::GameObjects::Car::draw (  )  const [virtual]

Draw the object.

Called indirectly by draw(const OcclusionTester &) const when it is on the screen, but can also be called manually if view bounds are not known.

Implements Track::Drawable.

Definition at line 267 of file Car.cpp.

unsigned long int Engine::GameObjects::Car::get_best_lap_ticks (  ) 

Return the number of ticks taken to complete the fastest lap.

Definition at line 782 of file Car.cpp.

Track::AxisAlignedBoundingBox Engine::GameObjects::Car::get_bounds (  )  const [virtual]

Get the Axis aligned bounding box of the object.

The object is contained entierly within this region.

Implements Track::AABBBounded.

Definition at line 251 of file Car.cpp.

btScalar Engine::GameObjects::Car::get_camera_height (  )  const

Find a suitable height for a camera.

Takes into account the slope of the track infront of the car.

Definition at line 881 of file Car.cpp.

bool Engine::GameObjects::Car::get_disqualified (  )  const

Return true if the car has been disqualifed.

Definition at line 823 of file Car.cpp.

int Engine::GameObjects::Car::get_facing_backwards (  )  const

Find if car is facing the wrong way.

If facing the right way, returns 0. Otherwise returns a value between 1 and 255 indicating how wrong the directions is.

Definition at line 833 of file Car.cpp.

unsigned long int Engine::GameObjects::Car::get_finish_time (  )  const

Return the time taken to complete the course or get disqualified.

Precondition: get_finished() or get_disqualified() returns true.

Returns:
time in ticks taken to complete three laps or get disqualified.

Definition at line 828 of file Car.cpp.

bool Engine::GameObjects::Car::get_finished (  )  const

Return true if three laps have been completed.

Definition at line 818 of file Car.cpp.

signed int Engine::GameObjects::Car::get_lap (  ) 

Return the lap the car is on.

Definition at line 772 of file Car.cpp.

btScalar Engine::GameObjects::Car::get_lap_distance (  )  const

Return the distance from the start of the lap.

Definition at line 793 of file Car.cpp.

unsigned long int Engine::GameObjects::Car::get_last_lap_ticks (  ) 

Return the number of ticks taken to complete the last lap.

Definition at line 777 of file Car.cpp.

void Engine::GameObjects::Car::get_sensors ( float  results[NUM_SENSORS]  )  const

Return the relative distance to the goal in various directions.

Gives the difference between the distance to the goal of the car and the difference to the goal of other points: 1m infront of the car, 1m behind the car, 1m to the left of the car, 1m to the right of the car

Parameters:
results array where calculated values will be written.

Todo:
direction and distance to nearest booster(s).

direction and distance to nearest other car(s).

See if the scales can be removed once the AI is good enough.

See if any sensor can be removed once the AI is good enough.

Definition at line 901 of file Car.cpp.

btScalar Engine::GameObjects::Car::get_speed (  ) 

Return the speed the car is travelling at in decimeters per second.

Definition at line 787 of file Car.cpp.

void Engine::GameObjects::Car::get_transform ( btTransform &  transform  ) 

Definition at line 762 of file Car.cpp.

Car& Engine::GameObjects::Car::operator= ( Car car  )  [private]

void Engine::GameObjects::Car::posttick (  )  [virtual]

update the physics

Todo:
better lap detection. We count it if the car is within 17 units of the start/finish line. It is fiesable that this is wrong in some cases (e.g. on a mobius stip this would count the lap twice.)

Todo:
recycle some vertical momentum as forwards momentum

Todo:
do this smoothly for anolgue input.

Implements Engine::Physics::TickObserver.

Definition at line 433 of file Car.cpp.

void Engine::GameObjects::Car::remove (  )  [private]

Remove the car from the course.

Definition at line 803 of file Car.cpp.

void Engine::GameObjects::Car::set_forces (  )  [virtual]

apply driving forces to the physics engine's representation of the car.

Reimplemented from Engine::Physics::TickObserver.

Definition at line 426 of file Car.cpp.

void Engine::GameObjects::Car::take_input ( InputReport report  ) 

Take input from a device.

Change to accelerator / break amount

Change to sideways crabbing control

Change to steering wheel angle

Definition at line 401 of file Car.cpp.

void Engine::GameObjects::Car::update_sounds (  )  [private]

Set the volume, pitch, position and velocity of the sound sources.

Definition at line 1030 of file Car.cpp.


Member Data Documentation

unsigned long int Engine::GameObjects::Car::best_lap_ticks [private]

The number of ticks taken to complete the fastest lap.

Definition at line 153 of file Car.h.

unsigned int Engine::GameObjects::Car::boost_timer [private]

number of ticks since last boost.

Definition at line 170 of file Car.h.

unsigned int Engine::GameObjects::Car::car_model [private]

Which car mesh and texture to use.

Definition at line 142 of file Car.h.

btScalar Engine::GameObjects::Car::elastic_potential_energy [private]

energy built up when breaking.

Definition at line 163 of file Car.h.

Track::BulletMesh* Engine::GameObjects::Car::flame_mesh [private]

The mesh used for the engine flame effect.

Definition at line 130 of file Car.h.

Track::Texture* Engine::GameObjects::Car::flame_texture [private]

The texture used for the engine flame effect.

Definition at line 128 of file Car.h.

bool Engine::GameObjects::Car::floor_stick [private]

True when sticking to a floor, false if falling.

Definition at line 139 of file Car.h.

btVector3 Engine::GameObjects::Car::force [private]

Definition at line 135 of file Car.h.

bool Engine::GameObjects::Car::infront_of_start [private]

True if infront of the start line.

Definition at line 156 of file Car.h.

InputDevice* Engine::GameObjects::Car::input_device [private]

Definition at line 134 of file Car.h.

signed int Engine::GameObjects::Car::lap [private]

the lap the car is on

Definition at line 145 of file Car.h.

unsigned long int Engine::GameObjects::Car::lap_start_ticks [private]

The tick number when starting the last lap.

Definition at line 149 of file Car.h.

unsigned long int Engine::GameObjects::Car::last_lap_ticks [private]

The number of ticks taken to complete the last lap.

Definition at line 151 of file Car.h.

btVector3 Engine::GameObjects::Car::local_force [private]

Definition at line 135 of file Car.h.

btVector3 Engine::GameObjects::Car::local_torque [private]

Definition at line 135 of file Car.h.

boost::shared_ptr<SoundSource> Engine::GameObjects::Car::m_boost_sound_source [private]

The sound effect for the booster noise.

Definition at line 195 of file Car.h.

boost::shared_ptr<SoundSource> Engine::GameObjects::Car::m_break_sound_source [private]

The sound effect when the car is braking.

Definition at line 193 of file Car.h.

bool Engine::GameObjects::Car::m_course_complete [private]

True if 3 laps have been completed.

Definition at line 173 of file Car.h.

unsigned long int Engine::GameObjects::Car::m_course_complete_time [private]

The time in ticks taken to complete three laps.

Definition at line 175 of file Car.h.

boost::shared_ptr<SoundSource> Engine::GameObjects::Car::m_drag_sound_source [private]

The sound effect when the car is moving independant of acceleration.

Definition at line 191 of file Car.h.

boost::shared_ptr<SoundSource> Engine::GameObjects::Car::m_engine_sound_source [private]

The sound effect for the engine accelerating noise.

Definition at line 189 of file Car.h.

btTransform Engine::GameObjects::Car::m_last_transform [private]

The transformation used when the car crossed the finish line.

Definition at line 183 of file Car.h.

boost::shared_ptr<SoundSource> Engine::GameObjects::Car::m_release_energy_sound_source [private]

The sound effect for releasing energy stored while breaking.

Definition at line 197 of file Car.h.

bool Engine::GameObjects::Car::m_removed [private]

True if the car has been removed from the course.

If m_course_complete is set, it finished, otherwise it has been disqualified.

Definition at line 180 of file Car.h.

boost::shared_ptr<SoundSource> Engine::GameObjects::Car::m_slide_sound_source [private]

The sound effect for sliding sideways.

Definition at line 199 of file Car.h.

signed int Engine::GameObjects::Car::max_lap [private]

The highest numbered lap ever reached.

Definition at line 147 of file Car.h.

Track::BulletMesh* Engine::GameObjects::Car::mesh [private]

Definition at line 126 of file Car.h.

const unsigned int Engine::GameObjects::Car::NUM_FEELER_PROPERTIES = Track::SENSOR_COUNT [static]

The number of values of data each directional feeler has.

Definition at line 47 of file Car.h.

const unsigned int Engine::GameObjects::Car::NUM_SENSORS = NUM_SENSORS_FEELERS * NUM_FEELER_PROPERTIES + 14 [static]

The total number of sensor values.

Definition at line 49 of file Car.h.

const unsigned int Engine::GameObjects::Car::NUM_SENSORS_FEELERS = 8 [static]

The number of directions the cpu car directional sensors read.

Definition at line 45 of file Car.h.

const btScalar& Engine::GameObjects::Car::plane_distance [private]

Definition at line 159 of file Car.h.

const btVector3& Engine::GameObjects::Car::plane_normal [private]

Definition at line 158 of file Car.h.

btRigidBody* Engine::GameObjects::Car::rigid_body [private]

Definition at line 133 of file Car.h.

const btVector3& Engine::GameObjects::Car::start_point [private]

Definition at line 160 of file Car.h.

Track::Texture* Engine::GameObjects::Car::texture [private]

Definition at line 125 of file Car.h.

btScalar Engine::GameObjects::Car::tick_energy_absorbed [private]

amount of energy built up while breaking in the last frame.

Definition at line 165 of file Car.h.

btVector3 Engine::GameObjects::Car::torque [private]

Definition at line 135 of file Car.h.

btScalar Engine::GameObjects::Car::used_energy_boost [private]

The amount stored of enery released last tick.

Definition at line 167 of file Car.h.

Physics::World& Engine::GameObjects::Car::world [private]

Definition at line 132 of file Car.h.


The documentation for this class was generated from the following files:
Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:17 2010 by Doxygen version 1.4.7 for Racer version svn335.