home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- //////////////////////////////////////////////////////////////////////
- // Dynamics.h - definition of the dynamics class
- //////////////////////////////////////////////////////////////////////
-
- #ifndef DYNAMICS_H
- #define DYNAMICS_H
-
- #include "Defines.h"
- #include "MiscMath.h"
-
- #define BACK 0
- #define FRONT 1
-
- class Car;
- class Stretch;
- class Noise;
-
- class Dynamics {
-
- public:
-
- Dynamics(Car *);
- ~Dynamics();
-
- void reset_to_start(const Stretch *start, int side);
-
- // is the car moving ?
- Boolean moving() const { return (_velocity > EPSILON); };
-
- // used to set camera orientation
- const SbRotation get_view_orientation() const { return _view_orientation; };
-
- // used to set car orientation
- const SbRotation get_motion_orientation() const { return _motion_orientation; };
-
- // returns eye position relative to center of car in world coords
- const SbVec3f get_eye_position() const { return _eye_position; };
-
- // returns center of car in world coords
- const SbVec3f get_car_position() const { return _center_position; };
-
- float get_velocity() const { return _velocity; };
-
- Boolean get_off_road_left() const { return _off_road_left; };
- Boolean get_off_road_right() const { return _off_road_right; };
-
- // not const Stretch * because car list for each stretch
- // is affected by the driver when the car is moved, such
- // as after a crash
- Stretch * get_stretch(int end) const { return _stretch[end]; };
-
- int get_marker(int end) const { return _marker[end]; };
- float get_offset(int end) const { return _marker_offset[end]; };
- const SbVec3f get_flag(int side, int end) const { return _flag[side][end];};
- const SbVec3f get_position(int end) const { return _position[end];};
- const SbVec3f get_side_position(int side) const { return _side_position[side];};
-
- float get_yaw() const { return _yaw; };
-
- // updates the car's position/orientation based on user input and road
- void update();
-
- protected:
-
- // protected data members
-
- Car * _car; // car that these dynamics are controlling
-
- // The back and front of the car may be on different stretches
- // of road. Every stretch has _count-1 segments. The segments
- // that the back and front of the car are on are indicated by
- // the marker
-
- Stretch * _stretch[2];
- int _marker[2];
-
- // indicates how far along between markers
- // 0.0 to 1.0, beginning marker to ending marker
- float _marker_offset[2];
-
- // indicates position along left/right x front/back of stretch
- SbVec3f _flag[2][2];
-
- // orientation of the car
- SbVec3f _pitch_roll; // up vector of the car
- float _yaw; // radians about _pitch_roll
- SbRotation _view_orientation; // orientation of for the camera
- SbRotation _motion_orientation; // orientation to move the car
- SbMatrix _pitch_roll_mat; // used to transform eye position
- // in world coords relative to car
- // position of the car
- // the car is centered on right-handed axes and
- // is always pointing down it's negative z axis
- SbVec3f _position[2]; // in the world
- SbVec3f _side_position[2]; // in the world
- SbVec3f _center_position; // in the world
- SbVec3f _eye_position; // relative to center of car
- float _velocity; // distance per hour
- Boolean _off_road_left, _off_road_right;
-
- // gravity in road units per second per second
- float _gravity;
-
- // protected member functions
-
- // sets the front stretch, marker and marker offset, based on
- // the car's wheelbase
- // Assumes that the front marker and marker offset are 0.
- void initialize_front(int side);
-
- float get_delta_yaw() const;
- SbVec3f get_pitch_roll() const;
-
- void update_marker(int end);
- SbVec3f update_position();
- void compute_side_positions();
- void update_eye_position();
- void update_robot_position();
- void update_orientation();
- void compute_orientation();
- void compute_pitch_roll();
- void update_velocity();
- void update_brakes();
-
- void check_collisions(SbVec3f offset);
-
- // noises
- Noise * _screech;
-
- // count of robots cars with dynamics
- // used to spread them around the road
- static int _num_robots;
- };
-
- #endif
-
-