//now do init specific to the Balloon
- sgVec3 temp;
-
SG_LOG( SG_FLIGHT, SG_INFO, "Starting initializing BalloonSim" );
SG_LOG( SG_FLIGHT, SG_INFO, " created a balloon" );
//set position
- sgSetVec3( temp,
- get_Latitude(),
- get_Longitude(),
- get_Altitude() * SG_FEET_TO_METER);
+ SGVec3f temp(get_Latitude(),
+ get_Longitude(),
+ get_Altitude() * SG_FEET_TO_METER);
current_balloon.setPosition( temp );
//set Euler angles (?)
- sgSetVec3( temp,
- get_Phi(),
- get_Theta(),
- get_Psi() );
+ temp = SGVec3f(get_Phi(),
+ get_Theta(),
+ get_Psi() );
current_balloon.setHPR( temp );
//set velocities
- sgSetVec3( temp,
- fgGetDouble("/sim/presets/uBody-fps"),
- fgGetDouble("/sim/presets/vBody-fps"),
- fgGetDouble("/sim/presets/wBody-fps") );
+ temp = SGVec3f(fgGetDouble("/sim/presets/uBody-fps"),
+ fgGetDouble("/sim/presets/vBody-fps"),
+ fgGetDouble("/sim/presets/wBody-fps") );
current_balloon.setVelocity( temp );
SG_LOG( SG_FLIGHT, SG_INFO, "Finished initializing BalloonSim" );
// Convert from the BalloonSim to the FGInterface struct
bool FGBalloonSim::copy_from_BalloonSim() {
- sgVec3 temp;
+ SGVec3f temp;
// Velocities
current_balloon.getVelocity( temp );
_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 );
#endif
#include <stdio.h>
-// #include <conio.h>
#include <math.h>
#include <simgear/constants.h>
#include "BalloonSim.h"
-#include <plib/sg.h>
-
/****************************************************************************/
/********************************** CODE ************************************/
/****************************************************************************/
dt = 0.1;
ground_level = 3400.0;
- sgSetVec3(gravity_vector, 0.0, 0.0, -9.81);
- sgSetVec3(velocity, 0.0, 0.0, 0.0);
- sgSetVec3(position, 0.0, 0.0, 0.0);
- sgSetVec3(hpr, 0.0, 0.0, 0.0);
+ gravity_vector = SGVec3f(0.0, 0.0, -9.81);
+ velocity = SGVec3f(0.0, 0.0, 0.0);
+ position = SGVec3f(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 */
float mTotal = mEnvelope + mBasket;
//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
- //sgAddVec3(fTotal, fFriction); //FIXME: uninitialized fFriction
+ // fTotal += fLift; //FIXME: uninitialized fLift
+ // fTotal += fFriction; //FIXME: uninitialized fFriction
//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
- sgScaleVec3(vTotal, velocity, dt);
- sgScaleVec3(dTotal, aTotal, 0.5*dt*dt); sgAddVec3(dTotal, vTotal);
+ vTotal = dt*velocity;
+ dTotal = (0.5*dt*dt)*aTotal; dTotal += vTotal;
//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 */
position[2] = ground_level;
//return results
- sgAddVec3(position, dTotal);
+ position += dTotal;
//cout << "BallonSim: T: " << (T-273.16) << " alt: " << position[2] << " ground: " << ground_level << " throttle: " << current_burner_strength << "\n";
}
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)
/****************************************************************************/
/* INCLUDES */
/****************************************************************************/
-#include <plib/sg.h>
+#include <simgear/math/SGMath.hxx>
/****************************************************************************/
/* DEFINES */
private:
float dt; //in s
- sgVec3 gravity_vector; //in m/s*s
- sgVec3 hpr; //the balloon isn't allways exactly vertical (e.g. during gusts); normalized
- sgVec3 velocity; //current velocity; it gets iterated at each 'update'
- sgVec3 position; //current position in lat/lon/alt
+ SGVec3f gravity_vector; //in m/s*s
+ SGVec3f hpr; //the balloon isn't allways exactly vertical (e.g. during gusts); normalized
+ SGVec3f velocity; //current velocity; it gets iterated at each 'update'
+ SGVec3f position; //current position in lat/lon/alt
float balloon_envelope_area; //area of the envelope
float balloon_envelope_volume; //volume of the envelope
void update(); //dt = time in seconds since last call
void set_burner_strength(const float bs);
- void getVelocity(sgVec3 v) const;
- void setVelocity(const sgVec3 v);
+ void getVelocity(SGVec3f& v) const;
+ void setVelocity(const SGVec3f& v);
- void getPosition(sgVec3 v) const;
- void setPosition(const sgVec3 v);
+ void getPosition(SGVec3f& v) const;
+ void setPosition(const SGVec3f& v);
- void getHPR(sgVec3 angles) const; //the balloon isn't allways exactly vertical
- void setHPR(const sgVec3 angles); //the balloon isn't allways exactly vertical
+ void getHPR(SGVec3f& angles) const; //the balloon isn't allways exactly vertical
+ void setHPR(const SGVec3f& angles); //the balloon isn't allways exactly vertical
void setGroundLevel(const float altitude);