virtual void operator()(const osg::Camera& cam) const { SDCars * cars = (SDCars *)getCars(); cars->activateCar(car); }
void Road::advanceCars(){ int no_of_cars = getNoOfCars(); int speed; if(no_of_cars != 0){ speed = (ceil((getLength())/no_of_cars)); std::vector<Car*> cars = getCars(); int i = 0, j = 0; if(cars.size() > 0){ i = cars.size()-1; j = cars.size()-1; } double decreaseSpeed = 1; while(i >= 0){ Car* car = cars[i]; if(car->isFault()){ car->decreaseFaultyTime(); int location = car->getLocation(); j = --i; int count = 1; // count how many cars there are in the same location with fault car. while(((unsigned int)j < cars.size()) && ((cars[j])->getLocation()) == location){ Car* same_location_car = cars[j]; if(!same_location_car->isFault()){ same_location_car->setSpeed(ceil(speed*decreaseSpeed),_simulator->getMaxSpeed()); same_location_car->driveCar(getLength()); }else{ same_location_car->decreaseFaultyTime(); count++; } j--; } i = j; decreaseSpeed *= pow(0.5,count); }else{ car->setSpeed(ceil(speed*decreaseSpeed),_simulator->getMaxSpeed()); car->driveCar(getLength()); i--; } } } std::stable_sort(getCars().begin(),getCars().end(),CompareCarByLocation()); }
int main() { Car c[3]; int i=0; for(i=0; i<3; i++) getCars(&c[i]); printCars(&c[0],3); return 0; }
void SDScreens::update(tSituation * s,SDFrameInfo* fi) { for (unsigned i=0;i< Screens.size();i++) { Screens[i]->update(s,fi); } SDCars * cars = (SDCars *)getCars(); tCarElt * c = this->getActiveView()->getCurrentCar(); this->debugHUD->setTexture(cars->getCar(c)->getReflectionMap()->getReflectionMap()); if (!viewer->done()) viewer->frame(); }
virtual void operator()(const osg::Camera& cam) const { SDCars * cars = (SDCars*)getCars(); osg::Matrixf mat = cam.getViewMatrix(); cars->updateShadingParameters(mat); }