Skip to content

Commit

Permalink
Merge pull request pioneerspacesim#5973 from fluffyfreak/micro-tidying
Browse files Browse the repository at this point in the history
More default colours and cleanup copy-n-paste in GeoPatch
  • Loading branch information
fluffyfreak authored Nov 17, 2024
2 parents fb6e5f8 + 90ff523 commit a841814
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
5 changes: 5 additions & 0 deletions src/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const Color4f Color4f::YELLOW = Color4f(1.0f, 1.0f, 0.0f, 1.0f);
const Color4f Color4f::GRAY = Color4f(0.5f, 0.5f, 0.5f, 1.f);
const Color4f Color4f::STEELBLUE = Color4f(0.27f, 0.51f, 0.71f, 1.f);
const Color4f Color4f::BLANK = Color4f(0.0f, 0.0f, 0.0f, 0.0f);
const Color4f Color4f::PINK = Color4f(0.988f, 0.058f, 0.753f, 1.f); // debug pink
const Color4f Color4f::CYAN = Color4f(0.0f, 1.0f, 1.0f, 1.0f);

const Color4ub Color::BLACK = Color(0, 0, 0, 255);
const Color4ub Color::WHITE = Color(255, 255, 255, 255);
Expand All @@ -26,6 +28,7 @@ const Color4ub Color::GRAY = Color(128, 128, 128, 255);
const Color4ub Color::STEELBLUE = Color(68, 130, 181, 255);
const Color4ub Color::BLANK = Color(0, 0, 0, 0);
const Color4ub Color::PINK = Color(252, 15, 192, 255); // debug pink
const Color4ub Color::CYAN = Color(0, 255, 255, 255);

const Color3ub Color3ub::BLACK = Color3ub(0, 0, 0);
const Color3ub Color3ub::WHITE = Color3ub(255, 255, 255);
Expand All @@ -35,6 +38,8 @@ const Color3ub Color3ub::BLUE = Color3ub(0, 0, 255);
const Color3ub Color3ub::YELLOW = Color3ub(255, 255, 0);
const Color3ub Color3ub::STEELBLUE = Color3ub(68, 130, 181);
const Color3ub Color3ub::BLANK = Color3ub(0, 0, 0);
const Color3ub Color3ub::PINK = Color3ub(252, 15, 192); // debug pink
const Color3ub Color3ub::CYAN = Color3ub(0, 255, 255);

float Color4f::GetLuminance() const
{
Expand Down
5 changes: 5 additions & 0 deletions src/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ struct Color4f {
static const Color4f GRAY;
static const Color4f STEELBLUE;
static const Color4f BLANK;
static const Color4f PINK;
static const Color4f CYAN;
};

namespace {
Expand Down Expand Up @@ -162,6 +164,7 @@ struct Color4ub {
static const Color4ub STEELBLUE;
static const Color4ub BLANK;
static const Color4ub PINK;
static const Color4ub CYAN;
};

struct Color3ub {
Expand Down Expand Up @@ -207,6 +210,8 @@ struct Color3ub {
static const Color3ub YELLOW;
static const Color3ub STEELBLUE;
static const Color3ub BLANK;
static const Color3ub PINK;
static const Color3ub CYAN;
};

typedef Color4ub Color;
Expand Down
49 changes: 22 additions & 27 deletions src/GeoPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,13 @@ void GeoPatch::Render(Graphics::Renderer *renderer, const vector3d &campos, cons
PROFILE_SCOPED()
// must update the VBOs to calculate the clipRadius...
UpdateVBOs(renderer);
// ...before doing the furstum culling that relies on it.
// ...before doing the frustum culling that relies on it.
if (!frustum.TestPoint(m_clipCentroid, m_clipRadius))
return; // nothing below this patch is visible

// only want to horizon cull patches that can actually be over the horizon!
const vector3d camDir(campos - m_clipCentroid);
const vector3d camDirNorm(camDir.Normalized());
const vector3d cenDir(m_clipCentroid.Normalized());
const double dotProd = camDirNorm.Dot(cenDir);

if (dotProd < 0.25 && (camDir.LengthSqr() > (m_clipRadius * m_clipRadius))) {
SSphere obj;
obj.m_centre = m_clipCentroid;
obj.m_radius = m_clipRadius;

if (!s_sph.HorizonCulling(campos, obj)) {
return; // nothing below this patch is visible
}
if (IsOverHorizon(campos)) {
return;
}

if (m_kids[0]) {
Expand Down Expand Up @@ -344,19 +333,8 @@ void GeoPatch::LODUpdate(const vector3d &campos, const Graphics::Frustum &frustu
return; // nothing below this patch is visible

// only want to horizon cull patches that can actually be over the horizon!
const vector3d camDir(campos - m_clipCentroid);
const vector3d camDirNorm(camDir.Normalized());
const vector3d cenDir(m_clipCentroid.Normalized());
const double dotProd = camDirNorm.Dot(cenDir);

if (dotProd < 0.25 && (camDir.LengthSqr() > (m_clipRadius * m_clipRadius))) {
SSphere obj;
obj.m_centre = m_clipCentroid;
obj.m_radius = m_clipRadius;

if (!s_sph.HorizonCulling(campos, obj)) {
return; // nothing below this patch is visible
}
if (IsOverHorizon(campos)) {
return;
}

// we can see this patch so submit the jobs!
Expand Down Expand Up @@ -466,3 +444,20 @@ void GeoPatch::ReceiveJobHandle(Job::Handle job)
assert(!m_job.HasJob());
m_job = static_cast<Job::Handle &&>(job);
}

bool GeoPatch::IsOverHorizon(const vector3d &camPos)
{
const vector3d camDir(camPos - m_clipCentroid);
const vector3d camDirNorm(camDir.Normalized());
const vector3d cenDir(m_clipCentroid.Normalized());
const double dotProd = camDirNorm.Dot(cenDir);

if (dotProd < 0.25 && (camDir.LengthSqr() > (m_clipRadius * m_clipRadius))) {
// return the result of the Horizon Culling test, inverted to match naming semantic
// eg: HC returns true==visible, but this method returns true==hidden
return !s_sph.HorizonCulling(camPos, SSphere(m_clipCentroid, m_clipRadius));
}

// not over the horizon
return false;
}
2 changes: 2 additions & 0 deletions src/GeoPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class GeoPatch {
private:
static const int NUM_KIDS = 4;

bool IsOverHorizon(const vector3d &camPos);

RefCountedPtr<GeoPatchContext> m_ctx;
const vector3d m_v0, m_v1, m_v2, m_v3;
std::unique_ptr<double[]> m_heights;
Expand Down
8 changes: 6 additions & 2 deletions src/math/Sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ struct SSphere {
SSphere(const double rad) :
m_centre(vector3d(0.0)),
m_radius(rad) {}
vector3d m_centre;
double m_radius;
SSphere(const vector3d &centre, const double rad) :
m_centre(centre),
m_radius(rad) {}

// Adapted from Ysaneya here: http://www.gamedev.net/blog/73/entry-1666972-horizon-culling/
bool HorizonCulling(const vector3d &view, const SSphere &obj) const;

vector3d m_centre;
double m_radius;
};

#endif /* _SPHERE_H */

0 comments on commit a841814

Please sign in to comment.