home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / drive / Dynamics.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.7 KB  |  153 lines

  1. /*
  2.  * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. //////////////////////////////////////////////////////////////////////
  18. // Dynamics.h - definition of the dynamics class
  19. //////////////////////////////////////////////////////////////////////
  20.  
  21. #ifndef DYNAMICS_H
  22. #define DYNAMICS_H
  23.  
  24. #include "Defines.h"
  25. #include "MiscMath.h"
  26.  
  27. #define BACK 0
  28. #define FRONT 1
  29.  
  30. class Car;
  31. class Stretch;
  32. class Noise;
  33.  
  34. class Dynamics  {
  35.  
  36. public:
  37.  
  38.     Dynamics(Car *);
  39.     ~Dynamics();
  40.  
  41.     void reset_to_start(const Stretch *start, int side);
  42.  
  43.     // is the car moving ?
  44.     Boolean moving() const { return (_velocity > EPSILON); };
  45.  
  46.     // used to set camera orientation
  47.     const SbRotation get_view_orientation() const { return _view_orientation; };
  48.  
  49.     // used to set car orientation
  50.     const SbRotation get_motion_orientation() const { return _motion_orientation; };
  51.  
  52.     // returns eye position relative to center of car in world coords
  53.     const SbVec3f get_eye_position() const { return _eye_position; };
  54.  
  55.     // returns center of car in world coords
  56.     const SbVec3f get_car_position() const { return _center_position; };
  57.     
  58.     float get_velocity() const { return _velocity; };
  59.  
  60.     Boolean get_off_road_left() const { return _off_road_left; };
  61.     Boolean get_off_road_right() const { return _off_road_right; };
  62.  
  63.     // not const Stretch * because car list for each stretch
  64.     // is affected by the driver when the car is moved, such
  65.     // as after a crash
  66.     Stretch * get_stretch(int end) const { return _stretch[end]; };
  67.     
  68.     int get_marker(int end) const { return _marker[end]; };
  69.     float get_offset(int end) const { return _marker_offset[end]; };
  70.     const SbVec3f get_flag(int side, int end) const { return _flag[side][end];};
  71.     const SbVec3f get_position(int end) const { return _position[end];};
  72.     const SbVec3f get_side_position(int side) const { return _side_position[side];};
  73.  
  74.     float get_yaw() const { return _yaw; };
  75.  
  76.     // updates the car's position/orientation based on user input and road
  77.     void update();
  78.     
  79. protected:
  80.  
  81.     // protected data members
  82.     
  83.     Car * _car; // car that these dynamics are controlling
  84.     
  85.     // The back and front of the car may be on different stretches
  86.     // of road. Every stretch has _count-1 segments. The segments
  87.     // that the back and front of the car are on are indicated by
  88.     // the marker
  89.     
  90.     Stretch * _stretch[2];
  91.     int _marker[2];
  92.  
  93.     // indicates how far along between markers
  94.     // 0.0 to 1.0, beginning marker to ending marker
  95.     float _marker_offset[2];
  96.  
  97.     // indicates position along left/right x front/back of stretch
  98.     SbVec3f _flag[2][2];
  99.  
  100.     // orientation of the car
  101.     SbVec3f _pitch_roll;        // up vector of the car
  102.     float _yaw;                    // radians about _pitch_roll
  103.     SbRotation _view_orientation;    // orientation of for the camera
  104.     SbRotation _motion_orientation;    // orientation to move the car
  105.     SbMatrix _pitch_roll_mat;    // used to transform eye position
  106.                                 // in world coords relative to car
  107.     // position of the car
  108.     // the car is centered on right-handed axes and
  109.     // is always pointing down it's negative z axis
  110.     SbVec3f _position[2];        // in the world
  111.     SbVec3f _side_position[2];    // in the world
  112.     SbVec3f _center_position;    // in the world
  113.     SbVec3f _eye_position;        // relative to center of car
  114.     float _velocity;            // distance per hour
  115.     Boolean _off_road_left, _off_road_right;
  116.  
  117.     // gravity in road units per second per second
  118.     float _gravity;
  119.  
  120.     // protected member functions
  121.  
  122.     // sets the front stretch, marker and marker offset, based on
  123.     // the car's wheelbase
  124.     // Assumes that the front marker and marker offset are 0.
  125.     void initialize_front(int side);
  126.     
  127.     float get_delta_yaw() const;
  128.     SbVec3f get_pitch_roll() const;
  129.  
  130.     void update_marker(int end);
  131.     SbVec3f update_position();
  132.     void compute_side_positions();
  133.     void update_eye_position();
  134.     void update_robot_position();
  135.     void update_orientation();
  136.     void compute_orientation();
  137.     void compute_pitch_roll();
  138.     void update_velocity();
  139.     void update_brakes();
  140.  
  141.     void check_collisions(SbVec3f offset);
  142.  
  143.     // noises
  144.     Noise * _screech;
  145.  
  146.     // count of robots cars with dynamics
  147.     // used to spread them around the road
  148.     static int _num_robots;
  149. };
  150.  
  151. #endif
  152.     
  153.