Skip to content

Commit

Permalink
Merge branch 'orbitersim:main' into fix_410_unpredictable_precision
Browse files Browse the repository at this point in the history
  • Loading branch information
schnepe2 authored Jan 14, 2024
2 parents b23c9d7 + 1a13671 commit 496dfb6
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 28 deletions.
5 changes: 5 additions & 0 deletions OVP/D3D7Client/VVessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ void vVessel::UpdateRenderVectors()
if (logscale) len = log(len + shift) - lshift; else len *= scale;
AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(1, 0, 0), alpha, D3DRGB(1, 0.5, 0.5));
}
if ((flag & BFV_SIDEFORCE) && vessel->GetSideForceVector(F)) {
sprintf(cbuf, "SF = %fN", len = length(F));
if (logscale) len = log(len + shift) - lshift; else len *= scale;
AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(0.0392, 0.6235, 0.4941), alpha, D3DRGB(0.0392, 0.6235, 0.4941));
}
if ((flag & BFV_TOTAL) && vessel->GetForceVector(F)) {
sprintf(cbuf, "F = %fN", len = length(F));
if (logscale) len = log(len + shift) - lshift; else len *= scale;
Expand Down
10 changes: 10 additions & 0 deletions OVP/D3D9Client/VVessel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ void vVessel::RenderVectors (LPDIRECT3DDEVICE9 dev, D3D9Pad *pSkp)
if (bfvmode & BFV_LIFT) { vessel->GetLiftVector(vector); if (length(vector)>len) len = length(vector); }
if (bfvmode & BFV_TOTAL) { vessel->GetForceVector(vector); if (length(vector)>len) len = length(vector); }
if (bfvmode & BFV_TORQUE) { vessel->GetTorqueVector(vector); if (length(vector)>len) len = length(vector); }
if (bfvmode & BFV_SIDEFORCE) { vessel->GetSideForceVector(vector); if (length(vector) > len) len = length(vector); }

lscale = float(size * sclset / len);
}
Expand Down Expand Up @@ -924,6 +925,15 @@ void vVessel::RenderVectors (LPDIRECT3DDEVICE9 dev, D3D9Pad *pSkp)
RenderAxisLabel(pSkp, ptr(D3DXCOLOR(1,0,1,alpha)), vector, lscale, scale, label, bLog);
}
}

if (bfvmode & BFV_SIDEFORCE) {
vessel->GetSideForceVector(vector);
if (length(vector) > threshold) {
RenderAxisVector(pSkp, ptr(D3DXCOLOR(0.0392, 0.6235, 0.4941, alpha)), vector, lscale, scale, bLog);
sprintf_s(label, 64, "SF = %sN", value_string(length(vector)));
RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0.0392, 0.6235, 0.4941, alpha)), vector, lscale, scale, label, bLog);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Orbitersdk/include/GraphicsAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ typedef void *HDC;
#define BFV_DRAG 0x0020 ///< Show drag vector
#define BFV_TOTAL 0x0040 ///< Show total force vector
#define BFV_TORQUE 0x0080 ///< Show torque vector
#define BFV_SIDEFORCE 0x0100 ///< Show side-force vector
/// @}

/// \defgroup favflag Bit flags for frame axis vector render options
Expand Down
16 changes: 14 additions & 2 deletions Orbitersdk/include/OrbiterAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,17 @@ typedef void (*AirfoilCoeffFuncEx)(
// Contains additional parameters (calling vessel and pointer to
// user-defined data)

typedef void (*AirfoilCoeffFuncEx2)(
VESSEL* v,
VECTOR3 WindDir,
double alpha, double beta, double gamma,
double M, double Re, void* context,
double* CA, double* CN, double* CY,
double* Cl, double* Cm, double* Cn);
// Further extended version of aerodynamic coefficients callback function
// Contains additional parameters (calling vessel and pointer to
// user-defined data for all force and moment coefficients)


// ===========================================================================
/// \ingroup defines
Expand All @@ -1638,11 +1649,12 @@ typedef void (*AirfoilCoeffFuncEx)(
*
* Defines the orientation of an airfoil by the direction of the lift vector
* generated (vertical or horizontal).
* \sa VESSEL::CreateAirfoil, VESSEL::CreateAirfoil2, VESSEL::CreateAirfoil3
* \sa VESSEL::CreateAirfoil, VESSEL::CreateAirfoil2, VESSEL::CreateAirfoil3, VESSEL::CreateAirfoil4
*/
typedef enum {
LIFT_VERTICAL, ///< lift direction is vertical (e.g. elevator)
LIFT_HORIZONTAL ///< lift direction is horizontal (e.g. rudder)
LIFT_HORIZONTAL, ///< lift direction is horizontal (e.g. rudder)
FORCE_AND_MOMENT ///< complex model of forces and moments along and about all axes
} AIRFOIL_ORIENTATION;
//@}

Expand Down
56 changes: 56 additions & 0 deletions Orbitersdk/include/VesselAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,40 @@ class OAPIFUNC VESSEL {
*/
AIRFOILHANDLE CreateAirfoil3 (AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFuncEx cf, void *context, double c, double S, double A) const;

/**
* \brief Creates a new airfoil and defines its aerodynamic properties.
* \param ref centre of pressure in vessel coordinates [<b>m</b>], nominally this shoud be at the CoM.
* \param cf pointer to coefficient callback function (see notes)
* \param context pointer to data block passed to cf callback function
* \param c airfoil chord length [m]
* \param S wing area [m<sup>2</sup>]
* \param A wing aspect ratio
* \return Handle for the new airfoil.
* \note This method is an extension to \ref CreateAirfoil3, using a
* more versatile coefficient callback function.
* \note AirfoilCoeffFuncEx has the following interface:
* \code
* void (*AirfoilCoeffFuncEx2)(
* VESSEL* v,
* double alpha, double beta, double gamma,
* double M, double Re, void* context,
* double* CA, double* CN, double* CY,
* double* Cl, double* Cm, double* Cn);
* \endcode
* where \e v is a pointer to the calling vessel instance, and
* \a context is the pointer passed to CreateAirfoil4. It can be
* used to make available to the callback function any additional
* parameters required to calculate the lift and drag coefficients.
* The coefficients: CA, CN, and CY are force coefficients along the
* vessel's Z, Y, and X body axes respectively.
* The coefficients: Cl, Cm, and Cn are moment coefficients about the
* vessel's Z, X, and Y body axes respectively.
* All other parameters are identical to AirfoilCoeffFunc (see
* \ref CreateAirfoil).
* \sa CreateAirfoil, CreateAirfoil2, CreateAirfoil3, EditAirfoil, DelAirfoil
*/
AIRFOILHANDLE CreateAirfoil4(const VECTOR3& ref, AirfoilCoeffFuncEx2 cf, void* context, double c, double S, double A) const;

/**
* \brief Returns the parameters of an existing airfoil.
* \param [in] hAirfoil airfoil handle
Expand Down Expand Up @@ -1982,6 +2016,14 @@ class OAPIFUNC VESSEL {
*/
double GetDrag () const;

/**
* \brief Returns magnitude of aerodynamic side-force vector.
* \return Magnitude of drag force vector [N].
* \note Return value is the sum of drag components from all airfoils.
* \sa GetDragVector, GetLift
*/
double GetSideForce() const;

/**
* \brief Returns gravitational force vector in local vessel coordinates.
* \param[out] G gravitational force vector [<b>N</b>]
Expand Down Expand Up @@ -2037,6 +2079,20 @@ class OAPIFUNC VESSEL {
*/
bool GetDragVector (VECTOR3 &D) const;

/**
* \brief Returns aerodynamic side-force force vector in local vessel
* coordinates.
* \param[out] SF drag vector [<b>N</b>]
* \return false indicates zero side-force. In that case, the returned vector
* is (0,0,0).
* \note On return, SD contains the sum of Side-force components from all
* airfoils.
* \note The side-force vector is mutually orthogonal to the Lift and Drag vectors
* \sa GetDrag, GetWeightVector, GetThrustVector, GetLiftVector,
* GetForceVector
*/
bool GetSideForceVector (VECTOR3 &SF) const;

/**
* \brief Returns total force vector acting on the vessel in local
* vessel coordinates.
Expand Down
23 changes: 13 additions & 10 deletions Src/Orbiter/OptionsPages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2177,8 +2177,8 @@ const HELPCONTEXT* OptionsPage_Forces::HelpContext() const

void OptionsPage_Forces::UpdateControls(HWND hPage)
{
std::array<int, 15> residForces = {
IDC_OPT_VEC_WEIGHT, IDC_OPT_VEC_THRUST, IDC_OPT_VEC_LIFT, IDC_OPT_VEC_DRAG, IDC_OPT_VEC_TOTAL,
std::array<int, 16> residForces = {
IDC_OPT_VEC_WEIGHT, IDC_OPT_VEC_THRUST, IDC_OPT_VEC_LIFT, IDC_OPT_VEC_DRAG, IDC_OPT_VEC_SIDEFORCE, IDC_OPT_VEC_TOTAL,
IDC_OPT_VEC_TORQUE, IDC_OPT_VEC_LINSCL, IDC_OPT_VEC_LOGSCL, IDC_OPT_VEC_SCALE, IDC_OPT_VEC_OPACITY,
IDC_STATIC1, IDC_STATIC2, IDC_STATIC3, IDC_STATIC4, IDC_STATIC5
};
Expand All @@ -2193,6 +2193,7 @@ void OptionsPage_Forces::UpdateControls(HWND hPage)
SendDlgItemMessage(hPage, IDC_OPT_VEC_THRUST, BM_SETCHECK, vecFlag & BFV_THRUST ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hPage, IDC_OPT_VEC_LIFT, BM_SETCHECK, vecFlag & BFV_LIFT ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hPage, IDC_OPT_VEC_DRAG, BM_SETCHECK, vecFlag & BFV_DRAG ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hPage, IDC_OPT_VEC_SIDEFORCE, BM_SETCHECK, vecFlag & BFV_SIDEFORCE ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hPage, IDC_OPT_VEC_TOTAL, BM_SETCHECK, vecFlag & BFV_TOTAL ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hPage, IDC_OPT_VEC_TORQUE, BM_SETCHECK, vecFlag & BFV_TORQUE ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(hPage, IDC_OPT_VEC_LINSCL, BM_SETCHECK, vecFlag & BFV_LOGSCALE ? BST_UNCHECKED : BST_CHECKED, 0);
Expand Down Expand Up @@ -2227,6 +2228,7 @@ BOOL OptionsPage_Forces::OnCommand(HWND hPage, WORD ctrlId, WORD notification, H
case IDC_OPT_VEC_THRUST:
case IDC_OPT_VEC_LIFT:
case IDC_OPT_VEC_DRAG:
case IDC_OPT_VEC_SIDEFORCE:
case IDC_OPT_VEC_TOTAL:
case IDC_OPT_VEC_TORQUE:
case IDC_OPT_VEC_LINSCL:
Expand All @@ -2247,14 +2249,15 @@ void OptionsPage_Forces::OnItemClicked(HWND hPage, WORD ctrlId)
bool check = (SendDlgItemMessage(hPage, ctrlId, BM_GETCHECK, 0, 0) == TRUE);
DWORD flag;
switch (ctrlId) {
case IDC_OPT_VEC: flag = BFV_ENABLE; break;
case IDC_OPT_VEC_WEIGHT: flag = BFV_WEIGHT; break;
case IDC_OPT_VEC_THRUST: flag = BFV_THRUST; break;
case IDC_OPT_VEC_LIFT: flag = BFV_LIFT; break;
case IDC_OPT_VEC_DRAG: flag = BFV_DRAG; break;
case IDC_OPT_VEC_TOTAL: flag = BFV_TOTAL; break;
case IDC_OPT_VEC_TORQUE: flag = BFV_TORQUE; break;
case IDC_OPT_VEC_LINSCL: flag = BFV_LOGSCALE; check = false; break;
case IDC_OPT_VEC: flag = BFV_ENABLE; break;
case IDC_OPT_VEC_WEIGHT: flag = BFV_WEIGHT; break;
case IDC_OPT_VEC_THRUST: flag = BFV_THRUST; break;
case IDC_OPT_VEC_LIFT: flag = BFV_LIFT; break;
case IDC_OPT_VEC_DRAG: flag = BFV_DRAG; break;
case IDC_OPT_VEC_SIDEFORCE: flag = BFV_SIDEFORCE; break;
case IDC_OPT_VEC_TOTAL: flag = BFV_TOTAL; break;
case IDC_OPT_VEC_TORQUE: flag = BFV_TORQUE; break;
case IDC_OPT_VEC_LINSCL: flag = BFV_LOGSCALE; check = false; break;
case IDC_OPT_VEC_LOGSCL: flag = BFV_LOGSCALE; check = true; break;
default: flag = 0; break;
}
Expand Down
3 changes: 2 additions & 1 deletion Src/Orbiter/Orbiter.rc
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@ BEGIN
CONTROL "Thrust",IDC_OPT_VEC_THRUST,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,40,44,10
CONTROL "Lift",IDC_OPT_VEC_LIFT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,56,28,44,10
CONTROL "Drag",IDC_OPT_VEC_DRAG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,56,40,44,10
CONTROL "Total",IDC_OPT_VEC_TOTAL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,56,80,10
CONTROL "Side", IDC_OPT_VEC_SIDEFORCE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 56, 52, 44, 10
CONTROL "Total",IDC_OPT_VEC_TOTAL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,68,80,10
GROUPBOX "Angular moments",IDC_STATIC2,6,80,100,26
CONTROL "Torque",IDC_OPT_VEC_TORQUE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,92,80,10
GROUPBOX "Display",IDC_STATIC3,114,16,100,90
Expand Down
Loading

0 comments on commit 496dfb6

Please sign in to comment.