Enclosed is the latest engine model update that supercedes the
one I sent yesterday. I have re-zipped all four files so you can neglect the last lot but only io360.cxx has changed if you've already committed. It's untested since I can't start the engine until John has committed his update with separate properties. Should work fine though.
This commit is contained in:
parent
c0f70c0d54
commit
646f93e618
5 changed files with 453 additions and 121 deletions
|
@ -85,6 +85,11 @@
|
|||
//
|
||||
// DCL 22/03/01 - based on Riley's post on the list (25 rpm gain at 1000 rpm as lever is pulled out from full rich)
|
||||
// I have reduced the sea level full rich mixture to thi = 1.3
|
||||
//
|
||||
// DCL 18/9/01 - Got the engine to start and stop in response to the magneto switch.
|
||||
// Changed all PI to LS_PI (in ls_constants.h).
|
||||
// Engine now checks for fuel and stops when not available.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
|
@ -99,7 +104,9 @@ SG_USING_STD(cout);
|
|||
#endif
|
||||
|
||||
#include "IO360.hxx"
|
||||
#include "LaRCsim/ls_constants.h"
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
// Static utility functions
|
||||
|
||||
|
@ -317,22 +324,27 @@ void FGNewEngine::init(double dt) {
|
|||
Max_Fuel_Flow = 130;
|
||||
Mag_Derate_Percent = 5;
|
||||
// MaxHP = 285; //Continental IO520-M
|
||||
MaxHP = 180; //Lycoming IO360
|
||||
MaxHP = 200; //Lycoming IO360 -A-C-D series
|
||||
// MaxHP = 180; //Current Lycoming IO360 ?
|
||||
// displacement = 520; //Continental IO520-M
|
||||
displacement = 360; //Lycoming IO360
|
||||
displacement_SI = displacement * CONVERT_CUBIC_INCHES_TO_METERS_CUBED;
|
||||
engine_inertia = 0.2; //kgm^2 - value taken from a popular family saloon car engine - need to find an aeroengine value !!!!!
|
||||
prop_inertia = 0.03; //kgm^2 - this value is a total guess - dcl
|
||||
prop_inertia = 0.05; //kgm^2 - this value is a total guess - dcl
|
||||
Gear_Ratio = 1;
|
||||
n_R = 2; // Number of crank revolutions per power cycle - 2 for a 4 cylinder engine.
|
||||
|
||||
started = true;
|
||||
running = fgGetBool("/engines/engine[0]/running");
|
||||
cranking = false;
|
||||
|
||||
fgSetBool("/engines/engine[0]/cranking", false);
|
||||
|
||||
// Initialise Engine Variables used by this instance
|
||||
if(running)
|
||||
RPM = 600;
|
||||
else
|
||||
RPM = 0;
|
||||
Percentage_Power = 0;
|
||||
Manifold_Pressure = 29.00; // Inches
|
||||
RPM = 600;
|
||||
Fuel_Flow_gals_hr = 0;
|
||||
Torque = 0;
|
||||
Torque_SI = 0;
|
||||
|
@ -371,7 +383,9 @@ void FGNewEngine::update() {
|
|||
// cout << "AFR = " << 14.7 / equivalence_ratio << '\n';
|
||||
// cout << "Mixture lever = " << Mixture_Lever_Pos << '\n';
|
||||
// cout << "n = " << RPM << " rpm\n";
|
||||
cout << "T_amb = " << T_amb << '\n';
|
||||
// cout << "T_amb = " << T_amb << '\n';
|
||||
cout << "running = " << running << '\n';
|
||||
cout << "fuel = " << fgGetFloat("/consumables/fuel/tank[0]/level-gal_us") << '\n';
|
||||
}
|
||||
count1++;
|
||||
if(count1 == 600)
|
||||
|
@ -382,15 +396,76 @@ void FGNewEngine::update() {
|
|||
float Vo = 0;
|
||||
float V1 = 0;
|
||||
|
||||
// Set up the new variables
|
||||
float PI = 3.1428571;
|
||||
// Parameters that alter the operation of the engine. (spark, fuel, starter motor etc)
|
||||
// Check for spark
|
||||
int Magneto_Left = 0;
|
||||
int Magneto_Right = 0;
|
||||
int mag_pos = fgGetInt("/engines/engine[0]/magneto");
|
||||
// Magneto positions:
|
||||
// 0 -> off
|
||||
// 1 -> left only
|
||||
// 2 -> right only
|
||||
// 3 -> both
|
||||
if(mag_pos != 0) {
|
||||
spark = true;
|
||||
} else {
|
||||
spark = false;
|
||||
} // neglects battery voltage, master on switch, etc for now.
|
||||
if((mag_pos == 1) || (mag_pos > 2))
|
||||
Magneto_Left = 1;
|
||||
if(mag_pos > 1)
|
||||
Magneto_Right = 1;
|
||||
|
||||
// crude check for fuel
|
||||
if((fgGetFloat("/consumables/fuel/tank[0]/level-gal_us") > 0) || (fgGetFloat("/consumables/fuel/tank[1]/level-gal_us") > 0)) {
|
||||
fuel = true;
|
||||
} else {
|
||||
fuel = false;
|
||||
} // Need to make this better, eg position of fuel selector switch.
|
||||
|
||||
// Check if we are turning the starter motor
|
||||
bool temp = fgGetBool("/engines/engine[0]/starter");
|
||||
if(cranking != temp) {
|
||||
// This check saves .../cranking from getting updated every loop - they only update when changed.
|
||||
cranking = temp;
|
||||
if(cranking)
|
||||
fgSetBool("/engines/engine[0]/cranking", true);
|
||||
else
|
||||
fgSetBool("/engines/engine[0]/cranking", false);
|
||||
}
|
||||
// Note that although /engines/engine[0]/starter and /engines/engine[0]/cranking might appear to be duplication it is
|
||||
// not since the starter may be engaged with the battery voltage too low for cranking to occur (or perhaps the master
|
||||
// switch just left off) and the sound manager will read .../cranking to determine wether to play a cranking sound.
|
||||
// For now though none of that is implemented so cranking can be set equal to .../starter without further checks.
|
||||
|
||||
// Parameters that alter the operation of the engine.
|
||||
int Fuel_Available = 1; // Yes = 1. Is there Fuel Available. Calculated elsewhere
|
||||
int Alternate_Air_Pos =0; // Off = 0. Reduces power by 3 % for same throttle setting
|
||||
int Magneto_Left = 1; // 1 = On. Reduces power by 5 % for same power lever settings
|
||||
int Magneto_Right = 1; // 1 = On. Ditto, Both of the above though do not alter fuel flow
|
||||
// DCL - don't know what this Alternate_Air_Pos is - this is a leftover from the Schubert code.
|
||||
|
||||
//Check mode of engine operation
|
||||
if(cranking) {
|
||||
if(RPM <= 480) {
|
||||
RPM += 100;
|
||||
if(RPM > 480)
|
||||
RPM = 480;
|
||||
} else {
|
||||
// consider making a horrible noise if the starter is engaged with the engine running
|
||||
}
|
||||
}
|
||||
if((!running) && (spark) && (fuel)) {
|
||||
// start the engine if revs high enough
|
||||
if(RPM > 450) {
|
||||
// For now just instantaneously start but later we should maybe crank for a bit
|
||||
running = true;
|
||||
fgSetBool("/engines/engine[0]/running", true);
|
||||
RPM = 600;
|
||||
}
|
||||
}
|
||||
if( (running) && ((!spark)||(!fuel)) ) {
|
||||
// Cut the engine
|
||||
// note that we only cut the power - the engine may continue to spin if the prop is in a moving airstream
|
||||
running = false;
|
||||
fgSetBool("/engines/engine[0]/running", false);
|
||||
}
|
||||
|
||||
// Calculate Sea Level Manifold Pressure
|
||||
Manifold_Pressure = Calc_Manifold_Pressure( Throttle_Lever_Pos, Max_Manifold_Pressure, Min_Manifold_Pressure );
|
||||
|
@ -470,7 +545,8 @@ void FGNewEngine::update() {
|
|||
Percentage_Power = Percentage_Power * Percentage_of_best_power_mixture_power / 100.0;
|
||||
|
||||
// Now Derate engine for the effects of Bad/Switched off magnetos
|
||||
if (Magneto_Left == 0 && Magneto_Right == 0) {
|
||||
//if (Magneto_Left == 0 && Magneto_Right == 0) {
|
||||
if(!running) {
|
||||
// cout << "Both OFF\n";
|
||||
Percentage_Power = 0;
|
||||
} else if (Magneto_Left && Magneto_Right) {
|
||||
|
@ -481,16 +557,40 @@ void FGNewEngine::update() {
|
|||
// cout << FGEng1_Percentage_Power << "%" << "\t";
|
||||
}
|
||||
|
||||
//DCL - stall the engine if RPM drops below 450 - this is possible if mixture lever is pulled right out
|
||||
//This is a kludge that I should eliminate by adding a total fmep estimation.
|
||||
if(RPM < 450)
|
||||
Percentage_Power = 0;
|
||||
|
||||
if(Percentage_Power < 0)
|
||||
Percentage_Power = 0;
|
||||
|
||||
// FMEP calculation. For now we will just use this during motored operation, ie when %Power == 0.
|
||||
// Eventually we will calculate IMEP and use the FMEP all the time to give BMEP
|
||||
//
|
||||
if(Percentage_Power == 0) {
|
||||
// This FMEP data is from the Patton paper, assumes fully warm conditions.
|
||||
FMEP = 1e-12*pow(RPM,4) - 1e-8*pow(RPM,3) + 5e-5*pow(RPM,2) - 0.0722*RPM + 154.85;
|
||||
// Gives FMEP in kPa - now convert to Pa
|
||||
FMEP *= 1000;
|
||||
} else {
|
||||
FMEP = 0.0;
|
||||
}
|
||||
|
||||
Torque_FMEP = (FMEP * displacement_SI) / (2.0 * LS_PI * n_R);
|
||||
|
||||
HP = Percentage_Power * MaxHP / 100.0;
|
||||
|
||||
Power_SI = HP * CONVERT_HP_TO_WATTS;
|
||||
|
||||
// Calculate Engine Torque. Check for div by zero since percentage power correlation does not guarantee zero power at zero rpm.
|
||||
// However this is problematical since there is a resistance to movement even at rest
|
||||
// Ie this is a dynamics equation not a statics one. This can be solved by going over to MEP based torque calculations.
|
||||
if(RPM == 0) {
|
||||
Torque_SI = 0;
|
||||
Torque_SI = 0 - Torque_FMEP;
|
||||
}
|
||||
else {
|
||||
Torque_SI = (Power_SI * 60.0) / (2.0 * PI * RPM); //Torque = power / angular velocity
|
||||
Torque_SI = ((Power_SI * 60.0) / (2.0 * LS_PI * RPM)) - Torque_FMEP; //Torque = power / angular velocity
|
||||
// cout << Torque << " Nm\n";
|
||||
}
|
||||
|
||||
|
@ -628,7 +728,7 @@ the values from file to avoid the necessity for re-compilation every time I chan
|
|||
|
||||
Gear_Ratio = 1.0;
|
||||
FGProp1_RPS = RPM * Gear_Ratio / 60.0; // Borrow this variable from Phils model for now !!
|
||||
angular_velocity_SI = 2.0 * PI * RPM / 60.0;
|
||||
angular_velocity_SI = 2.0 * LS_PI * RPM / 60.0;
|
||||
forward_velocity = IAS * 0.514444444444; // Convert to m/s
|
||||
|
||||
//cout << "Gear_Ratio = " << Gear_Ratio << '\n';
|
||||
|
@ -659,6 +759,10 @@ the values from file to avoid the necessity for re-compilation every time I chan
|
|||
//cout << "prop HP consumed = " << prop_power_consumed_SI / 745.699 << '\n';
|
||||
if(angular_velocity_SI == 0)
|
||||
prop_torque = 0;
|
||||
// However this can give problems - if rpm == 0 but forward velocity increases the prop should be able to generate a torque to start the engine spinning
|
||||
// Unlikely to happen in practice - but I suppose someone could move the lever of a stopped large piston engine from feathered to windmilling.
|
||||
// This *does* give problems - if the plane is put into a steep climb whilst windmilling the engine friction will eventually stop it spinning.
|
||||
// When put back into a dive it never starts re-spinning again. Although it is unlikely that anyone would do this in real life, they might well do it in a sim!!!
|
||||
else
|
||||
prop_torque = prop_power_consumed_SI / angular_velocity_SI;
|
||||
|
||||
|
@ -667,9 +771,14 @@ the values from file to avoid the necessity for re-compilation every time I chan
|
|||
neta_prop_25 = -0.3121*J*J*J*J + 0.4234*J*J*J - 0.7686*J*J + 1.5237*J - 0.0004;
|
||||
neta_prop = neta_prop_20 + ( (neta_prop_25 - neta_prop_20) * ((blade_angle - 20)/(25 - 20)) );
|
||||
|
||||
//FIXME - need to check for zero forward velocity to avoid divide by zero
|
||||
// Check for zero forward velocity to avoid divide by zero
|
||||
if(forward_velocity < 0.0001)
|
||||
prop_thrust = 0.0;
|
||||
// I don't see how this works - how can the plane possibly start from rest ???
|
||||
// Hmmmm - it works because the forward_velocity at present never drops below about 0.03 even at rest
|
||||
// We can't really rely on this in the future - needs fixing !!!!
|
||||
// The problem is that we're doing this calculation backwards - we're working out the thrust from the power consumed and the velocity, which becomes invalid as velocity goes to zero.
|
||||
// It would be far more natural to work out the power consumed from the thrust - FIXME!!!!!.
|
||||
else
|
||||
prop_thrust = neta_prop * prop_power_consumed_SI / forward_velocity; //TODO - rename forward_velocity to IAS_SI
|
||||
//cout << "prop_thrust = " << prop_thrust << '\n';
|
||||
|
@ -679,14 +788,20 @@ the values from file to avoid the necessity for re-compilation every time I chan
|
|||
|
||||
//Calculate new RPM from torque balance and inertia.
|
||||
Torque_Imbalance = Torque_SI - prop_torque; //This gives a +ve value when the engine torque exeeds the prop torque
|
||||
// (Engine torque is +ve when it acts in the direction of engine revolution, prop torque is +ve when it opposes the direction of engine revolution)
|
||||
|
||||
angular_acceleration = Torque_Imbalance / (engine_inertia + prop_inertia);
|
||||
angular_velocity_SI += (angular_acceleration * time_step);
|
||||
RPM = (angular_velocity_SI * 60) / (2.0 * PI);
|
||||
// Don't let the engine go into reverse
|
||||
if(angular_velocity_SI < 0)
|
||||
angular_velocity_SI = 0;
|
||||
RPM = (angular_velocity_SI * 60) / (2.0 * LS_PI);
|
||||
|
||||
// if(RPM < 0)
|
||||
// RPM = 0;
|
||||
|
||||
//DCL - stall the engine if RPM drops below 500 - this is possible if mixture lever is pulled right out
|
||||
if(RPM < 500)
|
||||
RPM = 0;
|
||||
// if(RPM < 500)
|
||||
// RPM = 0;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -105,10 +105,13 @@ private:
|
|||
float HP; // Current power output in HP
|
||||
float Power_SI; // Current power output in Watts
|
||||
float Torque_SI; // Torque in Nm
|
||||
float Torque_FMEP; // The component of Engine torque due to FMEP (Nm)
|
||||
float RPS;
|
||||
float Torque_Imbalance;
|
||||
bool started; //flag to indicate the engine is running self sustaining
|
||||
bool running; //flag to indicate the engine is running self sustaining
|
||||
bool cranking; //flag to indicate the engine is being cranked
|
||||
bool spark; //flag to indicate a spark is available
|
||||
bool fuel; //flag to indicate fuel is available
|
||||
|
||||
//DCL
|
||||
float volumetric_efficiency;
|
||||
|
@ -140,6 +143,8 @@ private:
|
|||
float engine_inertia; //kg.m^2
|
||||
float prop_inertia; //kg.m^2
|
||||
float angular_acceleration; //rad/s^2
|
||||
float n_R; //Number of cycles per power stroke
|
||||
float FMEP; //Friction Mean Effective Pressure (Pa)
|
||||
double time_step;
|
||||
|
||||
// Propellor Variables
|
||||
|
|
|
@ -13,11 +13,7 @@ libFlight_a_SOURCES = \
|
|||
LaRCsimIC.cxx LaRCsimIC.hxx \
|
||||
MagicCarpet.cxx MagicCarpet.hxx
|
||||
|
||||
bin_PROGRAMS = engine pstest
|
||||
|
||||
engine_SOURCES = engine.cxx
|
||||
|
||||
engine_LDADD = libFlight.a
|
||||
bin_PROGRAMS = pstest
|
||||
|
||||
pstest_SOURCES = ps-10520c.cxx
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
// 10520d test program
|
||||
|
||||
#include "IO360.hxx"
|
||||
|
||||
int main() {
|
||||
FGNewEngine e;
|
||||
|
||||
e.init( 1.0 / 120.0 );
|
||||
|
||||
e.set_IAS( 80 );
|
||||
e.set_Throttle_Lever_Pos( 50.0 );
|
||||
e.set_Propeller_Lever_Pos( 100.0 );
|
||||
e.set_Mixture_Lever_Pos( 75 );
|
||||
|
||||
e.update();
|
||||
|
||||
// cout << "Rho = " << e.get_Rho();
|
||||
cout << "Throttle = " << 100.0;
|
||||
cout << " RPM = " << e.get_RPM();
|
||||
cout << " Thrust = " << e.get_FGProp1_Thrust() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -104,20 +104,30 @@
|
|||
|
||||
#include <Input/input.hxx>
|
||||
|
||||
// begin - added Venky
|
||||
// $$$ begin - added VS Renganathan
|
||||
// ADA
|
||||
#include <simgear/misc/sgstream.hxx>
|
||||
#include <simgear/math/point3d.hxx>
|
||||
#include <FDM/flight.hxx>
|
||||
#include <FDM/ADA.hxx>
|
||||
#include <Scenery/tileentry.hxx>
|
||||
// Should be inlcluded by gl.h if needed by your platform
|
||||
// #include <GL/glext.h>
|
||||
PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT = 0;
|
||||
PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT = 0;
|
||||
float default_attenuation[3] = {1.0, 0.0, 0.0};
|
||||
//Required for using GL_extensions
|
||||
void fgLoadDCS (void);
|
||||
void fgUpdateDCS (void);
|
||||
ssgSelector *ship_sel=NULL;
|
||||
// upto 32 instances of a same object can be loaded.
|
||||
ssgTransform *ship_pos[32];
|
||||
double obj_lat[32],obj_lon[32],obj_alt[32];
|
||||
double obj_lat[32],obj_lon[32],obj_alt[32],obj_pitch[32],obj_roll[32];
|
||||
int objc=0;
|
||||
// $$$ end - added VS Renganathan
|
||||
// end - added Venky
|
||||
ssgSelector *lightpoints_brightness = new ssgSelector;
|
||||
ssgTransform *lightpoints_transform = new ssgTransform;
|
||||
FGTileEntry *dummy_tile;
|
||||
sgVec3 rway_ols;
|
||||
// ADA
|
||||
|
||||
#ifndef FG_OLD_WEATHER
|
||||
# include <WeatherCM/FGLocalWeatherDatabase.h>
|
||||
|
@ -444,6 +454,11 @@ void fgRenderFrame( void ) {
|
|||
cur_fdm_state->get_Theta(),
|
||||
cur_fdm_state->get_Psi() );
|
||||
|
||||
if (fgGetString("/sim/flight-model") == "ada") {
|
||||
//+ve x is aft, +ve z is up (see viewer.hxx)
|
||||
pilot_view->set_pilot_offset( -5.0, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
FGViewerLookAt *chase_view =
|
||||
(FGViewerLookAt *)globals->get_viewmgr()->get_view( 1 );
|
||||
|
||||
|
@ -784,8 +799,55 @@ void fgRenderFrame( void ) {
|
|||
// Set punch through fog density
|
||||
glFogf (GL_FOG_DENSITY, fog_exp2_punch_through);
|
||||
|
||||
#ifdef FG_EXPERIMENTAL_LIGHTING
|
||||
// Enable states for drawing points with GL_extension
|
||||
if (glutExtensionSupported("GL_EXT_point_parameters")) {
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
float quadratic[3] = {1.0, 0.01, 0.0001};
|
||||
// get the address of our OpenGL extensions
|
||||
glPointParameterfEXT = (PFNGLPOINTPARAMETERFEXTPROC)
|
||||
wglGetProcAddress("glPointParameterfEXT");
|
||||
glPointParameterfvEXT = (PFNGLPOINTPARAMETERFVEXTPROC)
|
||||
wglGetProcAddress("glPointParameterfvEXT");
|
||||
// makes the points fade as they move away
|
||||
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, quadratic);
|
||||
glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, 1.0);
|
||||
glPointSize(4.0);
|
||||
|
||||
// Enable states for drawing runway lights with spherical mapping
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
|
||||
//Maybe this is not the best way, but it works !!
|
||||
glPolygonMode(GL_FRONT, GL_POINT);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glDisable( GL_LIGHTING );
|
||||
// blending function for runway lights
|
||||
glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
|
||||
glEnable(GL_BLEND);
|
||||
#endif
|
||||
|
||||
ssgCullAndDraw( lighting );
|
||||
|
||||
#ifdef FG_EXPERIMENTAL_LIGHTING
|
||||
if (glutExtensionSupported("GL_EXT_point_parameters")) {
|
||||
// Disable states used for runway lighting
|
||||
glPolygonMode(GL_FRONT, GL_FILL);
|
||||
|
||||
glDisable(GL_TEXTURE_GEN_S);
|
||||
glDisable(GL_TEXTURE_GEN_T);
|
||||
glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT,
|
||||
default_attenuation);
|
||||
}
|
||||
|
||||
glPointSize(1.0);
|
||||
#endif
|
||||
|
||||
if ( fgGetBool("/sim/rendering/skyblend") ) {
|
||||
// draw the sky cloud layers
|
||||
thesky->postDraw( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER );
|
||||
|
@ -1135,47 +1197,51 @@ static void fgMainLoop( void ) {
|
|||
#ifdef ENABLE_AUDIO_SUPPORT
|
||||
if ( fgGetBool("/sim/sound") && globals->get_soundmgr()->is_working() ) {
|
||||
if ( fgGetString("/sim/aircraft") == "c172" ) {
|
||||
// pitch corresponds to rpm
|
||||
// volume corresponds to manifold pressure
|
||||
if(fgGetBool("/engines/engine[0]/running")) {
|
||||
// pitch corresponds to rpm
|
||||
// volume corresponds to manifold pressure
|
||||
|
||||
// cout << "AUDIO working = "
|
||||
// << globals->get_soundmgr()->is_working() << endl;
|
||||
// cout << "AUDIO working = "
|
||||
// << globals->get_soundmgr()->is_working() << endl;
|
||||
|
||||
double rpm_factor;
|
||||
if ( cur_fdm_state->get_engine(0) != NULL ) {
|
||||
rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
|
||||
} else {
|
||||
rpm_factor = 1.0;
|
||||
}
|
||||
// cout << "rpm = " << cur_fdm_state->get_engine(0)->get_RPM()
|
||||
// << endl;
|
||||
double rpm_factor;
|
||||
if ( cur_fdm_state->get_engine(0) != NULL ) {
|
||||
rpm_factor = cur_fdm_state->get_engine(0)->get_RPM() / 2500.0;
|
||||
} else {
|
||||
rpm_factor = 1.0;
|
||||
}
|
||||
// cout << "rpm = " << cur_fdm_state->get_engine(0)->get_RPM()
|
||||
// << endl;
|
||||
|
||||
double pitch = 0.3 + rpm_factor * 3.0;
|
||||
double pitch = 0.3 + rpm_factor * 3.0;
|
||||
|
||||
// don't run at absurdly slow rates -- not realistic
|
||||
// and sounds bad to boot. :-)
|
||||
if (pitch < 0.7) { pitch = 0.7; }
|
||||
if (pitch > 5.0) { pitch = 5.0; }
|
||||
// don't run at absurdly slow rates -- not realistic
|
||||
// and sounds bad to boot. :-)
|
||||
if (pitch < 0.7) { pitch = 0.7; }
|
||||
if (pitch > 5.0) { pitch = 5.0; }
|
||||
|
||||
double mp_factor;
|
||||
if ( cur_fdm_state->get_engine(0) != NULL ) {
|
||||
mp_factor =
|
||||
cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 100;
|
||||
double mp_factor;
|
||||
if ( cur_fdm_state->get_engine(0) != NULL ) {
|
||||
mp_factor = cur_fdm_state->get_engine(0)->get_Manifold_Pressure() / 100;
|
||||
} else {
|
||||
mp_factor = 0.3;
|
||||
}
|
||||
/* cout << "mp = "
|
||||
<< cur_fdm_state->get_engine(0)->get_Manifold_Pressure()
|
||||
<< endl; */
|
||||
|
||||
double volume = 0.15 + mp_factor / 2.0;
|
||||
|
||||
if ( volume < 0.15 ) { volume = 0.15; }
|
||||
if ( volume > 0.5 ) { volume = 0.5; }
|
||||
// cout << "volume = " << volume << endl;
|
||||
|
||||
s1->set_pitch( pitch );
|
||||
s1->set_volume( volume );
|
||||
} else {
|
||||
mp_factor = 0.3;
|
||||
s1->set_pitch(0.0);
|
||||
s1->set_volume(0.0);
|
||||
}
|
||||
/* cout << "mp = "
|
||||
<< cur_fdm_state->get_engine(0)->get_Manifold_Pressure()
|
||||
<< endl; */
|
||||
|
||||
double volume = 0.15 + mp_factor / 2.0;
|
||||
|
||||
if ( volume < 0.15 ) { volume = 0.15; }
|
||||
if ( volume > 0.5 ) { volume = 0.5; }
|
||||
// cout << "volume = " << volume << endl;
|
||||
|
||||
s1->set_pitch( pitch );
|
||||
s1->set_volume( volume );
|
||||
} else {
|
||||
double param
|
||||
= globals->get_controls()->get_throttle( 0 ) * 2.0 + 1.0;
|
||||
|
@ -1666,31 +1732,48 @@ int mainLoop( int argc, char **argv ) {
|
|||
airport->setName( "Airport Lighting" );
|
||||
lighting->addKid( airport );
|
||||
|
||||
// ADA
|
||||
fgLoadDCS();
|
||||
// ADA
|
||||
|
||||
// temporary visible aircraft "own ship"
|
||||
acmodel_selector = new ssgSelector;
|
||||
acmodel_pos = new ssgTransform;
|
||||
|
||||
// Get the model location, and load textures from the same
|
||||
// directory. Use an absolute path for the model to avoid
|
||||
// incompatibilities in different versions of PLIB.
|
||||
string acmodel_path =
|
||||
fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
|
||||
SGPath full_model = globals->get_fg_root();
|
||||
full_model.append(acmodel_path);
|
||||
ssgEntity *acmodel_obj = NULL;
|
||||
if (fgGetString("/sim/flight-model") == "ada") {
|
||||
// ada exteranl aircraft model loading
|
||||
if( !ship_pos[0]->getKid(0) ) {
|
||||
// fall back to default
|
||||
ssgEntity *acmodel_obj = ssgLoad( (char *)"glider.ac" );
|
||||
if( !acmodel_obj ) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, "FAILED to LOAD an AC model! ..." );
|
||||
exit(-1);
|
||||
}
|
||||
acmodel_pos->addKid( acmodel_obj );
|
||||
} else {
|
||||
acmodel_obj = ship_pos[0]->getKid(0);
|
||||
}
|
||||
} else {
|
||||
// default aircraft model loading
|
||||
|
||||
#if !defined( PLIB_1_2_X )
|
||||
// this should be redundant ... but it breaks for relative paths
|
||||
// ssgModelPath( (char *)full_model.dir().c_str() );
|
||||
#endif
|
||||
// Get the model location, and load textures from the same
|
||||
// directory. Use an absolute path for the model to avoid
|
||||
// incompatibilities in different versions of PLIB.
|
||||
string acmodel_path =
|
||||
fgGetString("/sim/model/path", "Models/Geometry/glider.ac");
|
||||
SGPath full_model = globals->get_fg_root();
|
||||
full_model.append(acmodel_path);
|
||||
|
||||
ssgTexturePath( (char *)full_model.dir().c_str() );
|
||||
ssgEntity *acmodel_obj = ssgLoad( (char *)full_model.c_str() );
|
||||
if( !acmodel_obj ) {
|
||||
// fall back to default
|
||||
acmodel_obj = ssgLoad( (char *)"Models/Geometry/glider.ac" );
|
||||
ssgTexturePath( (char *)full_model.dir().c_str() );
|
||||
acmodel_obj = ssgLoad( (char *)full_model.c_str() );
|
||||
if( !acmodel_obj ) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, "FAILED to LOAD an AC model! ..." );
|
||||
exit(-1);
|
||||
// fall back to default
|
||||
acmodel_obj = ssgLoad( (char *)"Models/Geometry/glider.ac" );
|
||||
if( !acmodel_obj ) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, "FAILED to LOAD an AC model! ..." );
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1741,10 +1824,6 @@ int mainLoop( int argc, char **argv ) {
|
|||
acmodel_selector->clrTraversalMaskBits( SSGTRAV_HOT );
|
||||
scene->addKid( acmodel_selector );
|
||||
|
||||
// $$$ begin - added VS Renganthan 17 Oct 2K
|
||||
fgLoadDCS();
|
||||
// $$$ end - added VS Renganthan 17 Oct 2K
|
||||
|
||||
#ifdef FG_NETWORK_OLK
|
||||
// Do the network intialization
|
||||
if ( fgGetBool("/sim/networking/network-olk") ) {
|
||||
|
@ -1785,8 +1864,7 @@ int main ( int argc, char **argv ) {
|
|||
void fgLoadDCS(void) {
|
||||
|
||||
ssgEntity *ship_obj = NULL;
|
||||
// double bz[3];
|
||||
// int j=0;
|
||||
|
||||
char obj_filename[25];
|
||||
|
||||
for ( int k = 0; k < 32; k++ ) {
|
||||
|
@ -1834,17 +1912,119 @@ void fgLoadDCS(void) {
|
|||
// instance of the last object.
|
||||
|
||||
if ( strcmp(obj_filename,"repeat") != 0) {
|
||||
ship_obj = ssgLoadOBJ( obj_filename );
|
||||
ship_obj = ssgLoad( obj_filename );
|
||||
}
|
||||
|
||||
if ( ship_obj != NULL ) {
|
||||
ship_obj->setName(obj_filename);
|
||||
if (objc == 0)
|
||||
ship_obj->clrTraversalMaskBits( SSGTRAV_HOT );
|
||||
else
|
||||
ship_obj->setTraversalMaskBits( SSGTRAV_HOT );
|
||||
ship_pos[objc]->addKid( ship_obj ); // add object to transform node
|
||||
ship_sel->addKid( ship_pos[objc] ); // add transform node to selector
|
||||
SG_LOG( SG_TERRAIN, SG_ALERT, "Loaded file: "
|
||||
<< obj_filename );
|
||||
} else {
|
||||
SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: "
|
||||
<< obj_filename );
|
||||
}
|
||||
|
||||
// temporary hack for deck lights - ultimately should move to PLib (when??)
|
||||
//const char *extn = file_extension ( obj_filename ) ;
|
||||
if ( objc == 1 ){
|
||||
ssgVertexArray *lights = new ssgVertexArray( 100 );
|
||||
ssgVertexArray *lightpoints = new ssgVertexArray( 100 );
|
||||
ssgVertexArray *lightnormals = new ssgVertexArray( 100 );
|
||||
ssgVertexArray *lightdir = new ssgVertexArray( 100 );
|
||||
int ltype[500], light_type;
|
||||
static int ltcount = 0;
|
||||
string token;
|
||||
sgVec3 rway_dir,rway_normal,lightpt;
|
||||
Point3D node;
|
||||
modelpath.append(obj_filename);
|
||||
sg_gzifstream in1( modelpath.str() );
|
||||
if ( ! in1.is_open() ) {
|
||||
SG_LOG( SG_TERRAIN, SG_ALERT, "Cannot open file: " << modelpath.str() );
|
||||
} else {
|
||||
while ( ! in1.eof() ) {
|
||||
in1 >> skipws;
|
||||
if ( in1.get( c ) && c == '#' ) {
|
||||
in1 >> skipeol;
|
||||
} else {
|
||||
in1.putback(c);
|
||||
in1 >> token;
|
||||
//cout << token << endl;
|
||||
if ( token == "runway" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_dir, node[0], node[1], node[2] );
|
||||
} else if ( token == "edgelight" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 1;
|
||||
} else if ( token == "taxi" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 2;
|
||||
} else if ( token == "vasi" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 3;
|
||||
} else if ( token == "threshold" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 4;
|
||||
} else if ( token == "rabbit" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 5;
|
||||
} else if ( token == "ols" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_ols, node[0], node[1], node[2] );
|
||||
light_type = 6;
|
||||
} else if ( token == "red" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 7;
|
||||
} else if ( token == "green" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (rway_normal, node[0], node[1], node[2] );
|
||||
light_type = 8;
|
||||
} else if ( token == "lp" ) {
|
||||
in1 >> node;
|
||||
sgSetVec3 (lightpt, node[0], node[1], node[2] );
|
||||
lightpoints->add( lightpt );
|
||||
lightnormals->add( rway_normal );
|
||||
lightdir->add( rway_dir );
|
||||
ltype[ltcount]= light_type;
|
||||
ltcount++;
|
||||
}
|
||||
if (in1.eof()) break;
|
||||
}
|
||||
} //while
|
||||
|
||||
if ( lightpoints->getNum() ) {
|
||||
ssgBranch *lightpoints_branch;
|
||||
long int dummy = -999;
|
||||
dummy_tile = new FGTileEntry((SGBucket)dummy);
|
||||
dummy_tile->lightmaps_sequence = new ssgSelector;
|
||||
dummy_tile->ols_transform = new ssgTransform;
|
||||
|
||||
// call function to generate the runway lights
|
||||
lightpoints_branch =
|
||||
dummy_tile->gen_runway_lights( lightpoints, lightnormals,
|
||||
lightdir, ltype);
|
||||
lightpoints_brightness->addKid(lightpoints_branch);
|
||||
lightpoints_transform->addKid(lightpoints_brightness);
|
||||
//dummy_tile->lightmaps_sequence->setTraversalMaskBits( SSGTRAV_HOT );
|
||||
lightpoints_transform->addKid( dummy_tile->lightmaps_sequence );
|
||||
lightpoints_transform->ref();
|
||||
ground->addKid( lightpoints_transform );
|
||||
}
|
||||
} //if in1
|
||||
} //if objc
|
||||
// end hack for deck lights
|
||||
|
||||
objc++;
|
||||
|
||||
if (in.eof()) break;
|
||||
|
@ -1853,8 +2033,7 @@ void fgLoadDCS(void) {
|
|||
|
||||
SG_LOG ( SG_TERRAIN, SG_ALERT, "Finished object processing." );
|
||||
|
||||
ship_sel->clrTraversalMaskBits( SSGTRAV_HOT );
|
||||
scene->addKid( ship_sel ); //add selector node to root node
|
||||
terrain->addKid( ship_sel ); //add selector node to root node
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -1876,9 +2055,14 @@ void fgUpdateDCS (void) {
|
|||
// Deck should be the first object in objects.txt in case of fdm=ada
|
||||
|
||||
if (fgGetString("/sim/flight-model") == "ada") {
|
||||
obj_lon[0] = fdm->get_aux5()*SGD_DEGREES_TO_RADIANS;
|
||||
obj_lat[0] = fdm->get_aux6()*SGD_DEGREES_TO_RADIANS;
|
||||
obj_alt[0] = fdm->get_aux7();
|
||||
if ((fdm->get_iaux(1))==1)
|
||||
{
|
||||
obj_lat[1] = fdm->get_daux(1)*SGD_DEGREES_TO_RADIANS;
|
||||
obj_lon[1] = fdm->get_daux(2)*SGD_DEGREES_TO_RADIANS;
|
||||
obj_alt[1] = fdm->get_daux(3);
|
||||
obj_pitch[1] = fdm->get_faux(1);
|
||||
obj_roll[1] = fdm->get_faux(2);
|
||||
}
|
||||
}
|
||||
|
||||
for ( int m = 0; m < objc; m++ ) {
|
||||
|
@ -1908,13 +2092,17 @@ void fgUpdateDCS (void) {
|
|||
sgSetVec3( ship_rt, 0.0, 1.0, 0.0);//up,pitch
|
||||
sgSetVec3( ship_up, 0.0, 0.0, 1.0); //north,yaw
|
||||
|
||||
sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg;
|
||||
sgMat4 sgROT_lon, sgROT_lat, sgROT_hdg, sgROT_pitch, sgROT_roll;
|
||||
sgMakeRotMat4( sgROT_lon, obj_lon[m]*SGD_RADIANS_TO_DEGREES, ship_up );
|
||||
sgMakeRotMat4( sgROT_lat, 90-obj_latgc*SGD_RADIANS_TO_DEGREES, ship_rt );
|
||||
sgMakeRotMat4( sgROT_hdg, 180.0, ship_up );
|
||||
sgMakeRotMat4( sgROT_pitch, obj_pitch[m], ship_rt );
|
||||
sgMakeRotMat4( sgROT_roll, obj_roll[m], ship_fwd );
|
||||
|
||||
sgMat4 sgTUX;
|
||||
sgCopyMat4( sgTUX, sgROT_hdg );
|
||||
sgPostMultMat4( sgTUX, sgROT_pitch );
|
||||
sgPostMultMat4( sgTUX, sgROT_roll );
|
||||
sgPostMultMat4( sgTUX, sgROT_lat );
|
||||
sgPostMultMat4( sgTUX, sgROT_lon );
|
||||
sgPostMultMat4( sgTUX, sgTRANS );
|
||||
|
@ -1922,9 +2110,60 @@ void fgUpdateDCS (void) {
|
|||
sgCoord shippos;
|
||||
sgSetCoord(&shippos, sgTUX );
|
||||
ship_pos[m]->setTransform( &shippos );
|
||||
// temporary hack for deck lights - ultimately should move to PLib (when ??)
|
||||
if (m == 1) {
|
||||
if (lightpoints_transform) {
|
||||
lightpoints_transform->setTransform( &shippos );
|
||||
float sun_angle = cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES;
|
||||
if ( sun_angle > 89 ) {
|
||||
lightpoints_brightness->select(0x01);
|
||||
} else {
|
||||
lightpoints_brightness->select(0x00);
|
||||
}
|
||||
}
|
||||
|
||||
float elev;
|
||||
sgVec3 rp,to;
|
||||
float *vp;
|
||||
float alt;
|
||||
float ref_elev;
|
||||
sgXformPnt3( rp, rway_ols, sgTUX );
|
||||
vp = globals->get_current_view()->get_view_pos();
|
||||
to[0] = rp[0]-vp[0];
|
||||
to[1] = rp[1]-vp[1];
|
||||
to[2] = rp[2]-vp[2];
|
||||
float dist = sgLengthVec3( to );
|
||||
alt = (current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER)-rway_ols[2];
|
||||
|
||||
elev = asin(alt/dist)*SGD_RADIANS_TO_DEGREES;
|
||||
|
||||
ref_elev = elev - 3.75; // +ve above, -ve below
|
||||
|
||||
unsigned int sel;
|
||||
sel = 0xFF;
|
||||
// DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
|
||||
// if (ref_elev > 0.51) sel = 0x21;
|
||||
// if ((ref_elev <= 0.51) & (ref_elev > 0.17)) sel = 0x22;
|
||||
// if ((ref_elev <= 0.17) & (ref_elev >= -0.17)) sel = 0x24;
|
||||
// if ((ref_elev < -0.17) & (ref_elev >= -0.51)) sel = 0x28;
|
||||
// if (ref_elev < -0.51) sel = 0x30;
|
||||
// DO NOT DELETE THIS CODE - This is to compare a discrete FLOLS (without LOD) with analog FLOLS
|
||||
dummy_tile->lightmaps_sequence->select(sel);
|
||||
|
||||
sgVec3 up;
|
||||
sgCopyVec3 (up, ship_up);
|
||||
if (dist > 750)
|
||||
sgScaleVec3 (up, 4.0*ref_elev*dist/750.0);
|
||||
else
|
||||
sgScaleVec3 (up, 4.0*ref_elev);
|
||||
dummy_tile->ols_transform->setTransform(up);
|
||||
//cout << "ref_elev " << ref_elev << endl;
|
||||
}
|
||||
// end hack for deck lights
|
||||
|
||||
}
|
||||
if ( ship_sel != NULL ) {
|
||||
ship_sel->select(0xFFFFFFFF);
|
||||
ship_sel->select(0xFFFFFFFE); // first object is ownship, added to acmodel
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue