diff --git a/CMakeLists.txt b/CMakeLists.txt index ed760f2..8f15b4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,10 +25,16 @@ file(GLOB_RECURSE J3ML_SRC "src/J3ML/*.c" "src/J3ML/*.cpp") include_directories("include") -add_library(J3ML SHARED ${J3ML_SRC}) +if (UNIX) + add_library(J3ML SHARED ${J3ML_SRC}) +endif() + +if (WIN32) + add_library(J3ML STATIC ${J3ML_SRC}) +endif() set_target_properties(J3ML PROPERTIES LINKER_LANGUAGE CXX) if(WIN32) - target_compile_options(J3ML PRIVATE -Wno-multichar) + #target_compile_options(J3ML PRIVATE -Wno-multichar) endif() install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) @@ -41,5 +47,5 @@ add_executable(MathDemo main.cpp) target_link_libraries(MathDemo ${PROJECT_NAME}) if(WIN32) - target_compile_options(MathDemo PRIVATE -mwindows) + #target_compile_options(MathDemo PRIVATE -mwindows) endif() \ No newline at end of file diff --git a/include/J3ML/Algorithm/GJK.h b/include/J3ML/Algorithm/GJK.h index a15257d..3b43eea 100644 --- a/include/J3ML/Algorithm/GJK.h +++ b/include/J3ML/Algorithm/GJK.h @@ -55,6 +55,6 @@ namespace J3ML::Algorithms Vector3 offset = (Vector3::Min(ab.minPoint, bb.minPoint) + Vector3::Max(ab.maxPoint, bb.maxPoint)) * 0.5f; const Vector3 floatingPtPrecisionOffset = -offset; - return GJLIntersect(a.Translated(floatingPtPrecisionOffset), b.Translated(floatingPtPrecisionOffset)); + return GJKIntersect(a.Translated(floatingPtPrecisionOffset), b.Translated(floatingPtPrecisionOffset)); } } \ No newline at end of file diff --git a/include/J3ML/Geometry/AABB.h b/include/J3ML/Geometry/AABB.h index a56f609..a8ebc8d 100644 --- a/include/J3ML/Geometry/AABB.h +++ b/include/J3ML/Geometry/AABB.h @@ -183,9 +183,9 @@ namespace J3ML::Geometry AABB Translated(const Vector3& offset) const; void Scale(const Vector3& scale); AABB Scaled(const Vector3& scale) const; - AABB TransformAABB(const Matrix3x3& transform); - AABB TransformAABB(const Matrix4x4& transform); - AABB TransformAABB(const Quaternion& transform); + void TransformAABB(const Matrix3x3& transform); + void TransformAABB(const Matrix4x4& transform); + void TransformAABB(const Quaternion& transform); /// 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 to this object itself, but instead returns the OBB that results in the transformation. diff --git a/include/J3ML/Geometry/Capsule.h b/include/J3ML/Geometry/Capsule.h index 0bdcee6..7dab35a 100644 --- a/include/J3ML/Geometry/Capsule.h +++ b/include/J3ML/Geometry/Capsule.h @@ -66,6 +66,7 @@ namespace J3ML::Geometry @return The extreme point of this Capsule in the given direction. */ Vector3 ExtremePoint(const Vector3 &direction) const; Vector3 ExtremePoint(const Vector3 &direction, float &projectionDistance) const; + /// Tests if this Capsule is degenerate. /** @return True if this Capsule does not span a strictly positive volume. */ bool IsDegenerate() const; @@ -196,5 +197,7 @@ namespace J3ML::Geometry bool Intersects(const Polygon &polygon) const; bool Intersects(const Frustum &frustum) const; bool Intersects(const Polyhedron &polyhedron) const; + + Capsule Translated(const Vector3&) const; }; } \ No newline at end of file diff --git a/include/J3ML/Geometry/Sphere.h b/include/J3ML/Geometry/Sphere.h index a94f764..57226bb 100644 --- a/include/J3ML/Geometry/Sphere.h +++ b/include/J3ML/Geometry/Sphere.h @@ -1,5 +1,7 @@ #pragma once + + #include #include #include diff --git a/include/J3ML/J3ML.h b/include/J3ML/J3ML.h index ea6c5ce..1b93aee 100644 --- a/include/J3ML/J3ML.h +++ b/include/J3ML/J3ML.h @@ -7,7 +7,6 @@ // #include #include -#include #include #include @@ -17,13 +16,11 @@ namespace J3ML::SizedIntegralTypes using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; - using u128 = __uint128_t; using s8 = int8_t; using s16 = int16_t; using s32 = int32_t; using s64 = int64_t; - using s128 = __int128_t; } @@ -39,6 +36,11 @@ namespace J3ML::SizedFloatTypes using namespace J3ML::SizedIntegralTypes; using namespace J3ML::SizedFloatTypes; +//On windows there is no shorthand for pi???? - Redacted. +#ifdef _WIN32 +#define M_PI 3.14159265358979323846 +#endif + namespace J3ML::Math { diff --git a/include/J3ML/LinearAlgebra/Vector2.h b/include/J3ML/LinearAlgebra/Vector2.h index 292343c..43ef450 100644 --- a/include/J3ML/LinearAlgebra/Vector2.h +++ b/include/J3ML/LinearAlgebra/Vector2.h @@ -1,5 +1,3 @@ -#pragma clang diagnostic push -#pragma ide diagnostic ignored "modernize-use-nodiscard" #pragma once #include #include @@ -191,5 +189,4 @@ namespace J3ML::LinearAlgebra { { return rhs * lhs; } -} -#pragma clang diagnostic pop \ No newline at end of file +} \ No newline at end of file diff --git a/src/J3ML/Geometry/AABB.cpp b/src/J3ML/Geometry/AABB.cpp index 57aafd4..0a9e201 100644 --- a/src/J3ML/Geometry/AABB.cpp +++ b/src/J3ML/Geometry/AABB.cpp @@ -296,6 +296,8 @@ namespace J3ML::Geometry { result.z = this->minPoint.z; else result.z = point.z; + + return result; } 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.HasUniformScale()); AABBTransformAsAABB(*this, transform); } - AABB AABB::TransformAABB(const Matrix4x4 &transform) { + void AABB::TransformAABB(const Matrix4x4 &transform) { // TODO: assert(transform.IsColOrthogonal()); // TODO: assert(transform.HasUniformScale()); // TODO: assert(transform.Row(3).Equals(0,0,0,1)); AABBTransformAsAABB(*this, transform); + } - AABB AABB::TransformAABB(const Quaternion &transform) { + void AABB::TransformAABB(const Quaternion &transform) { Vector3 newCenter = transform.Transform(Centroid()); Vector3 newDir = Vector3::Abs((transform.Transform(Size())*0.5f)); minPoint = newCenter - newDir; diff --git a/src/J3ML/Geometry/Capsule.cpp b/src/J3ML/Geometry/Capsule.cpp index 6e204a6..f2579cc 100644 --- a/src/J3ML/Geometry/Capsule.cpp +++ b/src/J3ML/Geometry/Capsule.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -8,6 +9,17 @@ namespace J3ML::Geometry 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 { Vector3 d = Vector3(r, r, r); @@ -49,12 +61,13 @@ namespace J3ML::Geometry 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 { - //return GJKIntersect(*this, obb); + return Algorithms::GJKIntersect(*this, obb); } /// [groupSyntax] @@ -104,4 +117,9 @@ namespace J3ML::Geometry projectionDistance = extremePoint.Dot(direction); return extremePoint; } + + Capsule Capsule::Translated(const Vector3 &offset) const + { + return Capsule(l.A + offset, l.B + offset, r); + } } \ No newline at end of file diff --git a/src/J3ML/Geometry/Plane.cpp b/src/J3ML/Geometry/Plane.cpp index 5f0d889..e8b7f5f 100644 --- a/src/J3ML/Geometry/Plane.cpp +++ b/src/J3ML/Geometry/Plane.cpp @@ -87,7 +87,7 @@ namespace J3ML::Geometry float Plane::SignedDistance(const Triangle &triangle) const { return Plane_SignedDistance(*this, triangle); } float Plane::Distance(const Vector3 &point) const { - std::abs(SignedDistance(point)); + return std::abs(SignedDistance(point)); } float Plane::Distance(const LineSegment &lineSegment) const diff --git a/src/J3ML/Geometry/Polyhedron.cpp b/src/J3ML/Geometry/Polyhedron.cpp index 6f5ca24..f85e3a8 100644 --- a/src/J3ML/Geometry/Polyhedron.cpp +++ b/src/J3ML/Geometry/Polyhedron.cpp @@ -333,7 +333,8 @@ namespace J3ML::Geometry } bool Polyhedron::IsClosed() const { - + // TODO: Implement + return false; } Plane Polyhedron::FacePlane(int faceIndex) const diff --git a/src/J3ML/Geometry/Sphere.cpp b/src/J3ML/Geometry/Sphere.cpp index bd9d9b5..9830cbb 100644 --- a/src/J3ML/Geometry/Sphere.cpp +++ b/src/J3ML/Geometry/Sphere.cpp @@ -4,7 +4,7 @@ namespace J3ML::Geometry { 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 diff --git a/src/J3ML/J3ML.cpp b/src/J3ML/J3ML.cpp index df500d1..238400d 100644 --- a/src/J3ML/J3ML.cpp +++ b/src/J3ML/J3ML.cpp @@ -38,7 +38,7 @@ namespace J3ML Math::Rotation::Rotation(float value) : valueInRadians(value) {} Math::Rotation Math::Rotation::operator+(const Math::Rotation &rhs) { - valueInRadians += rhs.valueInRadians; + return {valueInRadians + rhs.valueInRadians}; } float Math::Interp::SmoothStart(float t) { diff --git a/src/J3ML/LinearAlgebra/Matrix3x3.cpp b/src/J3ML/LinearAlgebra/Matrix3x3.cpp index cb5e85f..43ee004 100644 --- a/src/J3ML/LinearAlgebra/Matrix3x3.cpp +++ b/src/J3ML/LinearAlgebra/Matrix3x3.cpp @@ -507,6 +507,8 @@ namespace J3ML::LinearAlgebra { Vector3 s = source.Abs(); 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) { diff --git a/src/J3ML/LinearAlgebra/Matrix4x4.cpp b/src/J3ML/LinearAlgebra/Matrix4x4.cpp index d4c0900..be5b4dd 100644 --- a/src/J3ML/LinearAlgebra/Matrix4x4.cpp +++ b/src/J3ML/LinearAlgebra/Matrix4x4.cpp @@ -174,6 +174,7 @@ namespace J3ML::LinearAlgebra { 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 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 { diff --git a/src/J3ML/LinearAlgebra/Vector3.cpp b/src/J3ML/LinearAlgebra/Vector3.cpp index 7a78967..a4b35d4 100644 --- a/src/J3ML/LinearAlgebra/Vector3.cpp +++ b/src/J3ML/LinearAlgebra/Vector3.cpp @@ -89,6 +89,7 @@ namespace J3ML::LinearAlgebra { if (index == 0) return x; if (index == 1) return y; if (index == 2) return z; + throw; } 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 { assert(!this->IsZero()); assert(hint.IsNormalized()); @@ -447,6 +449,8 @@ namespace J3ML::LinearAlgebra { Vector3 v = this->Cross(hint); float len = v.TryNormalize(); + + return Vector3::Zero; } float Vector3::TryNormalize() {