/** * Update the animation. This method will be called by the * scenegraph rendering function just before the animated * branch will be rendered. */ int CRRCControlSurfaceAnimation::update() { // calculate the deflection angle by summing up the contribution // of all mapped control inputs times the individual gain float angle = 0.0f; for (int i = 0; i < (int)datasource.size(); i++) { angle += *datasource[i] * source_gain[i] * max_angle; } // limit to max_angle (caution: max_angle could be < 0.0, so we use the abs value!) if (angle > abs_max_angle) { angle = abs_max_angle; } else if (angle < -abs_max_angle) { angle = -abs_max_angle; } // calculate transformation matrix for surface rotation sgQuat q; sgMat4 qmat; sgAngleAxisToQuat(q, angle, axis); sgQuatToMatrix(qmat, q); sgMultMat4(current_transformation, qmat, move_to_origin); sgPostMultMat4(current_transformation, move_back); ((ssgTransform*)anim_branch)->setTransform(current_transformation); return 1; }
/* Initial configuration */ void SimConfig(tCarElt *carElt, tRmInfo* ReInfo) { tCar *car = &(SimCarTable[carElt->index]); memset(car, 0, sizeof(tCar)); car->carElt = carElt; car->DynGCg = car->DynGC = carElt->_DynGC; car->trkPos = carElt->_trkPos; car->ctrl = &carElt->ctrl; car->params = carElt->_carHandle; car->ReInfo = ReInfo; SimCarConfig(car); SimCarCollideConfig(car); sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z, RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); sgEulerToQuat (car->posQuat, -RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_pitch), RAD2DEG(carElt->_roll)); sgQuatToMatrix (car->posMat, car->posQuat); simu_total_time = 0.0f; simu_init_time = GfTimeClock(); //sgMakeRotMat4 (car->posMat, RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); }
/** * Initialize a CRRCControlSurfaceAnimation object */ void CRRCControlSurfaceAnimation::realInit() { sgQuat q; sgAngleAxisToQuat(q, 0.0f, axis); sgQuatToMatrix(current_transformation, q); ((ssgTransform*)anim_branch)->setTransform(current_transformation); }
void SimUpdate(tSituation *s, double deltaTime, int telemetry) { int i; int ncar; tCarElt *carElt; tCar *car; sgVec3 P; static const float UPSIDE_DOWN_TIMEOUT = 5.0f; double timestamp_start = GfTimeClock(); SimDeltaTime = deltaTime; SimTelemetry = 0;//telemetry; for (ncar = 0; ncar < s->_ncars; ncar++) { SimCarTable[ncar].collision = 0; SimCarTable[ncar].blocked = 0; } for (ncar = 0; ncar < s->_ncars; ncar++) { car = &(SimCarTable[ncar]); carElt = car->carElt; if (carElt->_state & RM_CAR_STATE_NO_SIMU) { RemoveCar(car, s); continue; } else if (((s->_maxDammage) && (car->dammage > s->_maxDammage)) || (car->fuel == 0) || (car->upside_down_timer > UPSIDE_DOWN_TIMEOUT) || (car->carElt->_state & RM_CAR_STATE_ELIMINATED)) { RemoveCar(car, s); if (carElt->_state & RM_CAR_STATE_NO_SIMU) { continue; } } if (s->_raceState & RM_RACE_PRESTART) { car->ctrl->gear = 0; } CHECK(car); ctrlCheck(car); CHECK(car); SimSteerUpdate(car); CHECK(car); SimGearboxUpdate(car); CHECK(car); SimEngineUpdateTq(car); CHECK(car); if (!(s->_raceState & RM_RACE_PRESTART)) { SimCarUpdateWheelPos(car); CHECK(car); SimBrakeSystemUpdate(car); CHECK(car); SimAeroUpdate(car, s); CHECK(car); for (i = 0; i < 2; i++){ SimWingUpdate(car, i, s); } CHECK(car); for (i = 0; i < 4; i++){ SimWheelUpdateRide(car, i); } CHECK(car); for (i = 0; i < 2; i++){ SimAxleUpdate(car, i); } CHECK(car); for (i = 0; i < 4; i++){ SimWheelUpdateForce(car, i); } CHECK(car); } SimTransmissionUpdate(car); CHECK(car); if (!(s->_raceState & RM_RACE_PRESTART)) { SimWheelUpdateRotation(car); CHECK(car); SimCarUpdate(car, s); CHECK(car); } } SimCarCollideCars(s); /* printf ("%f - ", s->currentTime); */ for (ncar = 0; ncar < s->_ncars; ncar++) { car = &(SimCarTable[ncar]); CHECK(car); carElt = car->carElt; if (carElt->_state & RM_CAR_STATE_NO_SIMU) { continue; } CHECK(car); SimCarUpdate2(car, s); /* copy back the data to carElt */ carElt->pub.DynGC = car->DynGC; carElt->pub.DynGCg = car->DynGCg; #if 0 sgMakeCoordMat4(carElt->pub.posMat, carElt->_pos_X, carElt->_pos_Y, carElt->_pos_Z - carElt->_statGC_z, RAD2DEG(carElt->_yaw), RAD2DEG(carElt->_roll), RAD2DEG(carElt->_pitch)); #else sgQuatToMatrix (carElt->pub.posMat, car->posQuat); carElt->pub.posMat[3][0] = car->DynGCg.pos.x; carElt->pub.posMat[3][1] = car->DynGCg.pos.y; carElt->pub.posMat[3][2] = car->DynGCg.pos.z - carElt->_statGC_z; carElt->pub.posMat[0][3] = SG_ZERO ; carElt->pub.posMat[1][3] = SG_ZERO ; carElt->pub.posMat[2][3] = SG_ZERO ; carElt->pub.posMat[3][3] = SG_ONE ; #endif carElt->_trkPos = car->trkPos; for (i = 0; i < 4; i++) { carElt->priv.wheel[i].relPos = car->wheel[i].relPos; carElt->_wheelSeg(i) = car->wheel[i].trkPos.seg; carElt->_brakeTemp(i) = car->wheel[i].brake.temp; carElt->pub.corner[i] = car->corner[i].pos; } carElt->_gear = car->transmission.gearbox.gear; carElt->_enginerpm = car->engine.rads; carElt->_fuel = car->fuel; carElt->priv.collision |= car->collision; carElt->_dammage = car->dammage; P[0] = -carElt->_statGC_x; P[1] = -carElt->_statGC_y; P[2] = -carElt->_statGC_z; sgXformPnt3(P, carElt->_posMat); carElt->_pos_X = P[0]; carElt->_pos_Y = P[1]; carElt->_pos_Z = P[2]; } simu_total_time += GfTimeClock() - timestamp_start; }