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.
- */
- //////////////////////////////////////////////////////////////////////
- // Stretch.h - definition of the stretch abstract class
- //
- // A road is a doubly-linked list of stretches. Each stretch
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //////////////////////////////////////////////////////////////////////
-
- #ifndef STRETCH_H
- #define STRETCH_H
-
- #include "Defines.h"
- #include <Inventor/SbPList.h>
-
- class Car;
-
- // stretch types
- #define STRAIGHT 1
- #define CURVE 2
- #define LOOP 3
- #define CONNECT 4
-
- // positions across a stretch
- // XXX ordered such because Dynamics do not use middle for flag representation
- #define LEFT 0
- #define RIGHT 1
- #define MIDDLE 2
-
- // stripe size relative to road
- const float STRIPE_WIDTH = .02;
- const float STRIPE_HEIGHT = .05;
-
- // terrain = terrain_width * .5*road_width
- #define TERRAIN_WIDTH 10.0
-
- // offset from side of road for trees & poles
- #define SCENERY_OFFSET 5.0;
-
- typedef struct {
- SbVec3f normal;
- SbVec3f left;
- SbVec3f middle;
- SbVec3f right;
- } StretchData;
-
-
- class Stretch {
-
- public:
-
- Stretch(Stretch *prev, Stretch *next);
-
- virtual ~Stretch();
-
- // draws all "visible" stretches, starting with this one
- // at the given marker.
- // display_mode is RENDER_FILLED or RENDER_WIREFRAME
- // ignore_car is a car _not_ to draw, usually the local car
- // when viewing from inside the car
- void draw(int start_marker, int display_mode, Car *ignore_car) const;
-
- // call this before calling draw
- void init_draw() const { _drawn = 0; };
-
- const Stretch * get_next() const { return _next; };
- const Stretch * get_prev() const { return _prev; };
-
- float get_turn_angle() { return _turn_angle; };
- float get_hill_angle() { return _hill_angle; };
- float get_step() const { return _step; };
- float get_length() const { return _length; };
- float get_width() const { return _width; };
-
- const SbVec3f get_left(int i) const { return _data[i].left; };
- const SbVec3f get_middle(int i) const { return _data[i].middle; };
- const SbVec3f get_right(int i) const { return _data[i].right; };
- const SbVec3f get_normal(int i) const { return _data[i].normal; };
- int get_count() const { return _num_markers; };
-
- const SbVec3f get_left_median(int i) const
- { return _median_data[i].left; };
- const SbVec3f get_right_median(int i) const
- { return _median_data[i].right; };
- const StretchData get_left_terrain(int i) const
- { return _left_terrain_data[i]; };
- const StretchData get_right_terrain(int i) const
- { return _right_terrain_data[i]; };
-
- const Stretch * get_next_stretch(int marker, int &next_marker) const;
- const Stretch * get_prev_stretch(int marker, int &prev_marker) const;
- const SbVec3f get_direction(int marker, int side) const;
- const SbVec3f get_side_direction(int marker, int side) const;
-
- // for this stretch, at current marker, returns the marker offset
- // for position in the range of 0.0-1.0. If the position is on
- // the next marker, returns TRUE; returns FALSE if on this marker.
- // 0.0 means at the beginning of the segment, 1.0 at the end.
- // XXX had to do *offset instead of &offset. Was getting NaN's.
- virtual Boolean get_marker_offset(
- int marker, const SbVec3f position, float *offset);
-
- // Returns the middle of the LEFT or RIGHT side of the
- // road at the given marker
- SbVec3f road_pos(int side, int marker) const;
-
- // Add or remove a car to the list of cars on this stretch
- void add_car(const Car *car) {
- _car_list->append((void *)car);
- };
- void remove_car(const Car *car) {
- int i = _car_list->find((void *)car);
- if (i == -1)
- fprintf(stderr,"Attempt to remove non-existant car %x\n",car);
- else
- _car_list->remove(i);
- };
-
- // XXX Do not panic. These are only temporary until the creation
- // of a genuine Scenery class.
- const SbVec3f get_pole_pos() const {return _pole_pos;};
- const SbVec3f get_tree1_pos() const {return _tree1_pos;};
- const SbVec3f get_tree2_pos() const {return _tree2_pos;};
-
- protected:
-
- /// protected data members
-
- Stretch * _prev;
- Stretch * _next;
-
- int _type; // type of the stretch
-
- // all these values are in world units, i.e. feet or meters
- float _width;
- float _length;
- float _step; // polygon step, in world units
-
- float _turn_angle; // radians, positive curves left
- float _turn_radius;
-
- float _hill_angle; // radians, positive curves up
- float _hill_radius;
-
- float _bank_angle; // radians, positive tilts to left, start to end
-
- // offset from origin to end of road;
- SbVec3f _offset;
-
- // change in pitch/roll from origin to end of road
- SbRotation _orientation;
-
- static int _drawn; // depth in the rendering recursion
- static int _ahead; // how many stretches to draw ahead of current
-
- StretchData * _data;
- StretchData * _median_data;
- StretchData * _left_terrain_data;
- StretchData * _right_terrain_data;
-
- int _num_markers; // number of vertices down one edge of stretch
- int _num_stripes; // number of median stripes
-
- // The stretch is in charge of drawing cars that are on it.
- // This is a list of cars on this stretch.
- SbPList * _car_list;
-
- // XXX scenery hacks until we get a real scenery class
- SbVec3f _pole_pos;
- SbVec3f _tree1_pos;
- SbVec3f _tree2_pos;
-
- // protected member functions
-
- void set_next(Stretch *s) { _next = s; };
- void set_prev(Stretch *s) { _prev = s; };
-
- void init_scenery();
- void draw_scenery(int display_mode) const;
- void draw_terrain(int start_marker, int display_mode) const;
- void draw_asphalt(int start_marker, int display_mode) const;
- void draw_stripes(int start_marker, int display_mode) const;
- void draw_cars(Car *ignore_car, int display_mode) const;
- // draws cars on this stretch
-
- const SbVec3f get_offset() const { return _offset; };
- const SbRotation get_orientation() const { return _orientation; };
- void rotate_bank(int i, float bank);
- void compute_step();
- void allocate_data();
- void find_previous(SbVec3f &prev_offset, SbRotation &prev_orientation);
- void match_ends();
- void transform_data(SbVec3f prev_offset, SbRotation prev_orientation);
- };
-
- #endif
-
-