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.
- */
- //////////////////////////////////////////////////////////////////////
- // Car.c++ - implementationtion of the car class
- //////////////////////////////////////////////////////////////////////
-
- #include <Inventor/Sb.h>
- #include <Inventor/nodes/SoDrawStyle.h>
- #include <Inventor/nodes/SoSeparator.h>
- #include <Inventor/actions/SoGLRenderAction.h>
- #include "Car.h"
- #include "Engine.h"
- #include "Dynamics.h"
- #include "Driver.h"
- #include "Road.h"
- #include "Stretch.h"
- #include "Render.h"
- extern "C" {
- #include "shapes.h"
- }
- #include "so.h"
-
-
- // Pointer to the driver that is on this workstaion
- Driver * Car::_local_driver = NULL;
-
-
- Car::Car(Simulation *sim, SbString carfile, Road *r, int type)
- {
- // set up the car as a Inventor graph
- _car_root = new SoSeparator;
- _car_root->ref();
-
- _style = new SoDrawStyle;
- _style->style = SoDrawStyle::FILLED;
-
- // read in the car database
- _car_body = readSceneGraph(carfile.getString());
-
- _car_root->addChild(_style);
- _car_root->addChild(_car_body);
-
- // simulation that this car is in
- _simulation = sim;
-
- // physical information about the car
- // XXX extract from car custom node
- _wheelbase = 35.0/2.0;
- _width = 15.0/2.0;
- _height = 11.0/2.0;
-
- // driver position relative to center of car
- _driver_position.setValue(-1.5,4.0,0.0);
-
- // road that this car is on
- _road = r;
-
- _type = type;
-
- /// components of the car
-
- // only local cars have a driver
- if (_type == LOCAL_CAR)
- // keep driver construction first
- _local_driver = _driver = new Driver(this);
- else
- _driver = NULL;
-
- _engine = new Engine(this);
- _dynamics = new Dynamics(this);
-
- _render_action = new SoGLRenderAction(
- SbVec2s(10,10), // dummy for now
- TRUE); // XXX do inherit GL state
-
- if (_type == LOCAL_CAR)
- {
- _material = RED_METAL;
- _color = 0xFF;
- }
- else if (_type == ROBOT_CAR)
- {
- _material = GREY_METAL;
- _color = 0x7f7f7f;
- }
- // XXX else if (_type == NETWORK_CAR)
- // _color = retrieve from network
- }
-
-
- Car::~Car()
- {
- if (_driver) delete _driver;
- delete _engine;
- delete _dynamics;
- delete _render_action;
- }
-
-
- void Car::update(Boolean ok_to_sleep)
- {
- switch (_type)
- {
- case LOCAL_CAR:
- _driver->update(ok_to_sleep);
- break;
- case ROBOT_CAR:
- _dynamics->update();
- break;
- }
- }
-
-
- void Car::setDrawStyle(int mode)
- {
- if (mode == RENDER_FILLED)
- _style->style = SoDrawStyle::FILLED;
- else
- _style->style = SoDrawStyle::LINES;
- }
-
-
- void Car::draw(int mode)
- {
- Boolean backface_state;
-
- if (mode == RENDER_FILLED)
- {
- backface_state = getbackface();
- static Boolean first_time = TRUE;
-
- backface(TRUE);
- lmbind(MATERIAL, _material);
- }
- else
- cpack(_color);
-
- if (_local_driver) {
- _render_action->setWindowSize(_local_driver->getViewWindowSize());
- _render_action->apply(_car_root);
- }
-
- if (mode == RENDER_FILLED)
- {
- backface(backface_state);
- lmbind(MATERIAL, 0);
- }
- }
-
-