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.c++ - implementation of the dynamics class
- //////////////////////////////////////////////////////////////////////
-
- #include "Defines.h"
- #include "Simulation.h"
- #include "MiscMath.h"
- #include "Dynamics.h"
- #include "Car.h"
- #include "Driver.h"
- #include "Cockpit.h"
- #include "Engine.h"
- #include "Road.h"
- #include "Stretch.h"
- #include "Noise.h"
- #include "Timer.h"
- #include "Bspline.h"
- #include <Inventor/SbString.h>
-
- int Dynamics::_num_robots = 0;
-
- Dynamics::Dynamics(Car *c)
- {
- _car = c;
-
- // gravity in road units per second per second
- _gravity = 32.0;
-
- // start the car in the right place
- if (_car->get_type() == LOCAL_CAR)
- reset_to_start(_car->get_road()->get_start(), RIGHT);
- else
- {
- // spread robot cars around the track
- const Stretch * start = _car->get_road()->get_start();
-
- for (int i = 0; i < _num_robots+1; i++)
- {
- if (_num_robots%2)
- start = start->get_next();
- else
- start = start->get_prev();
- }
-
- reset_to_start(start, RIGHT);
- _num_robots++;
- }
-
- // Screech noise starts as discontinuous, is made continuous when
- // the tires are squeeling, then made discontinuous again.
- // Assume longest length of 8 fps.
- // XXX For now, only the local car makes noise. Soon, you'll
- // be able to hear other car's on the track as well.
- _screech = NULL;
- if ((_car->get_type() == LOCAL_CAR) &&
- _car->get_simulation()->sound_capable())
- {
- SbString screechpath(_car->get_simulation()->get_path().getString());
- SbString screechfile("screech.aiff");
- screechpath += screechfile;
-
- _screech = new Noise(screechpath.getString(),125000,FALSE);
- }
- }
-
-
- // Moves the car to the beginning of the givin stretch, orients it
- // in the right direction, and puts it at the middle of the
- // given side.
- //
- // If side is RIGHT, the car's back starts at marker 0, and faces in
- // the direction of increasing markers.
- //
- // If side is LEFT, the car's back starts at marker n-1, and faces in
- // the direction of decreasing markers.
- //
- // XXX Only RIGHT supported, right now.
- void Dynamics::reset_to_start(const Stretch *start, int side)
- {
- // initial dynamics
- _velocity = 0.0;
-
- // initialize back position stuff
- if (side == RIGHT)
- {
- _stretch[BACK] = (Stretch *)start;
- _marker[BACK] = 0;
- _marker_offset[BACK] = 0.0;
-
- // position back at middle of right side of road
- // XXX different for english driving
- _position[BACK] = start->road_pos(RIGHT,0);
- }
- else
- fprintf(stderr,"Dynamics::reset_to_start - LEFT not yet supported\n");
-
- // set the front stretch, marker, and position
- // based on the wheelbase of the car
- initialize_front(side);
-
- _center_position = (_position[BACK] + _position[FRONT])/2.0;
-
- // we're certainly on the road
- _off_road_left = _off_road_right = FALSE;
-
- // initial orientation based on actual position on road
- compute_orientation();
-
- // set eye position based on orientation
- update_eye_position();
-
- compute_side_positions();
-
- _stretch[BACK]->add_car(_car);
- }
-
-
- Dynamics::~Dynamics()
- {
- if (_screech)
- delete _screech;
- }
-
-
- // Sets the front stretch, marker and position based on
- // the car's wheelbase and the back stretch.
- // Assumes that the back marker and marker offset are 0.
- void Dynamics::initialize_front(int side)
- {
- // XXX
- if (side == LEFT)
- fprintf(stderr,"Dynamics::initialize_front - LEFT not yet supported\n");
-
- float total_length = 0.0;
- float segment_length;
- Stretch *stretch = _stretch[BACK];
- int marker = 0;
-
- while (total_length < _car->get_wheelbase())
- {
- segment_length = stretch->get_direction(marker, MIDDLE).length();
- total_length += segment_length;
-
- if (total_length <= _car->get_wheelbase())
- {
- int next_marker;
- const Stretch *next_stretch =
- stretch->get_next_stretch(marker, next_marker);
-
- stretch = (Stretch *)next_stretch;
- marker = next_marker;
- }
- }
-
- _stretch[FRONT] = stretch;
- _marker[FRONT] = marker;
-
- _marker_offset[FRONT] =
- (segment_length - (total_length - _car->get_wheelbase()))/segment_length;
-
- int next_marker;
- const Stretch *next_stretch =
- _stretch[FRONT]->get_next_stretch(_marker[FRONT], next_marker);
-
- SbVec3f this_stretch_pos = _stretch[FRONT]->road_pos(RIGHT,_marker[FRONT]);
- SbVec3f next_stretch_pos = next_stretch->road_pos(RIGHT,next_marker);
-
- _position[FRONT] =
- (1.0-_marker_offset[FRONT])*this_stretch_pos +
- _marker_offset[FRONT]*next_stretch_pos;
- }
-
-
- // Knowing the back and front positions, the up vector (_pitch_roll),
- // and the width of the car, compute the left and right positions.
- // The left and right positions are at the front of the car.
- void Dynamics::compute_side_positions()
- {
- SbVec3f forward = _position[FRONT] - _position[BACK];
- SbVec3f right = forward.cross(_pitch_roll);
- right.normalize();
-
- SbVec3f offset = (_car->get_width()/2.0)*right;
- _side_position[RIGHT] = _position[FRONT] + offset;
- _side_position[LEFT] = _position[FRONT] - offset;
- }
-
-
-
- // returns radians change in yaw based on steering wheel
- float Dynamics::get_delta_yaw() const
- {
- return
- _car->get_driver()->get_cockpit()->get_steering()*
- _car->get_engine()->get_yaw_per_steering();
- }
-
-
- // Returns the normal representing pitch and roll for the car.
- // Based on normals at current and next marker positions,
- // interpolated by the marker offset.
- //
- // XXX Also sets the left and right flags that show the car's
- // position along the side of the road.
- SbVec3f Dynamics::get_pitch_roll() const
- {
- SbVec3f interp[2];
-
- for (int i = BACK; i <= FRONT; i++)
- {
- SbVec3f normal[2], flag[2][2];
- const Stretch * next_stretch;
- int next_marker;
-
- next_stretch = _stretch[i]->get_next_stretch(_marker[i], next_marker);
-
- normal[0] = _stretch[i]->get_normal(_marker[i]);
- normal[1] = next_stretch->get_normal(next_marker);
-
- flag[LEFT][0] = _stretch[i]->get_left(_marker[i]);
- flag[LEFT][1] = next_stretch->get_left(next_marker);
-
- flag[RIGHT][0] = _stretch[i]->get_right(_marker[i]);
- flag[RIGHT][1] = next_stretch->get_right(next_marker);
-
- // interpolate normal based on marker offset
- interp[i] =
- (1.0 - _marker_offset[i])*normal[0] +
- _marker_offset[i]*normal[1];
-
- // interpolate side-of-road position
- // _flag[LEFT][i] =
- flag[LEFT][i] =
- (1.0 - _marker_offset[i])*flag[LEFT][0] +
- _marker_offset[i]*flag[LEFT][1];
-
- // _flag[RIGHT][i] =
- flag[RIGHT][i] =
- (1.0 - _marker_offset[i])*flag[RIGHT][0] +
- _marker_offset[i]*flag[RIGHT][1];
- }
-
- SbVec3f result = (interp[BACK] + interp[FRONT])/2.0;
- result.normalize();
-
- return result;
- }
-
-
-
- void Dynamics::update_marker(int end)
- {
- // find the next stretch and marker. Most of the time,
- // next_stretch will == _stretch[end] (unless the car
- // really has moved on to the next stretch
- int next_marker;
- const Stretch * next_stretch =
- _stretch[end]->get_next_stretch(_marker[end],next_marker);
-
- /// keep the wheels on the ground by projecting the
- /// wheels onto the ground plane
-
- // Construct the road plane from three points on the road
- SbPlane road_plane(
- _stretch[end]->get_left(_marker[end]),
- _stretch[end]->get_right(_marker[end]),
- next_stretch->get_left(next_marker));
-
- // Construct line passing through wheel with normal of car
- SbLine wheel_line(_position[end], _position[end] + _pitch_roll);
-
- // intersection of that line with the road plane is the
- // projection of the wheels onto the road
- if (! road_plane.intersect(wheel_line,_position[end]))
- fprintf(stderr,"Dynamics: wheel_line parallel to road!\n");
-
-
- /// Update the stretch, marker and marker offset.
-
- // find the marker offset
- // marker offset is 0.0 at the beginning of a stretch segment,
- // 1.0 when you hit the next marker (at which point it rolls
- // over to 0.0 again)
- float new_marker_offset = 0.0;
-
- //printf("update1: new_marker_offset %f, this %x\n",new_marker_offset,this);
-
- // XXX had to do this to avoid NaN's
- Boolean on_to_next_marker;
- on_to_next_marker = _stretch[end]->get_marker_offset(
- _marker[end],_position[end], &new_marker_offset);
-
- //printf("update2: new_marker_offset %f\n",new_marker_offset);
- //if (new_marker_offset != new_marker_offset)
- //printf("HOSED1\n");
- //if ((new_marker_offset < 0.0) || (new_marker_offset > 1.0))
- //printf("HOSED2\n");
-
- if (on_to_next_marker)
- {
- // the stretches maintain a list of which cars
- // are on them. If we went on to the next stretch,
- // remove the car from this one and add it to the next.
- if ((end == BACK) && (next_stretch != _stretch[end]))
- {
- _stretch[end]->remove_car(_car);
- ((Stretch *)next_stretch)->add_car(_car);
- }
-
- _stretch[end] = (Stretch *) next_stretch;
- _marker[end] = next_marker;
-
- // XXX is this the right place to do this?
- // check if lap
- if ((end == FRONT) &&
- (_stretch[end] == _car->get_road()->get_start()) &&
- (_marker[end] == 0) &&
- (_car->get_type() == LOCAL_CAR))
- _car->get_driver()->get_timer()->lap();
- }
-
- _marker_offset[end] = new_marker_offset;
- //printf("update3: new_marker_offset %f\n",_marker_offset[end]);
- }
-
-
-
-
- // Update the car's position, stretches, markers and marker offsets.
- // Returns the vector the car moved
- SbVec3f Dynamics::update_position()
- {
- //// First, update the car's position based on its velocity and
- //// orientation. Do this by pumping a velocity vector through
- //// the orientation matrix to find the offset (from this current
- //// position to next position. Then add that offset to the
- //// back position. Then update the front position relative
- //// to the back position.
-
- // distance the car moved in this frame
- // dist/frame = dist/hour * hour/60min * min/60sec * sec/frame
- SbVec3f frame_velocity(0,0,0);
- frame_velocity[2] =
- - _car->get_road()->get_distance_factor() *
- _velocity/(60.0*60.0*_car->get_simulation()->get_fps());
-
- // get the orientation rotation matrix
- SbMatrix orientation;
- _motion_orientation.getValue(orientation);
-
- // rotate the velocity vector to get the offset
- SbVec3f offset;
- orientation.multVecMatrix(frame_velocity, offset);
-
- // XXX not quite sure why this is necessary, coordinate systems maybe?
- offset[0] = - offset[0];
- float offset_length = offset.length();
-
- // XXX Ick. Need to handle long offsets
- if (offset_length > _stretch[FRONT]->get_step())
- {
- float new_offset_length = _stretch[FRONT]->get_step();
- offset /= (offset_length/new_offset_length);
- }
-
- //// Now that we have the car's offset, update the position of the
- //// car, making sure it does not penetrate the road. Then update
- //// the stretch, marker and marker offset.
- //// Do all this for both the back and the front of the car.
-
- // update the position of the car
- _position[BACK] += offset;
- update_marker(BACK);
-
- // Front of the car is extended forwards in the
- // direction of the offset by the length of the car
- SbVec3f front_offset = offset;
- front_offset.normalize(); // make unit length
- front_offset *= _car->get_wheelbase();
-
- // don't do anything if the offset is too small
- if (fabs(front_offset.length() - _car->get_wheelbase()) < .01)
- {
- _position[FRONT] = _position[BACK] + front_offset;
- update_marker(FRONT);
- }
-
- // update the center position of the car
- _center_position = (_position[BACK] + _position[FRONT])/2.0;
-
- /// Check to see if we went off the road
-
- SbVec3f left_vec = _stretch[FRONT]->get_direction(_marker[FRONT],LEFT);
- float left_dist =
- point_vec_distance(_position[FRONT], left_vec,
- _stretch[FRONT]->get_left(_marker[FRONT]));
-
- if (! _off_road_left)
- _off_road_right =
- ((left_dist + _car->get_width()/2.0) > _stretch[FRONT]->get_width());
-
-
- SbVec3f right_vec = _stretch[FRONT]->get_direction(_marker[FRONT],RIGHT);
- float right_dist =
- point_vec_distance(_position[FRONT], right_vec,
- _stretch[FRONT]->get_right(_marker[FRONT]));
-
- if (! _off_road_right)
- _off_road_left =
- ((right_dist + _car->get_width()/2.0) > _stretch[FRONT]->get_width());
-
- /// return the car's positional offset vector
- return offset;
- }
-
- void Dynamics::update_eye_position()
- {
- // update the eye position (relative to car) based on pitch and roll
- _pitch_roll_mat.multDirMatrix(_car->get_driver_position(),_eye_position);
- }
-
-
- // Update the a robot car's position, stretches, markers and marker offsets.
- void Dynamics::update_robot_position()
- {
- //printf("\nrobot dynamics %x\n",this);
-
- // find the middle of the right side for the previous, current
- // and next markers
-
- SbVec3f this_stretch_pos = _stretch[BACK]->road_pos(RIGHT,_marker[BACK]);
-
- int next_marker;
- const Stretch *next_stretch =
- _stretch[BACK]->get_next_stretch(_marker[BACK], next_marker);
- SbVec3f next_stretch_pos = next_stretch->road_pos(RIGHT,next_marker);
-
- int prev_marker;
- const Stretch *prev_stretch =
- _stretch[BACK]->get_prev_stretch(_marker[BACK], prev_marker);
- SbVec3f prev_stretch_pos = prev_stretch->road_pos(RIGHT,prev_marker);
-
- // offset the car moved in this frame
- // offset/frame = (dist/frame)*(offset/dist)
- // dist/frame = dist/hour * hour/60min * min/60sec * sec/frame
- float offset =
- _marker_offset[BACK] +
- (1.0/_stretch[BACK]->get_step()) *
- _car->get_road()->get_distance_factor() *
- _velocity/(60.0*60.0*_car->get_simulation()->get_fps());
-
- /*
- printf("marker_offset before %f\n", _marker_offset[BACK]);
- printf("marker before %d\n", _marker[BACK]);
- printf("offset before %f\n", offset);
- */
-
- // if we go on to the next marker, update the stretch and markers
- if (offset >= 1.0)
- {
- offset -= 1.0;
- prev_stretch_pos = this_stretch_pos;
- this_stretch_pos = next_stretch_pos;
-
- prev_stretch = _stretch[BACK];
- prev_marker = _marker[BACK];
-
- if (next_stretch != _stretch[BACK])
- {
- _stretch[BACK]->remove_car(_car);
- ((Stretch *)next_stretch)->add_car(_car);
- }
-
- _stretch[BACK] = (Stretch *)next_stretch;
- _marker[BACK] = next_marker;
- _marker_offset[BACK] = 0.0; // XXX shouldn't need this
- // but am getting NaN's for some reason after running
- // for a long time
-
- next_stretch =
- _stretch[BACK]->get_next_stretch(_marker[BACK], next_marker);
-
- next_stretch_pos = next_stretch->road_pos(RIGHT,next_marker);
- }
-
- /*
- printf("offset after %f\n", offset);
- printf("marker after %d\n", _marker[BACK]);
- printf("marker_offset after %f\n", _marker_offset[BACK]);
- */
-
- // turn offset into parametric value where 0.0 would be
- // at previous marker, .5 at this marker and 1.0 at next
- // marker. The offset the program uses goes from 0.0
- // to 1.0 from this marker to the next marker only.
- float u = offset/2.0 + 0.5;
-
- // interpolate the back of the car along a quadratic bspline
- // whose control points are the middle of the right side of
- // the road at each marker
-
- // basis functions
- float b0 = bsbasis(2,0,u);
- float b1 = bsbasis(2,1,u);
- float b2 = bsbasis(2,2,u);
-
- _position[BACK] =
- b0*prev_stretch_pos +
- b1*this_stretch_pos +
- b2*next_stretch_pos;
-
- update_marker(BACK);
-
- /*
- printf("marker way after %d\n", _marker[BACK]);
- printf("marker_offset way after %f\n", _marker_offset[BACK]);
-
- printf("u %f\n", u);
- printf("basis %f %f %f, total %f\n",b0,b1,b2,b0+b1+b2);
-
- printf("a = "); print_vec(prev_stretch_pos);
- printf("b = "); print_vec(this_stretch_pos);
- printf("c = "); print_vec(next_stretch_pos);
- printf("back = "); print_vec(_position[BACK]);
- */
-
- // orient the car by interpolating the road directions
- // at the 3 markers using the same basis functions
- SbVec3f prev_stretch_dir =
- prev_stretch->get_direction(prev_marker, MIDDLE);
- SbVec3f this_stretch_dir =
- _stretch[BACK]->get_direction(_marker[BACK], MIDDLE);
- SbVec3f next_stretch_dir =
- next_stretch->get_direction(next_marker, MIDDLE);
- SbVec3f front_offset =
- b0*prev_stretch_dir +
- b1*this_stretch_dir +
- b2*next_stretch_dir;
-
- front_offset.normalize(); // make unit length
- front_offset *= _car->get_wheelbase();
-
- _position[FRONT] = _position[BACK] + front_offset;
- update_marker(FRONT);
-
- //printf("front = "); print_vec(_position[FRONT]);
-
-
- _center_position = (_position[FRONT] + _position[BACK])/2.0;
- }
-
-
- // computes car's orientation based on the front and back positions
- void Dynamics::compute_orientation()
- {
- SbVec3f forward = _position[FRONT] - _position[BACK];
-
- // compute only in ground plane
- forward[1] = 0.0;
-
- SbVec3f north(0.0,0.0,-1.0);
-
- // check cross product to determine orientation
- if (north.cross(forward)[1] < 0.0)
- _yaw = angle_between(north, forward);
- else
- _yaw = -angle_between(north, forward);
-
- compute_pitch_roll();
- }
-
-
-
- // updates the orientation of the car based on previous yaw and
- // new steering
- void Dynamics::update_orientation()
- {
- /// _yaw is in radians. 0.0 is pointing north (0,0,-1).
- /// negative yaw toward west, positive towards east
-
- // new radians of yaw, based on steering
- // XXX what's the 20.0 for?
- _yaw += 20.0*get_delta_yaw()/_car->get_simulation()->get_fps();
-
- if (_yaw >= 2.0*M_PI)
- _yaw -= 2.0*M_PI;
- else if (_yaw <= -2.0*M_PI)
- _yaw += 2.0*M_PI;
-
- compute_pitch_roll();
- }
-
-
- void Dynamics::compute_pitch_roll()
- {
- const SbVec3f up(0,1,0);
-
- // yaw is a rotation about the car's up vector
- SbRotation yaw_quat(up,_yaw);
- SbRotation minus_yaw_quat(up,-_yaw);
-
- // get normal representing pitch and roll based on position on road
- // this is a vector which is the 'normal' of the car
- _pitch_roll = get_pitch_roll();
-
- // Rotation used to move the car.
- // The rotation needed to get from up to pitch_roll.
- SbRotation motion_pitch_roll_quat(up, _pitch_roll);
- _motion_orientation = yaw_quat*motion_pitch_roll_quat;
-
- // Rotation used to set the view. The view is set by
- // rotating the world, so this from pitch_roll to up.
- SbRotation view_pitch_roll_quat(_pitch_roll, up);
- _view_orientation = view_pitch_roll_quat*yaw_quat;
-
- // this is used to set the eye position in world coords
- motion_pitch_roll_quat.getValue(_pitch_roll_mat);
- }
-
-
- void Dynamics::update_velocity()
- {
- float friction, gravity;
- float fps = _car->get_simulation()->get_fps();
-
- // update velocity based on rpms if not in neutral
- // dist/hour = engine-revs/min * 60min/hour *
- // axel-revs/engine-revs * dist/axel-rev
- if (_car->get_engine()->get_gear() != 0)
- {
- _velocity =
- (float)_car->get_engine()->get_rpm() * 60.0 *
- _car->get_engine()->get_ratio() *
- _car->get_engine()->get_tire_diam() *
- (1.0/_car->get_road()->get_distance_factor()) * M_PI;
- }
- else
- {
- // subtract tire friction
- friction = 2.0/fps;
- _velocity -= friction;
- }
-
- // effect of gravity
- float tilt = _position[BACK][1] - _position[FRONT][1];
- float incline = tilt/_car->get_wheelbase();
-
- // dist/hour = dist/s^2 * 60s/hour * s;
- gravity = 40.0*(_gravity/5280.0)*incline*60.0/fps;
- _velocity += gravity;
-
- // subtract braking
- // dist/hour = dist-lost/sec *
- _velocity -= _car->get_driver()->get_cockpit()->get_brakes();
-
- // Make offroad be like a swamp.
- // The longer off road, the more effect on
- // velocity and rpm.
- if (_off_road_left || _off_road_right)
- _velocity *= .92; // XXX Hard-coding a value. Tsk Tsk.
- }
-
-
- void Dynamics::update_brakes()
- {
- static float last_brakes = 0.0;
- float this_brakes = _car->get_driver()->get_cockpit()->get_brakes();
- Boolean brakes_applied = ((last_brakes == 0.0)&&(this_brakes == 1.0));
- Boolean brakes_released = ((last_brakes == 1.0)&&(this_brakes == 0.0));
- static Boolean screeching = FALSE;
-
- // XXX Ick. Need some _real_ dynamics.
- if ((_velocity > 40.0) && brakes_applied)
- {
- if (_car->get_simulation()->play_sound())
- {
- /*
- // XXX
- //something is amiss when using a second continuous audio process
- _screech->setContinuity(TRUE);
- _screech->play(1.0, _car->get_driver()->last_frame_time());
- */
- screeching = TRUE;
- }
- }
- else if (screeching &&
- ((_velocity < 40.0) || (brakes_released)))
- {
- // _screech->setContinuity(FALSE);
- screeching = FALSE;
- }
-
- if (screeching && _car->get_simulation()->play_sound())
- _screech->play(1.0, 125000);
-
- last_brakes = this_brakes;
- }
-
-
- // this is disgusting
- void Dynamics::check_collisions(SbVec3f offset)
- {
- SbVec3f obstacle;
- Boolean near_obstacle = FALSE;
-
- // yes, the position of the obstacles is hard-coded
- int c1 = _stretch[FRONT]->get_count()/3;
- int c2 = 2*_stretch[FRONT]->get_count()/3;
-
- if (_marker[FRONT] == 0)
- {
- obstacle = _stretch[FRONT]->get_pole_pos();
- near_obstacle = TRUE;
- }
- else if (_marker[FRONT] == c1)
- {
- obstacle = _stretch[FRONT]->get_tree1_pos();
- near_obstacle = TRUE;
- }
- else if (_marker[FRONT] == c2)
- {
- obstacle = _stretch[FRONT]->get_tree2_pos();
- near_obstacle = TRUE;
- }
-
-
- if (near_obstacle)
- {
- compute_side_positions();
-
- SbVec3f car_rect[4];
-
- car_rect[0] = _side_position[LEFT] - offset;
- car_rect[1] = _side_position[RIGHT] - offset;
- car_rect[2] = _side_position[RIGHT];
- car_rect[3] = _side_position[LEFT];
-
- if (point_within(car_rect,4,obstacle))
- {
- _car->get_driver()->crash();
- _velocity = 0.0;
- }
- }
- }
-
-
- // XXX DESPARATELY SEEKING REAL DYNAMICS
- void Dynamics::update()
- {
- SbVec3f offset;
-
- if (_car->get_type() == LOCAL_CAR)
- update_velocity();
- else
- _velocity = 80.0; // XXX for robot car
-
- // update orientation and position only if moving
- if (moving())
- {
- if (_car->get_type() == LOCAL_CAR)
- {
- offset = update_position();
- update_orientation();
- update_eye_position();
- update_brakes();
- check_collisions(offset);
- }
- else
- {
- update_robot_position();
- compute_orientation();
- }
- }
- else
- _velocity = 0.0;
- }
-
-