mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
[xswiftbus] Set maximum draw distance for labels
This commit is contained in:
@@ -897,6 +897,7 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
void CTraffic::Labels::draw()
|
void CTraffic::Labels::draw()
|
||||||
{
|
{
|
||||||
|
static const double maxRangeM = 10000;
|
||||||
static const double metersPerFt = 0.3048;
|
static const double metersPerFt = 0.3048;
|
||||||
static float color[3]{ 1.0f, 0.75f, 0.0f };
|
static float color[3]{ 1.0f, 0.75f, 0.0f };
|
||||||
std::array<float, 16> worldMat = m_worldMat.getAll();
|
std::array<float, 16> worldMat = m_worldMat.getAll();
|
||||||
@@ -915,6 +916,7 @@ namespace XSwiftBus
|
|||||||
double localPos[4]{};
|
double localPos[4]{};
|
||||||
double windowPos[4]{};
|
double windowPos[4]{};
|
||||||
XPLMWorldToLocal(planePos.lat, planePos.lon, planePos.elevation * metersPerFt, &worldPos[0], &worldPos[1], &worldPos[2]);
|
XPLMWorldToLocal(planePos.lat, planePos.lon, planePos.elevation * metersPerFt, &worldPos[0], &worldPos[1], &worldPos[2]);
|
||||||
|
if (distanceSquared(worldPos) > maxRangeM * maxRangeM) { continue; }
|
||||||
matrixMultVec(localPos, worldMat.data(), worldPos);
|
matrixMultVec(localPos, worldMat.data(), worldPos);
|
||||||
matrixMultVec(windowPos, projMat.data(), localPos);
|
matrixMultVec(windowPos, projMat.data(), localPos);
|
||||||
|
|
||||||
@@ -942,6 +944,14 @@ namespace XSwiftBus
|
|||||||
out[3] = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15];
|
out[3] = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double CTraffic::Labels::distanceSquared(const double pos[3]) const
|
||||||
|
{
|
||||||
|
const double dx = m_viewX.get() - pos[0];
|
||||||
|
const double dy = m_viewY.get() - pos[1];
|
||||||
|
const double dz = m_viewZ.get() - pos[2];
|
||||||
|
return dx * dx + dy * dy + dz * dz;
|
||||||
|
}
|
||||||
|
|
||||||
int CTraffic::orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon)
|
int CTraffic::orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon)
|
||||||
{
|
{
|
||||||
constexpr bool DEBUG = false;
|
constexpr bool DEBUG = false;
|
||||||
|
|||||||
@@ -198,12 +198,16 @@ namespace XSwiftBus
|
|||||||
virtual void draw() override;
|
virtual void draw() override;
|
||||||
private:
|
private:
|
||||||
static void matrixMultVec(double out[4], const float m[16], const double v[4]);
|
static void matrixMultVec(double out[4], const float m[16], const double v[4]);
|
||||||
|
double distanceSquared(const double pos[3]) const;
|
||||||
CTraffic *m_traffic = nullptr;
|
CTraffic *m_traffic = nullptr;
|
||||||
ArrayDataRef<xplane::data::sim::graphics::view::world_matrix> m_worldMat;
|
ArrayDataRef<xplane::data::sim::graphics::view::world_matrix> m_worldMat;
|
||||||
ArrayDataRef<xplane::data::sim::graphics::view::projection_matrix_3d> m_projMat;
|
ArrayDataRef<xplane::data::sim::graphics::view::projection_matrix_3d> m_projMat;
|
||||||
DataRef<xplane::data::sim::graphics::view::window_width> m_windowWidth;
|
DataRef<xplane::data::sim::graphics::view::window_width> m_windowWidth;
|
||||||
DataRef<xplane::data::sim::graphics::view::window_height> m_windowHeight;
|
DataRef<xplane::data::sim::graphics::view::window_height> m_windowHeight;
|
||||||
DataRef<xplane::data::sim::graphics::view::visibility_effective_m> m_visibilityM;
|
DataRef<xplane::data::sim::graphics::view::visibility_effective_m> m_visibilityM;
|
||||||
|
DataRef<xplane::data::sim::graphics::view::view_x> m_viewX;
|
||||||
|
DataRef<xplane::data::sim::graphics::view::view_y> m_viewY;
|
||||||
|
DataRef<xplane::data::sim::graphics::view::view_z> m_viewZ;
|
||||||
};
|
};
|
||||||
Labels m_labels { this };
|
Labels m_labels { this };
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user