1
0
Fork 0

Use simgear vector instead of plib vectors.

Modified Files:
	SP/Balloon.cxx SP/BalloonSim.cpp SP/BalloonSim.h
This commit is contained in:
frohlich 2009-03-17 05:32:39 +00:00 committed by Tim Moore
parent 4e13f8e4a0
commit 22888ca8a5
3 changed files with 48 additions and 56 deletions

View file

@ -81,31 +81,26 @@ void FGBalloonSim::init() {
//now do init specific to the Balloon //now do init specific to the Balloon
sgVec3 temp;
SG_LOG( SG_FLIGHT, SG_INFO, "Starting initializing BalloonSim" ); SG_LOG( SG_FLIGHT, SG_INFO, "Starting initializing BalloonSim" );
SG_LOG( SG_FLIGHT, SG_INFO, " created a balloon" ); SG_LOG( SG_FLIGHT, SG_INFO, " created a balloon" );
//set position //set position
sgSetVec3( temp, SGVec3f temp(get_Latitude(),
get_Latitude(), get_Longitude(),
get_Longitude(), get_Altitude() * SG_FEET_TO_METER);
get_Altitude() * SG_FEET_TO_METER);
current_balloon.setPosition( temp ); current_balloon.setPosition( temp );
//set Euler angles (?) //set Euler angles (?)
sgSetVec3( temp, temp = SGVec3f(get_Phi(),
get_Phi(), get_Theta(),
get_Theta(), get_Psi() );
get_Psi() );
current_balloon.setHPR( temp ); current_balloon.setHPR( temp );
//set velocities //set velocities
sgSetVec3( temp, temp = SGVec3f(fgGetDouble("/sim/presets/uBody-fps"),
fgGetDouble("/sim/presets/uBody-fps"), fgGetDouble("/sim/presets/vBody-fps"),
fgGetDouble("/sim/presets/vBody-fps"), fgGetDouble("/sim/presets/wBody-fps") );
fgGetDouble("/sim/presets/wBody-fps") );
current_balloon.setVelocity( temp ); current_balloon.setVelocity( temp );
SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing BalloonSim" ); SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing BalloonSim" );
@ -179,13 +174,13 @@ bool FGBalloonSim::copy_to_BalloonSim() {
// Convert from the BalloonSim to the FGInterface struct // Convert from the BalloonSim to the FGInterface struct
bool FGBalloonSim::copy_from_BalloonSim() { bool FGBalloonSim::copy_from_BalloonSim() {
sgVec3 temp; SGVec3f temp;
// Velocities // Velocities
current_balloon.getVelocity( temp ); current_balloon.getVelocity( temp );
_set_Velocities_Local( temp[0], temp[1], temp[2] ); _set_Velocities_Local( temp[0], temp[1], temp[2] );
/* ***FIXME*** */ _set_V_equiv_kts( sgLengthVec3 ( temp ) ); /* ***FIXME*** */ _set_V_equiv_kts( length( temp ) );
_set_Omega_Body( 0.0, 0.0, 0.0 ); _set_Omega_Body( 0.0, 0.0, 0.0 );

View file

@ -44,7 +44,6 @@ HISTORY
#endif #endif
#include <stdio.h> #include <stdio.h>
// #include <conio.h>
#include <math.h> #include <math.h>
#include <simgear/constants.h> #include <simgear/constants.h>
@ -53,8 +52,6 @@ HISTORY
#include "BalloonSim.h" #include "BalloonSim.h"
#include <plib/sg.h>
/****************************************************************************/ /****************************************************************************/
/********************************** CODE ************************************/ /********************************** CODE ************************************/
/****************************************************************************/ /****************************************************************************/
@ -71,10 +68,10 @@ balloon::balloon()
dt = 0.1; dt = 0.1;
ground_level = 3400.0; ground_level = 3400.0;
sgSetVec3(gravity_vector, 0.0, 0.0, -9.81); gravity_vector = SGVec3f(0.0, 0.0, -9.81);
sgSetVec3(velocity, 0.0, 0.0, 0.0); velocity = SGVec3f(0.0, 0.0, 0.0);
sgSetVec3(position, 0.0, 0.0, 0.0); position = SGVec3f(0.0, 0.0, 0.0);
sgSetVec3(hpr, 0.0, 0.0, 0.0); hpr = SGVec3f(0.0, 0.0, 0.0);
/************************************************************************/ /************************************************************************/
/* My balloon has a radius of 8.8 metres as that gives a envelope */ /* My balloon has a radius of 8.8 metres as that gives a envelope */
@ -202,24 +199,24 @@ void balloon::update()
float mTotal = mEnvelope + mBasket; float mTotal = mEnvelope + mBasket;
//calulate the forces //calulate the forces
sgVec3 fTotal, fFriction, fLift; SGVec3f fTotal, fFriction, fLift;
sgScaleVec3(fTotal, gravity_vector, mTotal); fTotal = mTotal*gravity_vector;
//sgAddVec3(fTotal, fLift); //FIXME: uninitialized fLift // fTotal += fLift; //FIXME: uninitialized fLift
//sgAddVec3(fTotal, fFriction); //FIXME: uninitialized fFriction // fTotal += fFriction; //FIXME: uninitialized fFriction
//claculate acceleration: a = F / m //claculate acceleration: a = F / m
sgVec3 aTotal, vTotal, dTotal; SGVec3f aTotal, vTotal, dTotal;
sgScaleVec3(aTotal, fTotal, 1.0 / mTotal); aTotal = (1.0 / mTotal)*fTotal;
//integrate the displacement: d = 0.5 * a * dt**2 + v * dt + d //integrate the displacement: d = 0.5 * a * dt**2 + v * dt + d
sgScaleVec3(vTotal, velocity, dt); vTotal = dt*velocity;
sgScaleVec3(dTotal, aTotal, 0.5*dt*dt); sgAddVec3(dTotal, vTotal); dTotal = (0.5*dt*dt)*aTotal; dTotal += vTotal;
//integrate the velocity to 'velocity': v = a * dt + v //integrate the velocity to 'velocity': v = a * dt + v
sgScaleVec3(vTotal, aTotal, dt); sgAddVec3(velocity, vTotal); vTotal = dt*aTotal; velocity += vTotal;
/************************************************************************/ /************************************************************************/
/* VERY WRONG STUFF: it's just here to get some results to start with */ /* VERY WRONG STUFF: it's just here to get some results to start with */
@ -230,7 +227,7 @@ void balloon::update()
position[2] = ground_level; position[2] = ground_level;
//return results //return results
sgAddVec3(position, dTotal); position += dTotal;
//cout << "BallonSim: T: " << (T-273.16) << " alt: " << position[2] << " ground: " << ground_level << " throttle: " << current_burner_strength << "\n"; //cout << "BallonSim: T: " << (T-273.16) << " alt: " << position[2] << " ground: " << ground_level << " throttle: " << current_burner_strength << "\n";
} }
@ -241,34 +238,34 @@ void balloon::set_burner_strength(const float bs)
current_burner_strength = bs; current_burner_strength = bs;
} }
void balloon::getVelocity(sgVec3 v) const void balloon::getVelocity(SGVec3f& v) const
{ {
sgCopyVec3(v, velocity); v = velocity;
} }
void balloon::setVelocity(const sgVec3 v) void balloon::setVelocity(const SGVec3f& v)
{ {
sgCopyVec3(velocity, v); velocity = v;
} }
void balloon::getPosition(sgVec3 v) const void balloon::getPosition(SGVec3f& v) const
{ {
sgCopyVec3(v, position); v = position;
} }
void balloon::setPosition(const sgVec3 v) void balloon::setPosition(const SGVec3f& v)
{ {
sgCopyVec3(position, v); position = v;
} }
void balloon::getHPR(sgVec3 angles) const //the balloon isn't allways exactly vertical void balloon::getHPR(SGVec3f& angles) const //the balloon isn't allways exactly vertical
{ {
sgCopyVec3(angles, hpr); angles = hpr;
} }
void balloon::setHPR(const sgVec3 angles) //the balloon isn't allways exactly vertical void balloon::setHPR(const SGVec3f& angles) //the balloon isn't allways exactly vertical
{ {
sgCopyVec3(hpr, angles); hpr = angles;
} }
void balloon::setGroundLevel(const float altitude) void balloon::setGroundLevel(const float altitude)

View file

@ -43,7 +43,7 @@ HISTORY
/****************************************************************************/ /****************************************************************************/
/* INCLUDES */ /* INCLUDES */
/****************************************************************************/ /****************************************************************************/
#include <plib/sg.h> #include <simgear/math/SGMath.hxx>
/****************************************************************************/ /****************************************************************************/
/* DEFINES */ /* DEFINES */
@ -57,10 +57,10 @@ class balloon
private: private:
float dt; //in s float dt; //in s
sgVec3 gravity_vector; //in m/s*s SGVec3f gravity_vector; //in m/s*s
sgVec3 hpr; //the balloon isn't allways exactly vertical (e.g. during gusts); normalized SGVec3f hpr; //the balloon isn't allways exactly vertical (e.g. during gusts); normalized
sgVec3 velocity; //current velocity; it gets iterated at each 'update' SGVec3f velocity; //current velocity; it gets iterated at each 'update'
sgVec3 position; //current position in lat/lon/alt SGVec3f position; //current position in lat/lon/alt
float balloon_envelope_area; //area of the envelope float balloon_envelope_area; //area of the envelope
float balloon_envelope_volume; //volume of the envelope float balloon_envelope_volume; //volume of the envelope
@ -94,14 +94,14 @@ public:
void update(); //dt = time in seconds since last call void update(); //dt = time in seconds since last call
void set_burner_strength(const float bs); void set_burner_strength(const float bs);
void getVelocity(sgVec3 v) const; void getVelocity(SGVec3f& v) const;
void setVelocity(const sgVec3 v); void setVelocity(const SGVec3f& v);
void getPosition(sgVec3 v) const; void getPosition(SGVec3f& v) const;
void setPosition(const sgVec3 v); void setPosition(const SGVec3f& v);
void getHPR(sgVec3 angles) const; //the balloon isn't allways exactly vertical void getHPR(SGVec3f& angles) const; //the balloon isn't allways exactly vertical
void setHPR(const sgVec3 angles); //the balloon isn't allways exactly vertical void setHPR(const SGVec3f& angles); //the balloon isn't allways exactly vertical
void setGroundLevel(const float altitude); void setGroundLevel(const float altitude);