void SimCarConfig(tCar *car) { void *hdle = car->params; tdble k; tdble w; tdble gcfrl, gcrrl, gcfr; tdble wf0, wr0; tdble overallwidth; int i; tCarElt *carElt = car->carElt; car->dimension.x = GfParmGetNum(hdle, SECT_CAR, PRM_LEN, (char*)NULL, 4.7f); car->dimension.y = GfParmGetNum(hdle, SECT_CAR, PRM_WIDTH, (char*)NULL, 1.9f); overallwidth = GfParmGetNum(hdle, SECT_CAR, PRM_OVERALLWIDTH, (char*)NULL, car->dimension.y); car->dimension.z = GfParmGetNum(hdle, SECT_CAR, PRM_HEIGHT, (char*)NULL, 1.2f); car->mass = GfParmGetNum(hdle, SECT_CAR, PRM_MASS, (char*)NULL, 1500); car->Minv = (tdble) (1.0 / car->mass); gcfr = GfParmGetNum(hdle, SECT_CAR, PRM_FRWEIGHTREP, (char*)NULL, .5); gcfrl = GfParmGetNum(hdle, SECT_CAR, PRM_FRLWEIGHTREP, (char*)NULL, .5); gcrrl = GfParmGetNum(hdle, SECT_CAR, PRM_RRLWEIGHTREP, (char*)NULL, .5); car->statGC.y = (tdble) (- (gcfr * gcfrl + (1 - gcfr) * gcrrl) * car->dimension.y + car->dimension.y / 2.0); car->statGC.z = GfParmGetNum(hdle, SECT_CAR, PRM_GCHEIGHT, (char*)NULL, .5); car->tank = GfParmGetNum(hdle, SECT_CAR, PRM_TANK, (char*)NULL, 80); car->fuel = GfParmGetNum(hdle, SECT_CAR, PRM_FUEL, (char*)NULL, 80); k = GfParmGetNum(hdle, SECT_CAR, PRM_CENTR, (char*)NULL, 1.0); carElt->_drvPos_x = GfParmGetNum(hdle, SECT_DRIVER, PRM_XPOS, (char*)NULL, 0.0); carElt->_drvPos_y = GfParmGetNum(hdle, SECT_DRIVER, PRM_YPOS, (char*)NULL, 0.0); carElt->_drvPos_z = GfParmGetNum(hdle, SECT_DRIVER, PRM_ZPOS, (char*)NULL, 0.0); carElt->_bonnetPos_x = GfParmGetNum(hdle, SECT_BONNET, PRM_XPOS, (char*)NULL, carElt->_drvPos_x); carElt->_bonnetPos_y = GfParmGetNum(hdle, SECT_BONNET, PRM_YPOS, (char*)NULL, carElt->_drvPos_y); carElt->_bonnetPos_z = GfParmGetNum(hdle, SECT_BONNET, PRM_ZPOS, (char*)NULL, carElt->_drvPos_z); if (car->fuel > car->tank) { car->fuel = car->tank; } k = k * k; car->Iinv.x = (tdble) (12.0 / (car->mass * k * (car->dimension.y * car->dimension.y + car->dimension.z * car->dimension.z))); car->Iinv.y = (tdble) (12.0 / (car->mass * k * (car->dimension.x * car->dimension.x + car->dimension.z * car->dimension.z))); car->Iinv.z = (tdble) (12.0 / (car->mass * k * (car->dimension.y * car->dimension.y + car->dimension.x * car->dimension.x))); /* configure components */ w = car->mass * G; wf0 = w * gcfr; wr0 = w * (1 - gcfr); car->wheel[FRNT_RGT].weight0 = wf0 * gcfrl; car->wheel[FRNT_LFT].weight0 = wf0 * (1 - gcfrl); car->wheel[REAR_RGT].weight0 = wr0 * gcrrl; car->wheel[REAR_LFT].weight0 = wr0 * (1 - gcrrl); for (i = 0; i < 2; i++) { SimAxleConfig(car, i); } for (i = 0; i < 4; i++) { SimWheelConfig(car, i); } SimEngineConfig(car); SimTransmissionConfig(car); SimSteerConfig(car); SimBrakeSystemConfig(car); SimAeroConfig(car); for (i = 0; i < 2; i++) { SimWingConfig(car, i); } /* Set the origin to GC */ car->wheelbase = car->wheeltrack = 0; car->statGC.x = car->wheel[FRNT_RGT].staticPos.x * gcfr + car->wheel[REAR_RGT].staticPos.x * (1 - gcfr); carElt->_dimension = car->dimension; carElt->_statGC = car->statGC; carElt->_tank = car->tank; for (i = 0; i < 4; i++) { carElt->priv.wheel[i].relPos = car->wheel[i].relPos; } for (i = 0; i < 4; i++) { car->wheel[i].staticPos.x -= car->statGC.x; car->wheel[i].staticPos.y -= car->statGC.y; } car->wheelbase = (tdble) ((car->wheel[FRNT_RGT].staticPos.x + car->wheel[FRNT_LFT].staticPos.x - car->wheel[REAR_RGT].staticPos.x - car->wheel[REAR_LFT].staticPos.x) / 2.0); car->wheeltrack = (tdble) ((-car->wheel[REAR_LFT].staticPos.y - car->wheel[FRNT_LFT].staticPos.y + car->wheel[FRNT_RGT].staticPos.y + car->wheel[REAR_RGT].staticPos.y) / 2.0); /* set corners pos */ car->corner[FRNT_RGT].pos.x = (tdble) (car->dimension.x * .5 - car->statGC.x); car->corner[FRNT_RGT].pos.y = (tdble) (- overallwidth * .5 - car->statGC.y); car->corner[FRNT_RGT].pos.z = 0; car->corner[FRNT_LFT].pos.x = (tdble) (car->dimension.x * .5 - car->statGC.x); car->corner[FRNT_LFT].pos.y = (tdble) (overallwidth * .5 - car->statGC.y); car->corner[FRNT_LFT].pos.z = 0; car->corner[REAR_RGT].pos.x = (tdble) (- car->dimension.x * .5 - car->statGC.x); car->corner[REAR_RGT].pos.y = (tdble) (- overallwidth * .5 - car->statGC.y); car->corner[REAR_RGT].pos.z = 0; car->corner[REAR_LFT].pos.x = (tdble) (- car->dimension.x * .5 - car->statGC.x); car->corner[REAR_LFT].pos.y = (tdble) (overallwidth * .5 - car->statGC.y); car->corner[REAR_LFT].pos.z = 0; }
void SimCarConfig(tCar *car) { void *hdle = car->params; tdble k; tdble w; tdble gcfrl, gcrrl, gcfr; tdble wf0, wr0; tdble overallwidth; int i; tCarElt *carElt = car->carElt; car->options = new SimulationOptions; car->options->SetFromSkill (carElt->_skillLevel); car->options->LoadFromFile (hdle); car->fuel_time = 0.0; car->fuel_consumption = 0.0; car->carElt->_fuelTotal = 0.0; car->carElt->_fuelInstant = 10.0; car->carElt->priv.collision_state.collision_count = 0; for (i=0; i<3; i++) { car->carElt->priv.collision_state.pos[0] = 0.0; car->carElt->priv.collision_state.force[0] = 0.0; } car->dimension.x = GfParmGetNum(hdle, SECT_CAR, PRM_LEN, (char*)NULL, 4.7); car->dimension.y = GfParmGetNum(hdle, SECT_CAR, PRM_WIDTH, (char*)NULL, 1.9); overallwidth = GfParmGetNum(hdle, SECT_CAR, PRM_OVERALLWIDTH, (char*)NULL, car->dimension.y); car->dimension.z = GfParmGetNum(hdle, SECT_CAR, PRM_HEIGHT, (char*)NULL, 1.2); car->mass = GfParmGetNum(hdle, SECT_CAR, PRM_MASS, (char*)NULL, 1500); car->Minv = 1.0 / car->mass; gcfr = GfParmGetNum(hdle, SECT_CAR, PRM_FRWEIGHTREP, (char*)NULL, .5); gcfrl = GfParmGetNum(hdle, SECT_CAR, PRM_FRLWEIGHTREP, (char*)NULL, .5); gcrrl = GfParmGetNum(hdle, SECT_CAR, PRM_RRLWEIGHTREP, (char*)NULL, .5); car->statGC.y = - (gcfr * gcfrl + (1 - gcfr) * gcrrl) * car->dimension.y + car->dimension.y / 2.0; car->statGC.z = GfParmGetNum(hdle, SECT_CAR, PRM_GCHEIGHT, (char*)NULL, .5); car->tank = GfParmGetNum(hdle, SECT_CAR, PRM_TANK, (char*)NULL, 80); car->fuel = GfParmGetNum(hdle, SECT_CAR, PRM_FUEL, (char*)NULL, 80); k = GfParmGetNum(hdle, SECT_CAR, PRM_CENTR, (char*)NULL, 1.0); carElt->_drvPos_x = GfParmGetNum(hdle, SECT_DRIVER, PRM_XPOS, (char*)NULL, 0.0); carElt->_drvPos_y = GfParmGetNum(hdle, SECT_DRIVER, PRM_YPOS, (char*)NULL, 0.0); carElt->_drvPos_z = GfParmGetNum(hdle, SECT_DRIVER, PRM_ZPOS, (char*)NULL, 0.0); carElt->_bonnetPos_x = GfParmGetNum(hdle, SECT_BONNET, PRM_XPOS, (char*)NULL, carElt->_drvPos_x); carElt->_bonnetPos_y = GfParmGetNum(hdle, SECT_BONNET, PRM_YPOS, (char*)NULL, carElt->_drvPos_y); carElt->_bonnetPos_z = GfParmGetNum(hdle, SECT_BONNET, PRM_ZPOS, (char*)NULL, carElt->_drvPos_z); if (car->fuel > car->tank) { car->fuel = car->tank; } car->fuel_prev = car->fuel; k = k * k; car->Iinv.x = 12.0 / (car->mass * (car->dimension.y * car->dimension.y + k *car->dimension.z * car->dimension.z)); car->Iinv.y = 12.0 / (car->mass * (car->dimension.x * car->dimension.x + k * car->dimension.z * car->dimension.z)); car->Iinv.z = 12.0 / (car->mass * (car->dimension.y * car->dimension.y + k * car->dimension.x * car->dimension.x)); // initialise rotational momentum for (i=0; i<4; i++) { car->rot_mom[i] = 0.0; } car->rot_mom[SG_W] = 1.0; /* configure components */ w = car->mass * G; wf0 = w * gcfr; wr0 = w * (1 - gcfr); car->wheel[FRNT_RGT].weight0 = wf0 * gcfrl; car->wheel[FRNT_LFT].weight0 = wf0 * (1 - gcfrl); car->wheel[REAR_RGT].weight0 = wr0 * gcrrl; car->wheel[REAR_LFT].weight0 = wr0 * (1 - gcrrl); for (i = 0; i < 2; i++) { SimAxleConfig(car, i); } for (i = 0; i < 4; i++) { SimWheelConfig(car, i); } SimEngineConfig(car); SimTransmissionConfig(car); SimSteerConfig(car); SimBrakeSystemConfig(car); SimAeroConfig(car); for (i = 0; i < 2; i++) { SimWingConfig(car, i); } /* Set the origin to GC */ car->wheelbase = car->wheeltrack = 0; car->statGC.x = car->wheel[FRNT_RGT].staticPos.x * gcfr + car->wheel[REAR_RGT].staticPos.x * (1 - gcfr); carElt->_dimension = car->dimension; carElt->_statGC = car->statGC; carElt->_tank = car->tank; for (i = 0; i < 4; i++) { carElt->priv.wheel[i].relPos = car->wheel[i].relPos; } for (i = 0; i < 4; i++) { car->wheel[i].staticPos.x -= car->statGC.x; car->wheel[i].staticPos.y -= car->statGC.y; } car->wheelbase = (car->wheel[FRNT_RGT].staticPos.x + car->wheel[FRNT_LFT].staticPos.x - car->wheel[REAR_RGT].staticPos.x - car->wheel[REAR_LFT].staticPos.x) / 2.0; car->wheeltrack = (-car->wheel[REAR_LFT].staticPos.y - car->wheel[FRNT_LFT].staticPos.y + car->wheel[FRNT_RGT].staticPos.y + car->wheel[REAR_RGT].staticPos.y) / 2.0; /* set corners pos */ car->corner[FRNT_RGT].pos.x = car->dimension.x * .5 - car->statGC.x; car->corner[FRNT_RGT].pos.y = - overallwidth * .5 - car->statGC.y; car->corner[FRNT_RGT].pos.z = 0; car->corner[FRNT_LFT].pos.x = car->dimension.x * .5 - car->statGC.x; car->corner[FRNT_LFT].pos.y = overallwidth * .5 - car->statGC.y; car->corner[FRNT_LFT].pos.z = 0; car->corner[REAR_RGT].pos.x = - car->dimension.x * .5 - car->statGC.x; car->corner[REAR_RGT].pos.y = - overallwidth * .5 - car->statGC.y; car->corner[REAR_RGT].pos.z = 0; car->corner[REAR_LFT].pos.x = - car->dimension.x * .5 - car->statGC.x; car->corner[REAR_LFT].pos.y = overallwidth * .5 - car->statGC.y; car->corner[REAR_LFT].pos.z = 0; car->upside_down_timer = 0.0f; }
void SimCarConfig(tCar *car) { void *hdle = car->params; tdble k; tdble w; tdble gcfrl, gcrrl, gcfr; tdble wf0, wr0; tdble overallwidth; int i; tCarElt *carElt = car->carElt; const char *enabling; /* get features first */ car->features = 0; enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_AEROTOCG, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_AEROTOCG; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_SLOWGRIP, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_SLOWGRIP; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_REALGEARCHANGE, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_REALGEARCHANGE; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_REVLIMIT, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_REVLIMIT; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_TIRETEMPDEG, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_TIRETEMPDEG; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_FIXEDWHEELFORCE, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_FIXEDWHEELFORCE; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_TCLINSIMU, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_TCLINSIMU; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_ABSINSIMU, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_ABSINSIMU; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_ESPINSIMU, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_ESPINSIMU; } enabling = GfParmGetStr(hdle, SECT_FEATURES, PRM_LIMITEDGROUNDEFFECT, VAL_NO); if (strcmp(enabling, VAL_YES) == 0) { car->features = car->features | FEAT_LIMITEDGROUNDEFFECT; } /* continue with car parameters */ car->dimension.x = GfParmGetNum(hdle, SECT_CAR, PRM_LEN, (char*)NULL, 4.7f); car->dimension.y = GfParmGetNum(hdle, SECT_CAR, PRM_WIDTH, (char*)NULL, 1.9f); overallwidth = GfParmGetNum(hdle, SECT_CAR, PRM_OVERALLWIDTH, (char*)NULL, car->dimension.y); car->dimension.z = GfParmGetNum(hdle, SECT_CAR, PRM_HEIGHT, (char*)NULL, 1.2f); car->mass = GfParmGetNum(hdle, SECT_CAR, PRM_MASS, (char*)NULL, 1500); car->Minv = (tdble) (1.0 / car->mass); gcfr = GfParmGetNum(hdle, SECT_CAR, PRM_FRWEIGHTREP, (char*)NULL, .5); gcfrl = GfParmGetNum(hdle, SECT_CAR, PRM_FRLWEIGHTREP, (char*)NULL, .5); gcrrl = GfParmGetNum(hdle, SECT_CAR, PRM_RRLWEIGHTREP, (char*)NULL, .5); car->statGC.y = (tdble) (- (gcfr * gcfrl + (1 - gcfr) * gcrrl) * car->dimension.y + car->dimension.y / 2.0); car->statGC.z = GfParmGetNum(hdle, SECT_CAR, PRM_GCHEIGHT, (char*)NULL, .5); car->tank = GfParmGetNum(hdle, SECT_CAR, PRM_TANK, (char*)NULL, 80); car->fuel = GfParmGetNum(hdle, SECT_CAR, PRM_FUEL, (char*)NULL, 80); k = GfParmGetNum(hdle, SECT_CAR, PRM_CENTR, (char*)NULL, 1.0); carElt->_drvPos_x = GfParmGetNum(hdle, SECT_DRIVER, PRM_XPOS, (char*)NULL, 0.0); carElt->_drvPos_y = GfParmGetNum(hdle, SECT_DRIVER, PRM_YPOS, (char*)NULL, 0.0); carElt->_drvPos_z = GfParmGetNum(hdle, SECT_DRIVER, PRM_ZPOS, (char*)NULL, 0.0); carElt->_bonnetPos_x = GfParmGetNum(hdle, SECT_BONNET, PRM_XPOS, (char*)NULL, carElt->_drvPos_x); carElt->_bonnetPos_y = GfParmGetNum(hdle, SECT_BONNET, PRM_YPOS, (char*)NULL, carElt->_drvPos_y); carElt->_bonnetPos_z = GfParmGetNum(hdle, SECT_BONNET, PRM_ZPOS, (char*)NULL, carElt->_drvPos_z); if (car->fuel > car->tank) { car->fuel = car->tank; } k = k * k; car->Iinv.x = (tdble) (12.0 / (car->mass * k * (car->dimension.y * car->dimension.y + car->dimension.z * car->dimension.z))); car->Iinv.y = (tdble) (12.0 / (car->mass * k * (car->dimension.x * car->dimension.x + car->dimension.z * car->dimension.z))); car->Iinv.z = (tdble) (12.0 / (car->mass * k * (car->dimension.y * car->dimension.y + car->dimension.x * car->dimension.x))); /* configure components */ tdble K[4], Kfheave, Krheave; for (i = 0; i < 4; i++) { K[i] = GfParmGetNum(hdle, SuspSect[i], PRM_SPR, (char*)NULL, 175000.0f); } Kfheave = GfParmGetNum(hdle, SECT_FRNTHEAVE, PRM_SPR, (char*)NULL, 0.0f); Krheave = GfParmGetNum(hdle, SECT_REARHEAVE, PRM_SPR, (char*)NULL, 0.0f); /* wheel force bugfix is needed for heave springs */ if ( (Kfheave > 0.0f) || (Krheave > 0.0f) ) {car->features = car->features | FEAT_FIXEDWHEELFORCE;} w = car->mass * G; wf0 = w * gcfr; wr0 = w * (1 - gcfr); car->wheel[FRNT_RGT].weight0 = wf0 * gcfrl * K[FRNT_RGT] / (K[FRNT_RGT] + 0.5f*Kfheave); car->wheel[FRNT_LFT].weight0 = wf0 * (1 - gcfrl) * K[FRNT_LFT] / (K[FRNT_LFT] + 0.5f*Kfheave); car->wheel[REAR_RGT].weight0 = wr0 * gcrrl * K[REAR_RGT] / (K[REAR_RGT] + 0.5f*Krheave); car->wheel[REAR_LFT].weight0 = wr0 * (1 - gcrrl) * K[REAR_LFT] / (K[REAR_LFT] + 0.5f*Krheave); /*for (i = 0; i < 2; i++) { SimAxleConfig(car, i, 0.0); }*/ if (Kfheave > 0.0f) { wf0 = (wf0 - car->wheel[FRNT_RGT].weight0 - car->wheel[FRNT_LFT].weight0); SimAxleConfig(car, FRNT, wf0); } else { SimAxleConfig(car, FRNT, 0.0f); } if (Krheave > 0.0f) { wr0 = (wr0 - car->wheel[REAR_RGT].weight0 - car->wheel[REAR_LFT].weight0); SimAxleConfig(car, REAR, wr0); } else { SimAxleConfig(car, REAR, 0.0f); } for (i = 0; i < 4; i++) { SimWheelConfig(car, i); } SimEngineConfig(car); SimTransmissionConfig(car); SimSteerConfig(car); SimBrakeSystemConfig(car); SimAeroConfig(car); for (i = 0; i < 2; i++) { SimWingConfig(car, i); } /* Set the origin to GC */ car->wheelbase = car->wheeltrack = 0; car->statGC.x = car->wheel[FRNT_RGT].staticPos.x * gcfr + car->wheel[REAR_RGT].staticPos.x * (1 - gcfr); carElt->_dimension = car->dimension; carElt->_statGC = car->statGC; carElt->_tank = car->tank; for (i = 0; i < 4; i++) { carElt->priv.wheel[i].relPos = car->wheel[i].relPos; } for (i = 0; i < 4; i++) { car->wheel[i].staticPos.x -= car->statGC.x; car->wheel[i].staticPos.y -= car->statGC.y; } car->wheelbase = (tdble) ((car->wheel[FRNT_RGT].staticPos.x + car->wheel[FRNT_LFT].staticPos.x - car->wheel[REAR_RGT].staticPos.x - car->wheel[REAR_LFT].staticPos.x) / 2.0); car->wheeltrack = (tdble) ((-car->wheel[REAR_LFT].staticPos.y - car->wheel[FRNT_LFT].staticPos.y + car->wheel[FRNT_RGT].staticPos.y + car->wheel[REAR_RGT].staticPos.y) / 2.0); /* set corners pos */ car->corner[FRNT_RGT].pos.x = (tdble) (car->dimension.x * .5 - car->statGC.x); car->corner[FRNT_RGT].pos.y = (tdble) (- overallwidth * .5 - car->statGC.y); car->corner[FRNT_RGT].pos.z = 0; car->corner[FRNT_LFT].pos.x = (tdble) (car->dimension.x * .5 - car->statGC.x); car->corner[FRNT_LFT].pos.y = (tdble) (overallwidth * .5 - car->statGC.y); car->corner[FRNT_LFT].pos.z = 0; car->corner[REAR_RGT].pos.x = (tdble) (- car->dimension.x * .5 - car->statGC.x); car->corner[REAR_RGT].pos.y = (tdble) (- overallwidth * .5 - car->statGC.y); car->corner[REAR_RGT].pos.z = 0; car->corner[REAR_LFT].pos.x = (tdble) (- car->dimension.x * .5 - car->statGC.x); car->corner[REAR_LFT].pos.y = (tdble) (overallwidth * .5 - car->statGC.y); car->corner[REAR_LFT].pos.z = 0; /* set wing positions */ if (car->features & FEAT_AEROTOCG) { for (i = 0; i < 2; i++) { car->wing[i].staticPos.x -= car->statGC.x; car->wing[i].staticPos.y -= car->statGC.y; car->wing[i].staticPos.z -= car->statGC.z; } } }