- Main Page
- Modules
- Classes
- Files
- Related Pages

- File List
- File Members

# src/sim/Car.h

Go to the documentation of this file.

    00001 #ifndef CAR_H_
    00002 #define CAR_H_
    00003
    00004 #include <iostream>
    00005 #include <string>
    00006
    00007 #include "../config.h"
    00008 #include <ode/ode.h>
    00009 #include "../vectorMath/vmath.h"
    00010 #include "../iface/Visualized.h"
    00011 #include "../iface/Animated.h"
    00012 #include "SimulationObject.h"
    00013 #include "Sector.h"
    00014
    00015 class CarSource;
    00016
    00017 class Car: public SimulationObject, public Animated, public Visualized {
    00018 public:
    00019     Car(
    00020         Sector* sector,
    00021         const Vector3r& size,
    00022         const Vector3r& pos,
    00023         const dReal direction,
    00024         const dReal weight,
    00025         const dReal whdia,
    00026         const dReal whthick,
    00027         const dReal whweight,
    00028         const dReal maxSpeed
    00029     );
    00030     virtual ~Car();
    00031
    00032     //Getters and setters
    00033     //-----------------------------
    00035     Sector* getSector() { return _sector; };
    00037     Vector3r getPosition() const { return _position; };
    00039     Vector3r getPrevPosition() const { return _prevPosition; };
    00041     Vector3r getDirection() const { return _direction; };
    00043     Vector3r getPrevDirection() const { return _prevDirection; };
    00045     dReal getSpeed() { return _speed; };
    00047     void getBoundingBox(Vector3r &aa, Vector3r &bb);
    00049     SectorDeque &getPlannedSectors() { return _plannedSectors; };
    00051     SectorVector &getPassedSectors() { return _passedSectors; };
    00052
    00054     virtual void initialize();
    00056     virtual void computeStep();
    00058     virtual void performStep();
    00060     void carAddedToSectorHandler(Sector* s, Car* c);
    00062     void carRemovedFromSectorHandler(Sector* s, Car* c);
    00063
    00064     //Visualization-related methods
    00065     //-----------------------------
    00067     void visualize();
    00069     bool getShowCarBorderPaths() { return _showCarBorderPaths; };
    00071     void toggleShowCarBorderPaths() { _showCarBorderPaths = !_showCarBorderPaths; };
    00073     bool getShowCarBezierPath() { return _showCarBezierPath; };
    00075     void toggleShowCarBezierPath() { _showCarBezierPath = !_showCarBezierPath; };
    00077     bool getShowCarDirection() { return _showCarDirection; };
    00079     void toggleShowCarDirection() { _showCarDirection = !_showCarDirection; };
    00081     bool getShowCarIntersectionPoints() { return _showCarIntersectionPoints; };
    00083     void toggleShowCarIntersectionPoints() { _showCarIntersectionPoints = !_showCarIntersectionPoints; };
    00084
    00086     std::string toString() const;
    00087
    00088 private:
    00089     enum DriveMode { MODE_FREEWAY, MODE_FOLLOW, MODE_LET_GO };
    00091     void tracePath();
    00093     void selectNextBezierPoint();
    00095     void switchSector();
    00097     bool isColliding(Car* car);
    00099     CarPriority decidePriority(Car* car);
    00101     void addCarEventHandler(Sector* sector);
    00103     void removeCarEventHandler(Sector* sector);
    00104
    00106     Sector* _sector;
    00108     SectorDeque _plannedSectors;
    00110     SectorVector _passedSectors;
    00112     Line _transitLine;
    00114     Vector3r _position;
    00116     Vector3r _prevPosition;
    00118     Vector3r _direction;
    00120     dReal _trajectoryDeviation;
    00122     Vector3r _prevDirection;
    00124     Vector3r _lastPoint;
    00126     Vector3r _targetPoint;
    00128     Vector3r _nextPoint;
    00130     Line _switchLine;
    00132     bool _expectNewSector;
    00134     SectorCarMapping _carsInSight;
    00135
    00137     dBodyID _body;
    00139     dBodyID _wheels[4];
    00141     dJointID _hinges[4];
    00143     dGeomID _box;
    00145     dGeomID _spheres[4];
    00147     dSpaceID _space;
    00149     Vector3r _size;
    00151     Vector3r _pathTrackPoint;
    00153     dReal _wheelRadius;
    00155     dReal _wheelThickness;
    00157     Polygon _path;
    00159     Polygon _leftPathBorder;
    00161     Polygon _rightPathBorder;
    00163     Polygon _bezierPath;
    00165     dReal _speed;
    00167     dReal _targetSpeed;
    00169     dReal _maxSpeed;
    00171     dReal _acceleration;
    00173     dReal _maxAcceleration;
    00175     dReal _maxDecceleration;
    00177     DriveMode _driveMode;
    00178
    00179     Polygon _points;
    00180     std::vector<PVector3r> _vectors;
    00181
    00183     bool _showCarBorderPaths;
    00185     bool _showCarBezierPath;
    00187     bool _showCarDirection;
    00189     bool _showCarIntersectionPoints;
    00190
    00191     friend std::ostream& operator<<(std::ostream& os, const Car& car);
    00192     friend class CarSource;
    00193 };
    00194
    00195 #endif /*CAR_H_*/