Add Vector3::up() and ::down() constants (#3021)

This commit is contained in:
Gamemechanic
2025-05-09 23:40:03 +02:00
committed by GitHub
parent 7fd712a727
commit a6a074e86b
6 changed files with 28 additions and 24 deletions
+2 -3
View File
@@ -750,8 +750,7 @@ namespace MMAP
/// Check every map vertice
// x, y * -1
Vector3 up(0, 0, 1);
for (vector<GroupModel>::iterator it = groupModels.begin(); it != groupModels.end(); ++it)
for (int t = 0; t < mapVertsCount / 3; ++t)
{
@@ -764,7 +763,7 @@ namespace MMAP
float outDist = -1.0f;
float inDist = -1.0f;
if (it->IsUnderObject(v, up, isM2, &outDist, &inDist)) // inDist < outDist
if (it->IsUnderObject(v, Vector3::up(), isM2, &outDist, &inDist)) // inDist < outDist
{
//if there are less than 5.0y between terrain and model then mark the terrain as unwalkable
if (inDist < 5.0f)
+8 -6
View File
@@ -236,13 +236,13 @@ public:
*/
inline Vector3 directionOrZero() const {
float mag = magnitude();
if (mag < 0.0000001f) {
if (mag < 0.0000001f)
return Vector3::zero();
} else if (mag < 1.00001f && mag > 0.99999f) {
if (mag < 1.00001f && mag > 0.99999f)
return *this;
} else {
return *this * (1.0f / mag);
}
return *this * (1.0f / mag);
}
/**
@@ -424,6 +424,8 @@ public:
static const Vector3& unitZ();
static const Vector3& inf();
static const Vector3& nan();
static const Vector3& up();
static const Vector3& down();
/** Smallest (most negative) representable vector */
static const Vector3& minFinite();
@@ -597,7 +599,7 @@ std::ostream& operator<<(std::ostream& os, const Vector3&);
void serialize(const Vector3::Axis& a, class BinaryOutput& bo);
void deserialize(Vector3::Axis& a, class BinaryInput& bo);
void deserialize(Vector3::Axis& a, class BinaryInput& bi);
//----------------------------------------------------------------------------
+13 -9
View File
@@ -102,7 +102,7 @@ Any Vector3::toAny(const std::string& name) const {
return any;
}
Vector3::Vector3(const class Color3& v) : x(v.r), y(v.g), z(v.b) {}
Vector3::Vector3(const class Color3& c) : x(c.r), y(c.g), z(c.b) {}
Vector3::Vector3(const class Vector3int32& v) : x((float)v.x), y((float)v.y), z((float)v.z) {}
@@ -116,11 +116,13 @@ Vector3& Vector3::ignore() {
return v;
}
const Vector3& Vector3::zero() { static const Vector3 v(0, 0, 0); return v; }
const Vector3& Vector3::zero() { static const Vector3 v(0, 0, 0); return v; }
const Vector3& Vector3::one() { static const Vector3 v(1, 1, 1); return v; }
const Vector3& Vector3::unitX() { static const Vector3 v(1, 0, 0); return v; }
const Vector3& Vector3::unitY() { static const Vector3 v(0, 1, 0); return v; }
const Vector3& Vector3::unitZ() { static const Vector3 v(0, 0, 1); return v; }
const Vector3& Vector3::up() { return unitZ(); }
const Vector3& Vector3::down() { static const Vector3 v(0, 0, -1); return v; }
const Vector3& Vector3::inf() { static const Vector3 v((float)G3D::finf(), (float)G3D::finf(), (float)G3D::finf()); return v; }
const Vector3& Vector3::nan() { static const Vector3 v((float)G3D::fnan(), (float)G3D::fnan(), (float)G3D::fnan()); return v; }
const Vector3& Vector3::minFinite(){ static const Vector3 v(-FLT_MAX, -FLT_MAX, -FLT_MAX); return v; }
@@ -303,11 +305,11 @@ Vector3 Vector3::cosPowHemiRandom(const Vector3& normal, const float k, Random&
Vector3 Vector3::hemiRandom(const Vector3& normal, Random& r) {
const Vector3& V = Vector3::random(r);
if (V.dot(normal) < 0) {
if (V.dot(normal) < 0)
return -V;
} else {
return V;
}
return V;
}
//----------------------------------------------------------------------------
@@ -345,12 +347,14 @@ Vector3 Vector3::refractionDirection(
float det = 1.0f - (float)square(hRatio) * (1.0f - (float)square(WdotN));
if (det < 0) {
if (det < 0)
{
// Total internal reflection
return Vector3::zero();
} else {
return -hRatio * (W - WdotN * N) - N * sqrt(det);
}
return -hRatio * (W - WdotN * N) - N * sqrt(det);
}
//----------------------------------------------------------------------------
+2 -2
View File
@@ -292,7 +292,7 @@ bool DynamicMapTree::isInLineOfSight(float x1, float y1, float z1, float x2, flo
float DynamicMapTree::getHeight(float x, float y, float z, float maxSearchDist) const
{
Vector3 v(x, y, z);
G3D::Ray r(v, Vector3(0, 0, -1));
G3D::Ray r(v, Vector3::down());
DynamicTreeIntersectionCallback callback;
impl.intersectZAllignedRay(r, callback, maxSearchDist);
@@ -312,4 +312,4 @@ GameObjectModel const* DynamicMapTree::getObjectHit(Vector3 const& pPos1, Vector
if (callback.hitObj)
return callback.hitObj;
return nullptr;
}
}
+2 -2
View File
@@ -276,9 +276,9 @@ namespace VMAP
float height = G3D::inf();
Vector3 dir;
if (maxSearchDist >= 0.f)
dir = Vector3(0, 0, -1);
dir = Vector3::down();
else
dir = Vector3(0, 0, 1);
dir = Vector3::up();
G3D::Ray ray(pPos, dir); // direction with length of 1
float maxDist = std::abs(maxSearchDist);
if (getIntersectionTime(ray, maxDist, false, false))
+1 -2
View File
@@ -115,9 +115,8 @@ namespace VMAP
else if (!iBound.contains(p))
return false;
// child bounds are defined in object space:
Vector3 up(0, 0, 1);
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
up = iInvRot * up * iInvScale;
Vector3 up = iInvRot * Vector3::up() * iInvScale;
return iModel->IsUnderObject(pModel, up, flags & MOD_M2, outDist, inDist);
}