SDK Question Rate of descent relative to ground

JMW

Aspiring Addon Developer
Joined
Aug 5, 2008
Messages
670
Reaction score
89
Points
43
Location
Happy Wherever
Hi.
With the introduction of the beautiful Beta, how can I calculate the rate of acceleration to the approaching "Ground"?
Explanation:
We now have the situation where the craft flying horizontally, is approaching a mountain. As it comes to the incline, the ground clearance reduces dramatically.
How can I calculate this "acceleration" in reduced ground clearance?
I thought it would be simply acceleration of negative vertical speed, but this isn't the case is it, because the craft's negative vertical speed is not the factor - it could be constant, but ground will be approaching at an increased rate!
Sounds simple , but I keep coming back to it not being a case of craft vertical speed.
Has got to be a comparison of samples of height to ground at two different points in time - hasn't it?
Can someone show me how that can be done please?
 
An extremely messy solution.
Code:
double alt1 = 0;
double alt2 = 0;
double dt = oapiGetSimTime ();
double dt2 = 0;
double diff3 = 0;
         alt1 = GetAltitude(ALTMODE_GROUND);
		if(dt2 == dt + 0.25)
			{alt2 = GetAltitude(ALTMODE_GROUND);}
		diff3 = (alt1 - alt2);

Help me somebody!
 
Code:
double alt1 = 0;
double alt2 = 0;
double dt = oapiGetSimTime ();
double dt2 = 0;
double diff3 = 0;
         alt1 = GetAltitude(ALTMODE_GROUND);
		if(dt2 == dt + 0.25)
			{alt2 = GetAltitude(ALTMODE_GROUND);}
		diff3 = (alt1 - alt2);
If I read that correctly, you're trying to get the altitude every .25 sim seconds, and get acceleration from there?

However, your post title is "Rate of descent with regard to ground", so I'll answer that.
In the current code, as you never store something in dt2, that will never work. To get the ground's "vertical velocity", just run this function from preStep or postStep (not sure which, you'd have to check with someone else)

Code:
//class var/global vars, depending on how you specifically implement it
double oldAlt = 0;
double groundVelocity = 0;
void getGroundVelocity(double simDt) //use the simDt variable from pre/postStep
{
  double alt = GetAltitude(ALTMODE_GROUND);
  groundVelocity = (alt - oldAlt) / simDt;
  oldAlt = alt;
}
That code updates the velocity every simulation step, which will be a much smoother approximation of ground velocity.

Now, to get vertical speed relative to the ground, just add groundVelocity and the ship's vertical velocity.

Of course, if you want to get acceleration, just do another function, fed from the getGroundVelocity function. For example:
Code:
double oldVel = 0;
double groundAcc = 0;
void getGroundAcc(double simDt)
{
  double vel = getGroundVelocity(simDt);
  groundAcc = (vel - oldVel) / simDt;
  oldVel = vel;
}
 
Sorry I got it wrong....
 
Last edited:
Why are you not using "GetHorizonAirspeedVector"?

8.51.3.75 bool VESSEL::GetHorizonAirspeedVector (VECTOR3 & v) const
Returns the airspeed vector in local horizon coordinates.
Parameters:
! v airspeed vector on exit [m/s]
Returns:
false indicates error
Note:
This method returns the airspeed vector in the reference frame of the local horizon. x = longitudinal
component, y = vertical component, z = latitudinal component.
See also:
GetAirspeed, GetShipAirspeedVector
 
Why are you not using "GetHorizonAirspeedVector"?
Perhaps because GetHorizonAirspeedVector won't show a descent if you're flying level but the ground is coming up to meet you, and they want to do that?
 
How can I calculate this "acceleration" in reduced ground clearance?

The acceleration is infinite.

Keep in mind that the ground beneath is not continuous but is instead broken up into triangles. Each triangle is flat, but the change from one to the other is abrupt.

What you can calculate is the velocity before transition to the new triangle and after.

to find the transition, you can find the acceleration of the vessel in horizontal coordinate system and take the vertical component of it (y component). If the change of vertical velocity between previous frame and this roughly matches (there will be numerical errors and the acceleration itself is kinda jumpy) the Acceleration.y * DeltaTime, then you haven't crossed into the new triangle yet, or the triangle is parallel to the previous one. If you have a high difference, however, you'll know you flew over the next triangle.
 
Sorry for being off-topic, but is there a seperate SDK for the latest Orbiter Beta?
I don't have this function
Code:
GetAltitude(ALTMODE_GROUND)
in the Orbitersdk that came with the Beta download.
Thanks.
 
That's strange, its in VesselAPI.h that comes with revision 13.....?
 
Back
Top