2001-12-01 06:22:24 +00:00
|
|
|
#include "Atmosphere.hpp"
|
|
|
|
#include "Thruster.hpp"
|
|
|
|
#include "Math.hpp"
|
|
|
|
#include "RigidBody.hpp"
|
|
|
|
#include "Integrator.hpp"
|
|
|
|
#include "Propeller.hpp"
|
|
|
|
#include "PistonEngine.hpp"
|
|
|
|
#include "Gear.hpp"
|
2005-02-17 10:26:14 +00:00
|
|
|
#include "Hook.hpp"
|
|
|
|
#include "Launchbar.hpp"
|
2001-12-01 06:22:24 +00:00
|
|
|
#include "Surface.hpp"
|
2003-10-16 14:56:13 +00:00
|
|
|
#include "Rotor.hpp"
|
|
|
|
#include "Rotorpart.hpp"
|
|
|
|
#include "Rotorblade.hpp"
|
2001-12-01 06:22:24 +00:00
|
|
|
#include "Glue.hpp"
|
2005-02-17 10:26:14 +00:00
|
|
|
#include "Ground.hpp"
|
2001-12-01 06:22:24 +00:00
|
|
|
|
|
|
|
#include "Model.hpp"
|
|
|
|
namespace yasim {
|
|
|
|
|
2003-12-01 01:22:27 +00:00
|
|
|
#if 0
|
2001-12-01 06:22:24 +00:00
|
|
|
void printState(State* s)
|
|
|
|
{
|
|
|
|
State tmp = *s;
|
|
|
|
Math::vmul33(tmp.orient, tmp.v, tmp.v);
|
|
|
|
Math::vmul33(tmp.orient, tmp.acc, tmp.acc);
|
|
|
|
Math::vmul33(tmp.orient, tmp.rot, tmp.rot);
|
|
|
|
Math::vmul33(tmp.orient, tmp.racc, tmp.racc);
|
|
|
|
|
|
|
|
printf("\nNEW STATE (LOCAL COORDS)\n");
|
|
|
|
printf("pos: %10.2f %10.2f %10.2f\n", tmp.pos[0], tmp.pos[1], tmp.pos[2]);
|
|
|
|
printf("o: ");
|
2001-12-07 20:00:59 +00:00
|
|
|
int i;
|
|
|
|
for(i=0; i<3; i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
if(i != 0) printf(" ");
|
|
|
|
printf("%6.2f %6.2f %6.2f\n",
|
|
|
|
tmp.orient[3*i+0], tmp.orient[3*i+1], tmp.orient[3*i+2]);
|
|
|
|
}
|
|
|
|
printf("v: %6.2f %6.2f %6.2f\n", tmp.v[0], tmp.v[1], tmp.v[2]);
|
|
|
|
printf("acc: %6.2f %6.2f %6.2f\n", tmp.acc[0], tmp.acc[1], tmp.acc[2]);
|
|
|
|
printf("rot: %6.2f %6.2f %6.2f\n", tmp.rot[0], tmp.rot[1], tmp.rot[2]);
|
|
|
|
printf("rac: %6.2f %6.2f %6.2f\n", tmp.racc[0], tmp.racc[1], tmp.racc[2]);
|
|
|
|
}
|
2003-12-01 01:22:27 +00:00
|
|
|
#endif
|
2001-12-01 06:22:24 +00:00
|
|
|
|
|
|
|
Model::Model()
|
|
|
|
{
|
2001-12-07 20:00:59 +00:00
|
|
|
int i;
|
|
|
|
for(i=0; i<3; i++) _wind[i] = 0;
|
2001-12-01 06:22:24 +00:00
|
|
|
|
|
|
|
_integrator.setBody(&_body);
|
|
|
|
_integrator.setEnvironment(this);
|
|
|
|
|
|
|
|
// Default value of 30 Hz
|
2002-05-10 23:35:06 +00:00
|
|
|
_integrator.setInterval(1.0f/30.0f);
|
2001-12-10 23:13:54 +00:00
|
|
|
|
|
|
|
_agl = 0;
|
|
|
|
_crashed = false;
|
2004-01-09 17:05:26 +00:00
|
|
|
_turb = 0;
|
2005-02-17 10:26:14 +00:00
|
|
|
_ground_cb = new Ground();
|
|
|
|
_hook = 0;
|
|
|
|
_launchbar = 0;
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Model::~Model()
|
|
|
|
{
|
|
|
|
// FIXME: who owns these things? Need a policy
|
2005-02-17 10:26:14 +00:00
|
|
|
delete _ground_cb;
|
|
|
|
delete _hook;
|
|
|
|
delete _launchbar;
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Model::getThrust(float* out)
|
|
|
|
{
|
|
|
|
float tmp[3];
|
|
|
|
out[0] = out[1] = out[2] = 0;
|
2001-12-07 20:00:59 +00:00
|
|
|
int i;
|
|
|
|
for(i=0; i<_thrusters.size(); i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
Thruster* t = (Thruster*)_thrusters.get(i);
|
|
|
|
t->getThrust(tmp);
|
|
|
|
Math::add3(tmp, out, out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-01 01:22:27 +00:00
|
|
|
void Model::initIteration()
|
2001-12-01 06:22:24 +00:00
|
|
|
{
|
|
|
|
// Precompute torque and angular momentum for the thrusters
|
2001-12-07 20:00:59 +00:00
|
|
|
int i;
|
|
|
|
for(i=0; i<3; i++)
|
2001-12-01 06:22:24 +00:00
|
|
|
_gyro[i] = _torque[i] = 0;
|
2004-01-12 04:03:55 +00:00
|
|
|
|
|
|
|
// Need a local altitude for the wind calculation
|
2005-02-17 10:26:14 +00:00
|
|
|
float lground[4];
|
|
|
|
_s->planeGlobalToLocal(_global_ground, lground);
|
|
|
|
float alt = Math::abs(lground[3]);
|
2004-01-12 04:03:55 +00:00
|
|
|
|
2001-12-07 20:00:59 +00:00
|
|
|
for(i=0; i<_thrusters.size(); i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
Thruster* t = (Thruster*)_thrusters.get(i);
|
|
|
|
|
|
|
|
// Get the wind velocity at the thruster location
|
|
|
|
float pos[3], v[3];
|
|
|
|
t->getPosition(pos);
|
2004-01-12 04:03:55 +00:00
|
|
|
localWind(pos, _s, v, alt);
|
2001-12-01 06:22:24 +00:00
|
|
|
|
|
|
|
t->setWind(v);
|
2002-06-10 08:47:29 +00:00
|
|
|
t->setAir(_pressure, _temp, _rho);
|
2001-12-01 06:22:24 +00:00
|
|
|
t->integrate(_integrator.getInterval());
|
|
|
|
|
|
|
|
t->getTorque(v);
|
|
|
|
Math::add3(v, _torque, _torque);
|
|
|
|
|
|
|
|
t->getGyro(v);
|
|
|
|
Math::add3(v, _gyro, _gyro);
|
|
|
|
}
|
2004-01-10 22:34:49 +00:00
|
|
|
|
|
|
|
// Displace the turbulence coordinates according to the local wind.
|
|
|
|
if(_turb) {
|
|
|
|
float toff[3];
|
|
|
|
Math::mul3(_integrator.getInterval(), _wind, toff);
|
|
|
|
_turb->offset(toff);
|
|
|
|
}
|
2005-02-17 10:26:14 +00:00
|
|
|
|
|
|
|
|
2003-12-01 01:22:27 +00:00
|
|
|
}
|
2003-10-16 14:56:13 +00:00
|
|
|
|
2003-12-01 01:22:27 +00:00
|
|
|
// FIXME: This method looks to me like it's doing *integration*, not
|
|
|
|
// initialization. Integration code should ideally go into
|
|
|
|
// calcForces. Only very "unstiff" problems can be solved well like
|
|
|
|
// this (see the engine code for an example); I don't know if rotor
|
|
|
|
// dynamics qualify or not.
|
|
|
|
// -Andy
|
|
|
|
void Model::initRotorIteration()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float dt = _integrator.getInterval();
|
2003-10-16 14:56:13 +00:00
|
|
|
float lrot[3];
|
|
|
|
Math::vmul33(_s->orient, _s->rot, lrot);
|
|
|
|
Math::mul3(dt,lrot,lrot);
|
|
|
|
for(i=0; i<_rotors.size(); i++) {
|
|
|
|
Rotor* r = (Rotor*)_rotors.get(i);
|
|
|
|
r->inititeration(dt);
|
|
|
|
}
|
|
|
|
for(i=0; i<_rotorparts.size(); i++) {
|
|
|
|
Rotorpart* rp = (Rotorpart*)_rotorparts.get(i);
|
|
|
|
rp->inititeration(dt,lrot);
|
|
|
|
}
|
|
|
|
for(i=0; i<_rotorblades.size(); i++) {
|
|
|
|
Rotorblade* rp = (Rotorblade*)_rotorblades.get(i);
|
|
|
|
rp->inititeration(dt,lrot);
|
|
|
|
}
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
|
|
|
|
2003-12-01 01:22:27 +00:00
|
|
|
void Model::iterate()
|
2001-12-01 06:22:24 +00:00
|
|
|
{
|
2003-12-01 01:22:27 +00:00
|
|
|
initIteration();
|
|
|
|
initRotorIteration();
|
2001-12-01 06:22:24 +00:00
|
|
|
_body.recalc(); // FIXME: amortize this, somehow
|
|
|
|
_integrator.calcNewInterval();
|
|
|
|
}
|
|
|
|
|
2001-12-10 23:13:54 +00:00
|
|
|
bool Model::isCrashed()
|
|
|
|
{
|
|
|
|
return _crashed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::setCrashed(bool crashed)
|
|
|
|
{
|
|
|
|
_crashed = crashed;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Model::getAGL()
|
|
|
|
{
|
|
|
|
return _agl;
|
|
|
|
}
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
State* Model::getState()
|
|
|
|
{
|
|
|
|
return _s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::setState(State* s)
|
|
|
|
{
|
|
|
|
_integrator.setState(s);
|
|
|
|
_s = _integrator.getState();
|
|
|
|
}
|
|
|
|
|
|
|
|
RigidBody* Model::getBody()
|
|
|
|
{
|
|
|
|
return &_body;
|
|
|
|
}
|
|
|
|
|
|
|
|
Integrator* Model::getIntegrator()
|
|
|
|
{
|
|
|
|
return &_integrator;
|
|
|
|
}
|
|
|
|
|
|
|
|
Surface* Model::getSurface(int handle)
|
|
|
|
{
|
|
|
|
return (Surface*)_surfaces.get(handle);
|
|
|
|
}
|
|
|
|
|
2003-10-16 14:56:13 +00:00
|
|
|
Rotorpart* Model::getRotorpart(int handle)
|
|
|
|
{
|
|
|
|
return (Rotorpart*)_rotorparts.get(handle);
|
|
|
|
}
|
|
|
|
Rotorblade* Model::getRotorblade(int handle)
|
|
|
|
{
|
|
|
|
return (Rotorblade*)_rotorblades.get(handle);
|
|
|
|
}
|
|
|
|
Rotor* Model::getRotor(int handle)
|
|
|
|
{
|
|
|
|
return (Rotor*)_rotors.get(handle);
|
|
|
|
}
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
int Model::addThruster(Thruster* t)
|
|
|
|
{
|
|
|
|
return _thrusters.add(t);
|
|
|
|
}
|
|
|
|
|
2005-02-17 10:26:14 +00:00
|
|
|
Hook* Model::getHook(void)
|
|
|
|
{
|
|
|
|
return _hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
Launchbar* Model::getLaunchbar(void)
|
|
|
|
{
|
|
|
|
return _launchbar;
|
|
|
|
}
|
|
|
|
|
2001-12-06 18:13:24 +00:00
|
|
|
int Model::numThrusters()
|
|
|
|
{
|
|
|
|
return _thrusters.size();
|
|
|
|
}
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
Thruster* Model::getThruster(int handle)
|
|
|
|
{
|
|
|
|
return (Thruster*)_thrusters.get(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::setThruster(int handle, Thruster* t)
|
|
|
|
{
|
|
|
|
_thrusters.set(handle, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Model::addSurface(Surface* surf)
|
|
|
|
{
|
|
|
|
return _surfaces.add(surf);
|
|
|
|
}
|
|
|
|
|
2003-10-16 14:56:13 +00:00
|
|
|
int Model::addRotorpart(Rotorpart* rpart)
|
|
|
|
{
|
|
|
|
return _rotorparts.add(rpart);
|
|
|
|
}
|
|
|
|
int Model::addRotorblade(Rotorblade* rblade)
|
|
|
|
{
|
|
|
|
return _rotorblades.add(rblade);
|
|
|
|
}
|
|
|
|
int Model::addRotor(Rotor* r)
|
|
|
|
{
|
|
|
|
return _rotors.add(r);
|
|
|
|
}
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
int Model::addGear(Gear* gear)
|
|
|
|
{
|
|
|
|
return _gears.add(gear);
|
|
|
|
}
|
|
|
|
|
2005-02-17 10:26:14 +00:00
|
|
|
void Model::addHook(Hook* hook)
|
|
|
|
{
|
|
|
|
_hook = hook;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::addLaunchbar(Launchbar* launchbar)
|
|
|
|
{
|
|
|
|
_launchbar = launchbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Model::setGroundCallback(Ground* ground_cb)
|
|
|
|
{
|
|
|
|
delete _ground_cb;
|
|
|
|
_ground_cb = ground_cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ground* Model::getGroundCallback(void)
|
|
|
|
{
|
|
|
|
return _ground_cb;
|
|
|
|
}
|
|
|
|
|
2001-12-06 18:13:24 +00:00
|
|
|
void Model::setGroundEffect(float* pos, float span, float mul)
|
|
|
|
{
|
|
|
|
Math::set3(pos, _wingCenter);
|
|
|
|
_groundEffectSpan = span;
|
|
|
|
_groundEffect = mul;
|
|
|
|
}
|
|
|
|
|
2002-06-10 08:47:29 +00:00
|
|
|
void Model::setAir(float pressure, float temp, float density)
|
2001-12-01 06:22:24 +00:00
|
|
|
{
|
2001-12-07 20:00:59 +00:00
|
|
|
_pressure = pressure;
|
|
|
|
_temp = temp;
|
2002-06-10 08:47:29 +00:00
|
|
|
_rho = density;
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Model::setWind(float* wind)
|
|
|
|
{
|
|
|
|
Math::set3(wind, _wind);
|
|
|
|
}
|
|
|
|
|
2005-02-17 10:26:14 +00:00
|
|
|
void Model::updateGround(State* s)
|
|
|
|
{
|
|
|
|
float dummy[3];
|
|
|
|
_ground_cb->getGroundPlane(s->pos, _global_ground, dummy);
|
|
|
|
|
|
|
|
int i;
|
|
|
|
// The landing gear
|
|
|
|
for(i=0; i<_gears.size(); i++) {
|
|
|
|
Gear* g = (Gear*)_gears.get(i);
|
|
|
|
|
|
|
|
// Get the point of ground contact
|
|
|
|
float pos[3], cmpr[3];
|
|
|
|
g->getPosition(pos);
|
|
|
|
g->getCompression(cmpr);
|
|
|
|
|
|
|
|
Math::mul3(g->getCompressFraction(), cmpr, cmpr);
|
|
|
|
Math::add3(cmpr, pos, pos);
|
|
|
|
// Transform the local coordinates of the contact point to
|
|
|
|
// global coordinates.
|
|
|
|
double pt[3];
|
|
|
|
s->posLocalToGlobal(pos, pt);
|
|
|
|
|
|
|
|
// Ask for the ground plane in the global coordinate system
|
|
|
|
double global_ground[4];
|
|
|
|
float global_vel[3];
|
|
|
|
_ground_cb->getGroundPlane(pt, global_ground, global_vel);
|
|
|
|
g->setGlobalGround(global_ground, global_vel);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The arrester hook
|
|
|
|
if(_hook) {
|
|
|
|
double pt[3];
|
|
|
|
_hook->getTipGlobalPosition(s, pt);
|
|
|
|
double global_ground[4];
|
|
|
|
_ground_cb->getGroundPlane(pt, global_ground, dummy);
|
|
|
|
_hook->setGlobalGround(global_ground);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The launchbar/holdback
|
|
|
|
if(_launchbar) {
|
|
|
|
double pt[3];
|
|
|
|
_launchbar->getTipGlobalPosition(s, pt);
|
|
|
|
double global_ground[4];
|
|
|
|
_ground_cb->getGroundPlane(pt, global_ground, dummy);
|
|
|
|
_launchbar->setGlobalGround(global_ground);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
void Model::calcForces(State* s)
|
|
|
|
{
|
|
|
|
// Add in the pre-computed stuff. These values aren't part of the
|
|
|
|
// Runge-Kutta integration (they don't depend on position or
|
|
|
|
// velocity), and are therefore constant across the four calls to
|
|
|
|
// calcForces. They get computed before we begin the integration
|
|
|
|
// step.
|
|
|
|
_body.setGyro(_gyro);
|
|
|
|
_body.addTorque(_torque);
|
2001-12-07 20:00:59 +00:00
|
|
|
int i;
|
|
|
|
for(i=0; i<_thrusters.size(); i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
Thruster* t = (Thruster*)_thrusters.get(i);
|
|
|
|
float thrust[3], pos[3];
|
|
|
|
t->getThrust(thrust);
|
|
|
|
t->getPosition(pos);
|
|
|
|
_body.addForce(pos, thrust);
|
|
|
|
}
|
|
|
|
|
2004-01-12 04:03:55 +00:00
|
|
|
// Get a ground plane in local coordinates. The first three
|
|
|
|
// elements are the normal vector, the final one is the distance
|
|
|
|
// from the local origin along that vector to the ground plane
|
|
|
|
// (negative for objects "above" the ground)
|
|
|
|
float ground[4];
|
2005-02-17 10:26:14 +00:00
|
|
|
s->planeGlobalToLocal(_global_ground, ground);
|
2004-01-12 04:03:55 +00:00
|
|
|
float alt = Math::abs(ground[3]);
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
// Gravity, convert to a force, then to local coordinates
|
|
|
|
float grav[3];
|
|
|
|
Glue::geodUp(s->pos, grav);
|
2002-05-10 23:35:06 +00:00
|
|
|
Math::mul3(-9.8f * _body.getTotalMass(), grav, grav);
|
2001-12-01 06:22:24 +00:00
|
|
|
Math::vmul33(s->orient, grav, grav);
|
|
|
|
_body.addForce(grav);
|
|
|
|
|
|
|
|
// Do each surface, remembering that the local velocity at each
|
|
|
|
// point is different due to rotation.
|
2001-12-06 18:13:24 +00:00
|
|
|
float faero[3];
|
|
|
|
faero[0] = faero[1] = faero[2] = 0;
|
2001-12-07 20:00:59 +00:00
|
|
|
for(i=0; i<_surfaces.size(); i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
Surface* sf = (Surface*)_surfaces.get(i);
|
|
|
|
|
|
|
|
// Vsurf = wind - velocity + (rot cross (cg - pos))
|
|
|
|
float vs[3], pos[3];
|
|
|
|
sf->getPosition(pos);
|
2004-01-12 04:03:55 +00:00
|
|
|
localWind(pos, s, vs, alt);
|
2001-12-01 06:22:24 +00:00
|
|
|
|
|
|
|
float force[3], torque[3];
|
|
|
|
sf->calcForce(vs, _rho, force, torque);
|
2001-12-06 18:13:24 +00:00
|
|
|
Math::add3(faero, force, faero);
|
2003-10-16 14:56:13 +00:00
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
_body.addForce(pos, force);
|
|
|
|
_body.addTorque(torque);
|
|
|
|
}
|
2003-10-16 14:56:13 +00:00
|
|
|
for(i=0; i<_rotorparts.size(); i++) {
|
|
|
|
Rotorpart* sf = (Rotorpart*)_rotorparts.get(i);
|
|
|
|
|
|
|
|
// Vsurf = wind - velocity + (rot cross (cg - pos))
|
|
|
|
float vs[3], pos[3];
|
|
|
|
sf->getPosition(pos);
|
2004-01-12 04:03:55 +00:00
|
|
|
localWind(pos, s, vs, alt);
|
2003-10-16 14:56:13 +00:00
|
|
|
|
|
|
|
float force[3], torque[3];
|
|
|
|
sf->calcForce(vs, _rho, force, torque);
|
|
|
|
//Math::add3(faero, force, faero);
|
|
|
|
|
|
|
|
sf->getPositionForceAttac(pos);
|
|
|
|
|
|
|
|
_body.addForce(pos, force);
|
|
|
|
_body.addTorque(torque);
|
|
|
|
}
|
|
|
|
for(i=0; i<_rotorblades.size(); i++) {
|
|
|
|
Rotorblade* sf = (Rotorblade*)_rotorblades.get(i);
|
|
|
|
|
|
|
|
// Vsurf = wind - velocity + (rot cross (cg - pos))
|
|
|
|
float vs[3], pos[3];
|
|
|
|
sf->getPosition(pos);
|
2004-01-12 04:03:55 +00:00
|
|
|
localWind(pos, s, vs, alt);
|
2003-10-16 14:56:13 +00:00
|
|
|
|
|
|
|
float force[3], torque[3];
|
|
|
|
sf->calcForce(vs, _rho, force, torque);
|
|
|
|
//Math::add3(faero, force, faero);
|
|
|
|
|
|
|
|
sf->getPositionForceAttac(pos);
|
|
|
|
|
|
|
|
_body.addForce(pos, force);
|
|
|
|
_body.addTorque(torque);
|
|
|
|
}
|
2001-12-01 06:22:24 +00:00
|
|
|
|
2001-12-06 18:13:24 +00:00
|
|
|
// Account for ground effect by multiplying the vertical force
|
|
|
|
// component by an amount linear with the fraction of the wingspan
|
|
|
|
// above the ground.
|
2002-05-01 01:17:33 +00:00
|
|
|
float dist = ground[3] - Math::dot3(ground, _wingCenter);
|
2001-12-06 18:13:24 +00:00
|
|
|
if(dist > 0 && dist < _groundEffectSpan) {
|
|
|
|
float fz = Math::dot3(faero, ground);
|
2002-11-05 21:36:47 +00:00
|
|
|
fz *= (_groundEffectSpan - dist) / _groundEffectSpan;
|
|
|
|
fz *= _groundEffect;
|
|
|
|
Math::mul3(fz, ground, faero);
|
2001-12-06 18:13:24 +00:00
|
|
|
_body.addForce(faero);
|
|
|
|
}
|
|
|
|
|
2001-12-01 06:22:24 +00:00
|
|
|
// Convert the velocity and rotation vectors to local coordinates
|
|
|
|
float lrot[3], lv[3];
|
|
|
|
Math::vmul33(s->orient, s->rot, lrot);
|
|
|
|
Math::vmul33(s->orient, s->v, lv);
|
|
|
|
|
|
|
|
// The landing gear
|
2001-12-07 20:00:59 +00:00
|
|
|
for(i=0; i<_gears.size(); i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
float force[3], contact[3];
|
|
|
|
Gear* g = (Gear*)_gears.get(i);
|
2005-02-17 10:26:14 +00:00
|
|
|
|
|
|
|
g->calcForce(&_body, s, lv, lrot);
|
2001-12-01 06:22:24 +00:00
|
|
|
g->getForce(force, contact);
|
|
|
|
_body.addForce(contact, force);
|
|
|
|
}
|
2005-02-17 10:26:14 +00:00
|
|
|
|
|
|
|
// The arrester hook
|
|
|
|
if(_hook) {
|
|
|
|
float v[3], rot[3], glvel[3], ground[3];
|
|
|
|
_hook->calcForce(_ground_cb, &_body, s, lv, lrot);
|
|
|
|
float force[3], contact[3];
|
|
|
|
_hook->getForce(force, contact);
|
|
|
|
_body.addForce(contact, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The launchbar/holdback
|
|
|
|
if(_launchbar) {
|
|
|
|
float v[3], rot[3], glvel[3], ground[3];
|
|
|
|
_launchbar->calcForce(_ground_cb, &_body, s, lv, lrot);
|
2006-03-01 22:59:58 +00:00
|
|
|
float forcelb[3], contactlb[3], forcehb[3], contacthb[3];
|
|
|
|
_launchbar->getForce(forcelb, contactlb, forcehb, contacthb);
|
|
|
|
_body.addForce(contactlb, forcelb);
|
|
|
|
_body.addForce(contacthb, forcehb);
|
2005-02-17 10:26:14 +00:00
|
|
|
}
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Model::newState(State* s)
|
|
|
|
{
|
|
|
|
_s = s;
|
|
|
|
|
|
|
|
// Some simple collision detection
|
2001-12-10 23:13:54 +00:00
|
|
|
float min = 1e8;
|
2001-12-07 20:00:59 +00:00
|
|
|
int i;
|
|
|
|
for(i=0; i<_gears.size(); i++) {
|
2001-12-01 06:22:24 +00:00
|
|
|
Gear* g = (Gear*)_gears.get(i);
|
2001-12-10 23:13:54 +00:00
|
|
|
|
|
|
|
// Get the point of ground contact
|
2005-02-17 10:26:14 +00:00
|
|
|
float pos[3], cmpr[3];
|
2001-12-01 06:22:24 +00:00
|
|
|
g->getPosition(pos);
|
|
|
|
g->getCompression(cmpr);
|
2001-12-10 23:13:54 +00:00
|
|
|
Math::mul3(g->getCompressFraction(), cmpr, cmpr);
|
2001-12-01 06:22:24 +00:00
|
|
|
Math::add3(cmpr, pos, pos);
|
2005-02-17 10:26:14 +00:00
|
|
|
|
|
|
|
// The plane transformed to local coordinates.
|
|
|
|
double global_ground[4];
|
|
|
|
g->getGlobalGround(global_ground);
|
|
|
|
float ground[4];
|
|
|
|
s->planeGlobalToLocal(global_ground, ground);
|
2001-12-01 06:22:24 +00:00
|
|
|
float dist = ground[3] - Math::dot3(pos, ground);
|
2001-12-10 23:13:54 +00:00
|
|
|
|
|
|
|
// Find the lowest one
|
|
|
|
if(dist < min)
|
|
|
|
min = dist;
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
2001-12-10 23:13:54 +00:00
|
|
|
_agl = min;
|
|
|
|
if(_agl < -1) // Allow for some integration slop
|
|
|
|
_crashed = true;
|
2001-12-01 06:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculates the airflow direction at the given point and for the
|
|
|
|
// specified aircraft velocity.
|
2004-01-12 04:03:55 +00:00
|
|
|
void Model::localWind(float* pos, State* s, float* out, float alt)
|
2001-12-01 06:22:24 +00:00
|
|
|
{
|
2004-01-09 17:05:26 +00:00
|
|
|
float tmp[3], lwind[3], lrot[3], lv[3];
|
|
|
|
|
|
|
|
// Get a global coordinate for our local position, and calculate
|
|
|
|
// turbulence.
|
|
|
|
if(_turb) {
|
2004-01-12 04:03:55 +00:00
|
|
|
double gpos[3]; float up[3];
|
2004-01-09 17:05:26 +00:00
|
|
|
Math::tmul33(s->orient, pos, tmp);
|
2004-01-12 04:03:55 +00:00
|
|
|
for(int i=0; i<3; i++) {
|
|
|
|
gpos[i] = s->pos[i] + tmp[i];
|
|
|
|
}
|
2005-02-17 10:26:14 +00:00
|
|
|
Glue::geodUp(gpos, up);
|
2004-01-12 04:03:55 +00:00
|
|
|
_turb->getTurbulence(gpos, alt, up, lwind);
|
2004-01-09 17:05:26 +00:00
|
|
|
Math::add3(_wind, lwind, lwind);
|
|
|
|
} else {
|
|
|
|
Math::set3(_wind, lwind);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert to local coordinates
|
|
|
|
Math::vmul33(s->orient, lwind, lwind);
|
2001-12-01 06:22:24 +00:00
|
|
|
Math::vmul33(s->orient, s->rot, lrot);
|
|
|
|
Math::vmul33(s->orient, s->v, lv);
|
|
|
|
|
|
|
|
_body.pointVelocity(pos, lrot, out); // rotational velocity
|
|
|
|
Math::mul3(-1, out, out); // (negated)
|
|
|
|
Math::add3(lwind, out, out); // + wind
|
|
|
|
Math::sub3(out, lv, out); // - velocity
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // namespace yasim
|