mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Merge pull request #5695 from acemod/ab-vanilla-drag-removal-fix
Advanced Ballistics - Fixes bug in the vanilla drag removal routine
This commit is contained in:
commit
ef0c2788d3
Binary file not shown.
Binary file not shown.
@ -112,7 +112,7 @@ if (_caliber > 0 && _bulletLength > 0 && _bulletMass > 0 && _barrelTwist > 0) th
|
||||
|
||||
GVAR(currentbulletID) = (GVAR(currentbulletID) + 1) % 10000;
|
||||
|
||||
"ace_advanced_ballistics" callExtension format["new:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:%17", GVAR(currentbulletID), _airFriction, _ballisticCoefficients, _velocityBoundaries, _atmosphereModel, _dragModel, _stabilityFactor, _twistDirection, _muzzleVelocity, _transonicStabilityCoef, getPosASL _projectile, EGVAR(common,mapLatitude), EGVAR(weather,currentTemperature), EGVAR(common,mapAltitude), EGVAR(weather,currentHumidity), EGVAR(weather,currentOvercast), CBA_missionTime toFixed 6];
|
||||
"ace_advanced_ballistics" callExtension format["new:%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12:%13:%14:%15:%16:%17", GVAR(currentbulletID), _airFriction, _ballisticCoefficients, _velocityBoundaries, _atmosphereModel, _dragModel, _stabilityFactor, _twistDirection, _transonicStabilityCoef, getPosASL _projectile, _bulletVelocity, EGVAR(common,mapLatitude), EGVAR(weather,currentTemperature), EGVAR(common,mapAltitude), EGVAR(weather,currentHumidity), EGVAR(weather,currentOvercast), CBA_missionTime toFixed 6];
|
||||
|
||||
GVAR(allBullets) pushBack [_projectile, _caliber, _bulletTraceVisible, GVAR(currentbulletID)];
|
||||
|
||||
|
@ -39,8 +39,7 @@ struct Bullet {
|
||||
double stabilityFactor;
|
||||
double twistDirection;
|
||||
double transonicStabilityCoef;
|
||||
double muzzleVelocity;
|
||||
double bulletSpeed;
|
||||
std::vector<double> bulletVelocity;
|
||||
std::vector<double> origin;
|
||||
double latitude;
|
||||
double temperature;
|
||||
@ -335,7 +334,9 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
double stabilityFactor = 1.5;
|
||||
int twistDirection = 1;
|
||||
double transonicStabilityCoef = 1;
|
||||
double muzzleVelocity = 850;
|
||||
char* bulletVelocityArray;
|
||||
char* bulletVelocityEntry;
|
||||
std::vector<double> bulletVelocity;
|
||||
char* originArray;
|
||||
char* originEntry;
|
||||
std::vector<double> origin;
|
||||
@ -368,7 +369,6 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
dragModel = strtol(strtok_s(NULL, ":", &next_token), NULL, 10);
|
||||
stabilityFactor = strtod(strtok_s(NULL, ":", &next_token), NULL);
|
||||
twistDirection = strtol(strtok_s(NULL, ":", &next_token), NULL, 10);
|
||||
muzzleVelocity = strtod(strtok_s(NULL, ":", &next_token), NULL);
|
||||
transonicStabilityCoef = strtod(strtok_s(NULL, ":", &next_token), NULL);
|
||||
originArray = strtok_s(NULL, ":", &next_token);
|
||||
originArray++;
|
||||
@ -378,6 +378,14 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
origin.push_back(strtod(originEntry, NULL));
|
||||
originEntry = strtok_s(NULL, ",", &token);
|
||||
}
|
||||
bulletVelocityArray = strtok_s(NULL, ":", &next_token);
|
||||
bulletVelocityArray++;
|
||||
bulletVelocityArray[strlen(bulletVelocityArray) - 1] = 0;
|
||||
bulletVelocityEntry = strtok_s(bulletVelocityArray, ",", &token);
|
||||
while (bulletVelocityEntry != NULL) {
|
||||
bulletVelocity.push_back(strtod(bulletVelocityEntry, NULL));
|
||||
bulletVelocityEntry = strtok_s(NULL, ",", &token);
|
||||
}
|
||||
latitude = strtod(strtok_s(NULL, ":", &next_token), NULL);
|
||||
temperature = strtod(strtok_s(NULL, ":", &next_token), NULL);
|
||||
altitude = strtod(strtok_s(NULL, ":", &next_token), NULL);
|
||||
@ -398,8 +406,7 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
bulletDatabase[index].stabilityFactor = stabilityFactor;
|
||||
bulletDatabase[index].twistDirection = twistDirection;
|
||||
bulletDatabase[index].transonicStabilityCoef = transonicStabilityCoef;
|
||||
bulletDatabase[index].muzzleVelocity = muzzleVelocity;
|
||||
bulletDatabase[index].bulletSpeed = muzzleVelocity;
|
||||
bulletDatabase[index].bulletVelocity = bulletVelocity;
|
||||
bulletDatabase[index].origin = origin;
|
||||
bulletDatabase[index].latitude = latitude / 180 * M_PI;
|
||||
bulletDatabase[index].temperature = temperature;
|
||||
@ -477,6 +484,7 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
double windSpeed = 0.0;
|
||||
double windAttenuation = 1.0;
|
||||
double velocityOffset[3] = { 0.0, 0.0, 0.0 };
|
||||
double bulletSpeed = sqrt(pow(bulletDatabase[index].bulletVelocity[0], 2) + pow(bulletDatabase[index].bulletVelocity[1], 2) + pow(bulletDatabase[index].bulletVelocity[2], 2));
|
||||
|
||||
bulletDatabase[index].lastFrame = tickTime;
|
||||
|
||||
@ -522,9 +530,9 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
windSpeed = sqrt(pow(wind[0], 2) + pow(wind[1], 2) + pow(wind[2], 2));
|
||||
}
|
||||
|
||||
trueVelocity[0] = velocity[0] - wind[0];
|
||||
trueVelocity[1] = velocity[1] - wind[1];
|
||||
trueVelocity[2] = velocity[2] - wind[2];
|
||||
trueVelocity[0] = bulletDatabase[index].bulletVelocity[0] - wind[0];
|
||||
trueVelocity[1] = bulletDatabase[index].bulletVelocity[1] - wind[1];
|
||||
trueVelocity[2] = bulletDatabase[index].bulletVelocity[2] - wind[2];
|
||||
trueSpeed = sqrt(pow(trueVelocity[0], 2) + pow(trueVelocity[1], 2) + pow(trueVelocity[2], 2));
|
||||
|
||||
if (bulletDatabase[index].transonicStabilityCoef < 1.0f && trueSpeed - 60 < SPEED_OF_SOUND(temperature) && trueSpeed > SPEED_OF_SOUND(temperature)) {
|
||||
@ -543,17 +551,17 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
bulletDatabase[index].bcDegradation *= pow(0.993, coef);
|
||||
};
|
||||
|
||||
dragRef = -bulletDatabase[index].airFriction * bulletSpeed * bulletSpeed;
|
||||
|
||||
accelRef[0] = (bulletDatabase[index].bulletVelocity[0] / bulletSpeed) * dragRef;
|
||||
accelRef[1] = (bulletDatabase[index].bulletVelocity[1] / bulletSpeed) * dragRef;
|
||||
accelRef[2] = (bulletDatabase[index].bulletVelocity[2] / bulletSpeed) * dragRef;
|
||||
|
||||
velocityOffset[0] += accelRef[0] * deltaT;
|
||||
velocityOffset[1] += accelRef[1] * deltaT;
|
||||
velocityOffset[2] += accelRef[2] * deltaT;
|
||||
|
||||
if (bulletDatabase[index].ballisticCoefficients.size() == bulletDatabase[index].velocityBoundaries.size() + 1) {
|
||||
dragRef = deltaT * bulletDatabase[index].airFriction * bulletDatabase[index].bulletSpeed * bulletDatabase[index].bulletSpeed;
|
||||
|
||||
accelRef[0] = (velocity[0] / bulletDatabase[index].bulletSpeed) * dragRef;
|
||||
accelRef[1] = (velocity[1] / bulletDatabase[index].bulletSpeed) * dragRef;
|
||||
accelRef[2] = (velocity[2] / bulletDatabase[index].bulletSpeed) * dragRef;
|
||||
|
||||
velocityOffset[0] -= accelRef[0];
|
||||
velocityOffset[1] -= accelRef[1];
|
||||
velocityOffset[2] -= accelRef[2];
|
||||
|
||||
ballisticCoefficient = bulletDatabase[index].ballisticCoefficients[0];
|
||||
for (int i = (int)bulletDatabase[index].velocityBoundaries.size() - 1; i >= 0; i = i - 1) {
|
||||
if (trueSpeed < bulletDatabase[index].velocityBoundaries[i]) {
|
||||
@ -564,62 +572,44 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function)
|
||||
|
||||
ballisticCoefficient = calculateAtmosphericCorrection(ballisticCoefficient, temperature, pressure, bulletDatabase[index].humidity, bulletDatabase[index].atmosphereModel);
|
||||
ballisticCoefficient *= bulletDatabase[index].bcDegradation;
|
||||
drag = deltaT * calculateRetard(bulletDatabase[index].dragModel, ballisticCoefficient, trueSpeed, SPEED_OF_SOUND(temperature));
|
||||
accel[0] = (trueVelocity[0] / trueSpeed) * drag;
|
||||
accel[1] = (trueVelocity[1] / trueSpeed) * drag;
|
||||
accel[2] = (trueVelocity[2] / trueSpeed) * drag;
|
||||
|
||||
velocityOffset[0] -= accel[0];
|
||||
velocityOffset[1] -= accel[1];
|
||||
velocityOffset[2] -= accel[2];
|
||||
drag = calculateRetard(bulletDatabase[index].dragModel, ballisticCoefficient, trueSpeed, SPEED_OF_SOUND(temperature));
|
||||
} else {
|
||||
double airDensity = calculateAirDensity(temperature, pressure, bulletDatabase[index].humidity);
|
||||
double airFriction = bulletDatabase[index].airFriction * airDensity / STD_AIR_DENSITY_ICAO;
|
||||
|
||||
if (airFriction != bulletDatabase[index].airFriction || windSpeed > 0) {
|
||||
dragRef = deltaT * bulletDatabase[index].airFriction * bulletDatabase[index].bulletSpeed * bulletDatabase[index].bulletSpeed;
|
||||
|
||||
accelRef[0] = (velocity[0] / bulletDatabase[index].bulletSpeed) * dragRef;
|
||||
accelRef[1] = (velocity[1] / bulletDatabase[index].bulletSpeed) * dragRef;
|
||||
accelRef[2] = (velocity[2] / bulletDatabase[index].bulletSpeed) * dragRef;
|
||||
|
||||
velocityOffset[0] -= accelRef[0];
|
||||
velocityOffset[1] -= accelRef[1];
|
||||
velocityOffset[2] -= accelRef[2];
|
||||
|
||||
drag = deltaT * airFriction * trueSpeed * trueSpeed;
|
||||
accel[0] = (trueVelocity[0] / trueSpeed) * drag;
|
||||
accel[1] = (trueVelocity[1] / trueSpeed) * drag;
|
||||
accel[2] = (trueVelocity[2] / trueSpeed) * drag;
|
||||
|
||||
velocityOffset[0] += accel[0];
|
||||
velocityOffset[1] += accel[1];
|
||||
velocityOffset[2] += accel[2];
|
||||
}
|
||||
drag = -airFriction * trueSpeed * trueSpeed;
|
||||
}
|
||||
|
||||
accel[0] = (trueVelocity[0] / trueSpeed) * drag;
|
||||
accel[1] = (trueVelocity[1] / trueSpeed) * drag;
|
||||
accel[2] = (trueVelocity[2] / trueSpeed) * drag;
|
||||
|
||||
velocityOffset[0] -= accel[0] * deltaT;
|
||||
velocityOffset[1] -= accel[1] * deltaT;
|
||||
velocityOffset[2] -= accel[2] * deltaT;
|
||||
|
||||
if (TOF > 0) {
|
||||
double bulletDir = atan2(velocity[0], velocity[1]);
|
||||
double bulletDir = atan2(bulletDatabase[index].bulletVelocity[0], bulletDatabase[index].bulletVelocity[1]);
|
||||
double driftAccel = bulletDatabase[index].twistDirection * (0.0482251 * (bulletDatabase[index].stabilityFactor + 1.2)) / pow(TOF, 0.17);
|
||||
double driftVelocity = 0.0581025 *(bulletDatabase[index].stabilityFactor + 1.2) * pow(TOF, 0.83);
|
||||
double dragCorrection = (driftVelocity / trueSpeed) * drag;
|
||||
double dragCorrection = (driftVelocity / trueSpeed) * drag * deltaT;
|
||||
velocityOffset[0] += sin(bulletDir + M_PI / 2) * (driftAccel * deltaT + dragCorrection);
|
||||
velocityOffset[1] += cos(bulletDir + M_PI / 2) * (driftAccel * deltaT + dragCorrection);
|
||||
}
|
||||
|
||||
double lat = bulletDatabase[index].latitude;
|
||||
accel[0] = 2 * EARTH_ANGULAR_SPEED * +(velocity[1] * sin(lat) - velocity[2] * cos(lat));
|
||||
accel[1] = 2 * EARTH_ANGULAR_SPEED * -(velocity[0] * sin(lat));
|
||||
accel[2] = 2 * EARTH_ANGULAR_SPEED * +(velocity[0] * cos(lat));
|
||||
accel[0] = 2 * EARTH_ANGULAR_SPEED * +(bulletDatabase[index].bulletVelocity[1] * sin(lat) - bulletDatabase[index].bulletVelocity[2] * cos(lat));
|
||||
accel[1] = 2 * EARTH_ANGULAR_SPEED * -(bulletDatabase[index].bulletVelocity[0] * sin(lat));
|
||||
accel[2] = 2 * EARTH_ANGULAR_SPEED * +(bulletDatabase[index].bulletVelocity[0] * cos(lat));
|
||||
|
||||
velocityOffset[0] += accel[0] * deltaT;
|
||||
velocityOffset[1] += accel[1] * deltaT;
|
||||
velocityOffset[2] += accel[2] * deltaT;
|
||||
|
||||
velocity[0] += velocityOffset[0];
|
||||
velocity[1] += velocityOffset[1];
|
||||
velocity[2] += velocityOffset[2];
|
||||
bulletDatabase[index].bulletSpeed = sqrt(pow(velocity[0], 2) + pow(velocity[1], 2) + pow(velocity[2], 2));
|
||||
bulletDatabase[index].bulletVelocity[0] = velocity[0] + velocityOffset[0];
|
||||
bulletDatabase[index].bulletVelocity[1] = velocity[1] + velocityOffset[1];
|
||||
bulletDatabase[index].bulletVelocity[2] = velocity[2] + velocityOffset[2];
|
||||
|
||||
outputStr << "[" << velocityOffset[0] << "," << velocityOffset[1] << "," << velocityOffset[2] << "]";
|
||||
strncpy_s(output, outputSize, outputStr.str().c_str(), _TRUNCATE);
|
||||
|
Loading…
Reference in New Issue
Block a user