MSVC Support fixes.
All checks were successful
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 1m20s

This commit is contained in:
2024-05-21 00:52:02 -07:00
parent ca2223aaee
commit 0c85b8408c
16 changed files with 62 additions and 23 deletions

View File

@@ -25,10 +25,16 @@ file(GLOB_RECURSE J3ML_SRC "src/J3ML/*.c" "src/J3ML/*.cpp")
include_directories("include") include_directories("include")
if (UNIX)
add_library(J3ML SHARED ${J3ML_SRC}) add_library(J3ML SHARED ${J3ML_SRC})
endif()
if (WIN32)
add_library(J3ML STATIC ${J3ML_SRC})
endif()
set_target_properties(J3ML PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(J3ML PROPERTIES LINKER_LANGUAGE CXX)
if(WIN32) if(WIN32)
target_compile_options(J3ML PRIVATE -Wno-multichar) #target_compile_options(J3ML PRIVATE -Wno-multichar)
endif() endif()
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
@@ -41,5 +47,5 @@ add_executable(MathDemo main.cpp)
target_link_libraries(MathDemo ${PROJECT_NAME}) target_link_libraries(MathDemo ${PROJECT_NAME})
if(WIN32) if(WIN32)
target_compile_options(MathDemo PRIVATE -mwindows) #target_compile_options(MathDemo PRIVATE -mwindows)
endif() endif()

View File

@@ -55,6 +55,6 @@ namespace J3ML::Algorithms
Vector3 offset = (Vector3::Min(ab.minPoint, bb.minPoint) + Vector3::Max(ab.maxPoint, bb.maxPoint)) * 0.5f; Vector3 offset = (Vector3::Min(ab.minPoint, bb.minPoint) + Vector3::Max(ab.maxPoint, bb.maxPoint)) * 0.5f;
const Vector3 floatingPtPrecisionOffset = -offset; const Vector3 floatingPtPrecisionOffset = -offset;
return GJLIntersect(a.Translated(floatingPtPrecisionOffset), b.Translated(floatingPtPrecisionOffset)); return GJKIntersect(a.Translated(floatingPtPrecisionOffset), b.Translated(floatingPtPrecisionOffset));
} }
} }

View File

@@ -183,9 +183,9 @@ namespace J3ML::Geometry
AABB Translated(const Vector3& offset) const; AABB Translated(const Vector3& offset) const;
void Scale(const Vector3& scale); void Scale(const Vector3& scale);
AABB Scaled(const Vector3& scale) const; AABB Scaled(const Vector3& scale) const;
AABB TransformAABB(const Matrix3x3& transform); void TransformAABB(const Matrix3x3& transform);
AABB TransformAABB(const Matrix4x4& transform); void TransformAABB(const Matrix4x4& transform);
AABB TransformAABB(const Quaternion& transform); void TransformAABB(const Quaternion& transform);
/// Applies a transformation to this AABB and returns the resulting OBB. /// Applies a transformation to this AABB and returns the resulting OBB.
/** Transforming an AABB produces an oriented bounding box. This set of functions does not apply the transformation /** Transforming an AABB produces an oriented bounding box. This set of functions does not apply the transformation
to this object itself, but instead returns the OBB that results in the transformation. to this object itself, but instead returns the OBB that results in the transformation.

View File

@@ -66,6 +66,7 @@ namespace J3ML::Geometry
@return The extreme point of this Capsule in the given direction. */ @return The extreme point of this Capsule in the given direction. */
Vector3 ExtremePoint(const Vector3 &direction) const; Vector3 ExtremePoint(const Vector3 &direction) const;
Vector3 ExtremePoint(const Vector3 &direction, float &projectionDistance) const; Vector3 ExtremePoint(const Vector3 &direction, float &projectionDistance) const;
/// Tests if this Capsule is degenerate. /// Tests if this Capsule is degenerate.
/** @return True if this Capsule does not span a strictly positive volume. */ /** @return True if this Capsule does not span a strictly positive volume. */
bool IsDegenerate() const; bool IsDegenerate() const;
@@ -196,5 +197,7 @@ namespace J3ML::Geometry
bool Intersects(const Polygon &polygon) const; bool Intersects(const Polygon &polygon) const;
bool Intersects(const Frustum &frustum) const; bool Intersects(const Frustum &frustum) const;
bool Intersects(const Polyhedron &polyhedron) const; bool Intersects(const Polyhedron &polyhedron) const;
Capsule Translated(const Vector3&) const;
}; };
} }

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <J3ML/Geometry.h> #include <J3ML/Geometry.h>
#include <J3ML/LinearAlgebra/Matrix3x3.h> #include <J3ML/LinearAlgebra/Matrix3x3.h>
#include <J3ML/LinearAlgebra/Matrix4x4.h> #include <J3ML/LinearAlgebra/Matrix4x4.h>

View File

@@ -7,7 +7,6 @@
// //
#include <cstdint> #include <cstdint>
#include <cmath> #include <cmath>
#include <stdfloat>
#include <string> #include <string>
#include <cassert> #include <cassert>
@@ -17,13 +16,11 @@ namespace J3ML::SizedIntegralTypes
using u16 = uint16_t; using u16 = uint16_t;
using u32 = uint32_t; using u32 = uint32_t;
using u64 = uint64_t; using u64 = uint64_t;
using u128 = __uint128_t;
using s8 = int8_t; using s8 = int8_t;
using s16 = int16_t; using s16 = int16_t;
using s32 = int32_t; using s32 = int32_t;
using s64 = int64_t; using s64 = int64_t;
using s128 = __int128_t;
} }
@@ -39,6 +36,11 @@ namespace J3ML::SizedFloatTypes
using namespace J3ML::SizedIntegralTypes; using namespace J3ML::SizedIntegralTypes;
using namespace J3ML::SizedFloatTypes; using namespace J3ML::SizedFloatTypes;
//On windows there is no shorthand for pi???? - Redacted.
#ifdef _WIN32
#define M_PI 3.14159265358979323846
#endif
namespace J3ML::Math namespace J3ML::Math
{ {

View File

@@ -1,5 +1,3 @@
#pragma clang diagnostic push
#pragma ide diagnostic ignored "modernize-use-nodiscard"
#pragma once #pragma once
#include <J3ML/J3ML.h> #include <J3ML/J3ML.h>
#include <cstddef> #include <cstddef>
@@ -192,4 +190,3 @@ namespace J3ML::LinearAlgebra {
return rhs * lhs; return rhs * lhs;
} }
} }
#pragma clang diagnostic pop

View File

@@ -296,6 +296,8 @@ namespace J3ML::Geometry {
result.z = this->minPoint.z; result.z = this->minPoint.z;
else else
result.z = point.z; result.z = point.z;
return result;
} }
AABB::AABB(const Vector3 &min, const Vector3 &max) : Shape(), minPoint(min), maxPoint(max) AABB::AABB(const Vector3 &min, const Vector3 &max) : Shape(), minPoint(min), maxPoint(max)
@@ -613,20 +615,21 @@ namespace J3ML::Geometry {
); );
} }
AABB AABB::TransformAABB(const Matrix3x3 &transform) { void AABB::TransformAABB(const Matrix3x3 &transform) {
// TODO: assert(transform.IsColOrthogonal()); // TODO: assert(transform.IsColOrthogonal());
// TODO: assert(transform.HasUniformScale()); // TODO: assert(transform.HasUniformScale());
AABBTransformAsAABB(*this, transform); AABBTransformAsAABB(*this, transform);
} }
AABB AABB::TransformAABB(const Matrix4x4 &transform) { void AABB::TransformAABB(const Matrix4x4 &transform) {
// TODO: assert(transform.IsColOrthogonal()); // TODO: assert(transform.IsColOrthogonal());
// TODO: assert(transform.HasUniformScale()); // TODO: assert(transform.HasUniformScale());
// TODO: assert(transform.Row(3).Equals(0,0,0,1)); // TODO: assert(transform.Row(3).Equals(0,0,0,1));
AABBTransformAsAABB(*this, transform); AABBTransformAsAABB(*this, transform);
} }
AABB AABB::TransformAABB(const Quaternion &transform) { void AABB::TransformAABB(const Quaternion &transform) {
Vector3 newCenter = transform.Transform(Centroid()); Vector3 newCenter = transform.Transform(Centroid());
Vector3 newDir = Vector3::Abs((transform.Transform(Size())*0.5f)); Vector3 newDir = Vector3::Abs((transform.Transform(Size())*0.5f));
minPoint = newCenter - newDir; minPoint = newCenter - newDir;

View File

@@ -1,3 +1,4 @@
#include <J3ML/Algorithm/GJK.h>
#include <J3ML/Geometry/Capsule.h> #include <J3ML/Geometry/Capsule.h>
#include <J3ML/Geometry/AABB.h> #include <J3ML/Geometry/AABB.h>
#include <J3ML/Geometry/Sphere.h> #include <J3ML/Geometry/Sphere.h>
@@ -8,6 +9,17 @@ namespace J3ML::Geometry
Capsule::Capsule() : l() {} Capsule::Capsule() : l() {}
Capsule::Capsule(const LineSegment &endPoints, float radius)
:l(endPoints), r(radius)
{
}
Capsule::Capsule(const Vector3 &bottomPoint, const Vector3 &topPoint, float radius)
:l(bottomPoint, topPoint), r(radius)
{
}
AABB Capsule::MinimalEnclosingAABB() const AABB Capsule::MinimalEnclosingAABB() const
{ {
Vector3 d = Vector3(r, r, r); Vector3 d = Vector3(r, r, r);
@@ -49,12 +61,13 @@ namespace J3ML::Geometry
bool Capsule::Intersects(const AABB &aabb) const bool Capsule::Intersects(const AABB &aabb) const
{ {
//return FloatingPointOffsetedGJKIntersect(*this, aabb); return Algorithms::FloatingPointOffsetedGJKIntersect(*this, aabb);
return false;
} }
bool Capsule::Intersects(const OBB &obb) const bool Capsule::Intersects(const OBB &obb) const
{ {
//return GJKIntersect(*this, obb); return Algorithms::GJKIntersect(*this, obb);
} }
/// [groupSyntax] /// [groupSyntax]
@@ -104,4 +117,9 @@ namespace J3ML::Geometry
projectionDistance = extremePoint.Dot(direction); projectionDistance = extremePoint.Dot(direction);
return extremePoint; return extremePoint;
} }
Capsule Capsule::Translated(const Vector3 &offset) const
{
return Capsule(l.A + offset, l.B + offset, r);
}
} }

View File

@@ -87,7 +87,7 @@ namespace J3ML::Geometry
float Plane::SignedDistance(const Triangle &triangle) const { return Plane_SignedDistance(*this, triangle); } float Plane::SignedDistance(const Triangle &triangle) const { return Plane_SignedDistance(*this, triangle); }
float Plane::Distance(const Vector3 &point) const { float Plane::Distance(const Vector3 &point) const {
std::abs(SignedDistance(point)); return std::abs(SignedDistance(point));
} }
float Plane::Distance(const LineSegment &lineSegment) const float Plane::Distance(const LineSegment &lineSegment) const

View File

@@ -333,7 +333,8 @@ namespace J3ML::Geometry
} }
bool Polyhedron::IsClosed() const { bool Polyhedron::IsClosed() const {
// TODO: Implement
return false;
} }
Plane Polyhedron::FacePlane(int faceIndex) const Plane Polyhedron::FacePlane(int faceIndex) const

View File

@@ -4,7 +4,7 @@ namespace J3ML::Geometry
{ {
bool Sphere::Contains(const LineSegment &lineseg) const { bool Sphere::Contains(const LineSegment &lineseg) const {
return Contains(lineseg.A) && Contains(lineseg.B);
} }
void Sphere::ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const void Sphere::ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const

View File

@@ -38,7 +38,7 @@ namespace J3ML
Math::Rotation::Rotation(float value) : valueInRadians(value) {} Math::Rotation::Rotation(float value) : valueInRadians(value) {}
Math::Rotation Math::Rotation::operator+(const Math::Rotation &rhs) { Math::Rotation Math::Rotation::operator+(const Math::Rotation &rhs) {
valueInRadians += rhs.valueInRadians; return {valueInRadians + rhs.valueInRadians};
} }
float Math::Interp::SmoothStart(float t) { float Math::Interp::SmoothStart(float t) {

View File

@@ -507,6 +507,8 @@ namespace J3ML::LinearAlgebra {
Vector3 s = source.Abs(); Vector3 s = source.Abs();
Vector3 unit = s.x < s.y && s.x < s.z ? Vector3::UnitX : (s.y < s.z ? Vector3::UnitY : Vector3::UnitZ); Vector3 unit = s.x < s.y && s.x < s.z ? Vector3::UnitX : (s.y < s.z ? Vector3::UnitY : Vector3::UnitZ);
} }
return Matrix3x3::Identity;
} }
Vector3 &Matrix3x3::Row(int row) { Vector3 &Matrix3x3::Row(int row) {

View File

@@ -174,6 +174,7 @@ namespace J3ML::LinearAlgebra {
float p10 = 0; float p11 = 2.f / v; float p12 = 0; float p13 = 0.f; float p10 = 0; float p11 = 2.f / v; float p12 = 0; float p13 = 0.f;
float p20 = 0; float p21 = 0; float p22 = 1.f / (n-f); float p23 = n / (n-f); float p20 = 0; float p21 = 0; float p22 = 1.f / (n-f); float p23 = n / (n-f);
float p30 = 0; float p31 = 0; float p32 = 0.f; float p33 = 1.f; float p30 = 0; float p31 = 0; float p32 = 0.f; float p33 = 1.f;
return {p00,p01,p02,p03, p10, p11, p12, p13, p20,p21,p22,p23, p30,p31,p32,p33};
} }
float Matrix4x4::At(int x, int y) const { float Matrix4x4::At(int x, int y) const {

View File

@@ -89,6 +89,7 @@ namespace J3ML::LinearAlgebra {
if (index == 0) return x; if (index == 0) return x;
if (index == 1) return y; if (index == 1) return y;
if (index == 2) return z; if (index == 2) return z;
throw;
} }
bool Vector3::IsWithinMarginOfError(const Vector3& rhs, float margin) const bool Vector3::IsWithinMarginOfError(const Vector3& rhs, float margin) const
@@ -440,6 +441,7 @@ namespace J3ML::LinearAlgebra {
}; };
} }
// TODO: Implement
Vector3 Vector3::Perpendicular(const Vector3 &hint, const Vector3 &hint2) const { Vector3 Vector3::Perpendicular(const Vector3 &hint, const Vector3 &hint2) const {
assert(!this->IsZero()); assert(!this->IsZero());
assert(hint.IsNormalized()); assert(hint.IsNormalized());
@@ -447,6 +449,8 @@ namespace J3ML::LinearAlgebra {
Vector3 v = this->Cross(hint); Vector3 v = this->Cross(hint);
float len = v.TryNormalize(); float len = v.TryNormalize();
return Vector3::Zero;
} }
float Vector3::TryNormalize() { float Vector3::TryNormalize() {