diff --git a/sources/include/cage-core/collider.h b/sources/include/cage-core/collider.h index 662762ab..8f16e863 100644 --- a/sources/include/cage-core/collider.h +++ b/sources/include/cage-core/collider.h @@ -21,7 +21,7 @@ namespace cage PointerRange triangles() const; - void addTriangle(const Triangle &t); + void addTriangle(Triangle t); void addTriangles(PointerRange tris); void optimize(); // removes duplicated triangles @@ -29,7 +29,7 @@ namespace cage void rebuild(); bool needsRebuild() const; - const Aabb &box() const; + Aabb box() const; }; CAGE_CORE_API Holder newCollider(); @@ -52,7 +52,7 @@ namespace cage { CollisionDetectionConfig() = default; explicit CollisionDetectionConfig(const Collider *ao, const Collider *bo) : ao(ao), bo(bo) {} - explicit CollisionDetectionConfig(const Collider *ao, const Collider *bo, const Transform &at, const Transform &bt) : at1(at), bt1(bt), at2(at), bt2(bt), ao(ao), bo(bo) {} + explicit CollisionDetectionConfig(const Collider *ao, const Collider *bo, Transform at, Transform bt) : at1(at), bt1(bt), at2(at), bt2(bt), ao(ao), bo(bo) {} // inputs Transform at1; @@ -70,26 +70,26 @@ namespace cage CAGE_CORE_API bool collisionDetection(CollisionDetectionConfig ¶ms); - CAGE_CORE_API Real distance(const Line &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Triangle &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Plane &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Sphere &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Aabb &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Cone &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Frustum &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Real distance(const Collider *ao, const Collider *bo, const Transform &at, const Transform &bt); - - CAGE_CORE_API bool intersects(const Line &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Triangle &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Plane &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Sphere &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Aabb &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Cone &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Frustum &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API bool intersects(const Collider *ao, const Collider *bo, const Transform &at, const Transform &bt); - - CAGE_CORE_API Vec3 intersection(const Line &shape, const Collider *collider, const Transform &t); - CAGE_CORE_API Vec3 intersection(const Line &shape, const Collider *collider, const Transform &t, uint32 &triangleIndex); + CAGE_CORE_API Real distance(Line shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(Triangle shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(Plane shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(Sphere shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(Aabb shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(Cone shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(const Frustum &shape, const Collider *collider, Transform t); + CAGE_CORE_API Real distance(const Collider *ao, const Collider *bo, Transform at, Transform bt); + + CAGE_CORE_API bool intersects(Line shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(Triangle shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(Plane shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(Sphere shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(Aabb shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(Cone shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(const Frustum &shape, const Collider *collider, Transform t); + CAGE_CORE_API bool intersects(const Collider *ao, const Collider *bo, Transform at, Transform bt); + + CAGE_CORE_API Vec3 intersection(Line shape, const Collider *collider, Transform t); + CAGE_CORE_API Vec3 intersection(Line shape, const Collider *collider, Transform t, uint32 &triangleIndex); CAGE_CORE_API AssetScheme genAssetSchemeCollider(); constexpr uint32 AssetSchemeIndexCollider = 3; diff --git a/sources/include/cage-core/collisionStructure.h b/sources/include/cage-core/collisionStructure.h index 040bc1bd..4c0f6552 100644 --- a/sources/include/cage-core/collisionStructure.h +++ b/sources/include/cage-core/collisionStructure.h @@ -19,27 +19,27 @@ namespace cage PointerRange collisionPairs() const; // finds arbitrary collision, if any - bool query(const Collider *collider, const Transform &t); + bool query(const Collider *collider, Transform t); // finds a collision that is first in time, if any - bool query(const Collider *collider, const Transform &t1, const Transform &t2); // t1 and t2 are initial and final transformations + bool query(const Collider *collider, Transform t1, Transform t2); // t1 and t2 are initial and final transformations // finds a collision that is first along the line, if any - bool query(const Line &shape); + bool query(Line shape); // finds arbitrary collision, if any - bool query(const Triangle &shape); - bool query(const Plane &shape); - bool query(const Sphere &shape); - bool query(const Aabb &shape); - bool query(const Cone &shape); + bool query(Triangle shape); + bool query(Plane shape); + bool query(Sphere shape); + bool query(Aabb shape); + bool query(Cone shape); bool query(const Frustum &shape); }; class CAGE_CORE_API CollisionStructure : private Immovable { public: - void update(uint32 name, Holder collider, const Transform &t); + void update(uint32 name, Holder collider, Transform t); void remove(uint32 name); void clear(); void rebuild(); diff --git a/sources/include/cage-core/geometry.h b/sources/include/cage-core/geometry.h index 7ec3f9b6..7c0b5d60 100644 --- a/sources/include/cage-core/geometry.h +++ b/sources/include/cage-core/geometry.h @@ -18,12 +18,12 @@ namespace cage explicit constexpr Line(Vec3 origin, Vec3 direction, Real minimum, Real maximum) noexcept : origin(origin), direction(direction), minimum(minimum), maximum(maximum) {} // compound operators - Line &operator*=(const Mat4 &other) { return *this = *this * other; } - Line &operator*=(const Transform &other) { return *this = *this * other; } + Line &operator*=(Mat4 other) { return *this = *this * other; } + Line &operator*=(Transform other) { return *this = *this * other; } // binary operators - Line operator*(const Mat4 &other) const; - Line operator*(const Transform &other) const { return *this * Mat4(other); } + Line operator*(Mat4 other) const; + Line operator*(Transform other) const { return *this * Mat4(other); } // comparison operators bool operator==(const Line &) const noexcept = default; @@ -56,16 +56,16 @@ namespace cage // constructors constexpr Triangle() noexcept {} explicit constexpr Triangle(const Vec3 vertices[3]) noexcept : vertices{ vertices[0], vertices[1], vertices[2] } {} - explicit constexpr Triangle(const Vec3 &a, const Vec3 &b, const Vec3 &c) noexcept : vertices{ a, b, c } {} + explicit constexpr Triangle(Vec3 a, Vec3 b, Vec3 c) noexcept : vertices{ a, b, c } {} explicit constexpr Triangle(const Real coords[9]) noexcept : vertices{ Vec3(coords[0], coords[1], coords[2]), Vec3(coords[3], coords[4], coords[5]), Vec3(coords[6], coords[7], coords[8]) } {} // compound operators - Triangle &operator*=(const Mat4 &other) { return *this = *this * other; } - Triangle &operator*=(const Transform &other) { return *this = *this * other; } + Triangle &operator*=(Mat4 other) { return *this = *this * other; } + Triangle &operator*=(Transform other) { return *this = *this * other; } // binary operators - Triangle operator*(const Mat4 &other) const; - Triangle operator*(const Transform &other) const { return *this * Mat4(other); } + Triangle operator*(Mat4 other) const; + Triangle operator*(Transform other) const { return *this * Mat4(other); } constexpr Vec3 operator[](uint32 idx) const { @@ -98,19 +98,19 @@ namespace cage // constructors constexpr Plane() noexcept {} - explicit constexpr Plane(const Vec3 &normal, Real d) noexcept : normal(normal), d(d) {} - explicit Plane(const Vec3 &point, const Vec3 &normal); - explicit Plane(const Vec3 &a, const Vec3 &b, const Vec3 &c); - explicit Plane(const Triangle &other); - explicit Plane(const Line &a, const Vec3 &b); + explicit constexpr Plane(Vec3 normal, Real d) noexcept : normal(normal), d(d) {} + explicit Plane(Vec3 point, Vec3 normal); + explicit Plane(Vec3 a, Vec3 b, Vec3 c); + explicit Plane(Triangle other); + explicit Plane(Line a, Vec3 b); // compound operators - Plane &operator*=(const Mat4 &other) { return *this = *this * other; } - Plane &operator*=(const Transform &other) { return *this = *this * other; } + Plane &operator*=(Mat4 other) { return *this = *this * other; } + Plane &operator*=(Transform other) { return *this = *this * other; } // binary operators - Plane operator*(const Mat4 &other) const; - Plane operator*(const Transform &other) const { return *this * Mat4(other); } + Plane operator*(Mat4 other) const; + Plane operator*(Transform other) const { return *this * Mat4(other); } // comparison operators bool operator==(const Plane &) const noexcept = default; @@ -130,20 +130,20 @@ namespace cage // constructors constexpr Sphere() noexcept {} - explicit constexpr Sphere(const Vec3 ¢er, Real radius) noexcept : center(center), radius(radius) {} - explicit Sphere(const Line &other); - explicit Sphere(const Triangle &other); - explicit Sphere(const Aabb &other); - explicit Sphere(const Cone &other); + explicit constexpr Sphere(Vec3 center, Real radius) noexcept : center(center), radius(radius) {} + explicit Sphere(Line other); + explicit Sphere(Triangle other); + explicit Sphere(Aabb other); + explicit Sphere(Cone other); explicit Sphere(const Frustum &other); // compound operators - Sphere &operator*=(const Mat4 &other) { return *this = *this * other; } - Sphere &operator*=(const Transform &other) { return *this = *this * other; } + Sphere &operator*=(Mat4 other) { return *this = *this * other; } + Sphere &operator*=(Transform other) { return *this = *this * other; } // binary operators - Sphere operator*(const Mat4 &other) const; - Sphere operator*(const Transform &other) const { return *this * Mat4(other); } + Sphere operator*(Mat4 other) const; + Sphere operator*(Transform other) const { return *this * Mat4(other); } // comparison operators bool operator==(const Sphere &other) const noexcept { return (empty() && other.empty()) || (center == other.center && radius == other.radius); } @@ -162,24 +162,24 @@ namespace cage // constructor constexpr Aabb() noexcept {} - explicit constexpr Aabb(const Vec3 &point) noexcept : a(point), b(point) {} - explicit constexpr Aabb(const Vec3 &a, const Vec3 &b) noexcept : a(min(a, b)), b(max(a, b)) {} - explicit constexpr Aabb(const Triangle &other) noexcept : a(min(min(other[0], other[1]), other[2])), b(max(max(other[0], other[1]), other[2])) {} - explicit constexpr Aabb(const Sphere &other) noexcept : a(other.center - other.radius), b(other.center + other.radius) {} - explicit Aabb(const Line &other); - explicit Aabb(const Plane &other); - explicit Aabb(const Cone &other); + explicit constexpr Aabb(Vec3 point) noexcept : a(point), b(point) {} + explicit constexpr Aabb(Vec3 a, Vec3 b) noexcept : a(min(a, b)), b(max(a, b)) {} + explicit constexpr Aabb(Triangle other) noexcept : a(min(min(other[0], other[1]), other[2])), b(max(max(other[0], other[1]), other[2])) {} + explicit constexpr Aabb(Sphere other) noexcept : a(other.center - other.radius), b(other.center + other.radius) {} + explicit Aabb(Line other); + explicit Aabb(Plane other); + explicit Aabb(Cone other); explicit Aabb(const Frustum &other); // compound operators - Aabb &operator+=(const Aabb &other) { return *this = *this + other; } - Aabb &operator*=(const Mat4 &other) { return *this = *this * other; } - Aabb &operator*=(const Transform &other) { return *this = *this * other; } + Aabb &operator+=(Aabb other) { return *this = *this + other; } + Aabb &operator*=(Mat4 other) { return *this = *this * other; } + Aabb &operator*=(Transform other) { return *this = *this * other; } // binary operators - Aabb operator+(const Aabb &other) const; - Aabb operator*(const Mat4 &other) const; - Aabb operator*(const Transform &other) const { return *this * Mat4(other); } + Aabb operator+(Aabb other) const; + Aabb operator*(Mat4 other) const; + Aabb operator*(Transform other) const { return *this * Mat4(other); } // comparison operators bool operator==(const Aabb &other) const noexcept { return (empty() && other.empty()) || (a == other.a && b == other.b); } @@ -207,15 +207,15 @@ namespace cage // constructor constexpr Cone() noexcept {} - explicit constexpr Cone(const Vec3 &origin, const Vec3 &direction, Real length, Rads halfAngle) noexcept : origin(origin), direction(direction), length(length), halfAngle(halfAngle) {} + explicit constexpr Cone(Vec3 origin, Vec3 direction, Real length, Rads halfAngle) noexcept : origin(origin), direction(direction), length(length), halfAngle(halfAngle) {} // compound operators - Cone &operator*=(const Mat4 &other) { return *this = *this * other; } - Cone &operator*=(const Transform &other) { return *this = *this * other; } + Cone &operator*=(Mat4 other) { return *this = *this * other; } + Cone &operator*=(Transform other) { return *this = *this * other; } // binary operators - Cone operator*(const Mat4 &other) const; - Cone operator*(const Transform &other) const { return *this * Mat4(other); } + Cone operator*(Mat4 other) const; + Cone operator*(Transform other) const { return *this * Mat4(other); } // comparison operators bool operator==(const Cone &other) const noexcept { return (empty() && other.empty()) || (origin == other.origin && direction == other.direction && length == other.length && halfAngle == other.halfAngle); } @@ -234,16 +234,16 @@ namespace cage // constructor constexpr Frustum() noexcept {} - explicit Frustum(const Transform &camera, const Mat4 &proj); - explicit Frustum(const Mat4 &viewProj); + explicit Frustum(Transform camera, Mat4 proj); + explicit Frustum(Mat4 viewProj); // compound operators - Frustum &operator*=(const Mat4 &other) { return *this = *this * other; } - Frustum &operator*=(const Transform &other) { return *this = *this * other; } + Frustum &operator*=(Mat4 other) { return *this = *this * other; } + Frustum &operator*=(Transform other) { return *this = *this * other; } // binary operators - Frustum operator*(const Mat4 &other) const; - Frustum operator*(const Transform &other) const { return *this * Mat4(other); } + Frustum operator*(Mat4 other) const; + Frustum operator*(Transform other) const { return *this * Mat4(other); } // methods struct Corners @@ -256,32 +256,32 @@ namespace cage namespace detail { template - CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, const Line &other) + CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, Line other) { return str + "(" + other.origin + ", " + other.direction + ", " + other.minimum + ", " + other.maximum + ")"; } template - CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, const Triangle &other) + CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, Triangle other) { return str + "(" + other.vertices[0] + ", " + other.vertices[1] + ", " + other.vertices[2] + ")"; } template - CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, const Plane &other) + CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, Plane other) { return str + "(" + other.normal + ", " + other.d + ")"; } template - CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, const Sphere &other) + CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, Sphere other) { return str + "(" + other.center + ", " + other.radius + ")"; } template - CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, const Aabb &other) + CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, Aabb other) { return str + "(" + other.a + "," + other.b + ")"; } template - CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, const Cone &other) + CAGE_FORCE_INLINE StringizerBase &operator+(StringizerBase &str, Cone other) { return str + "(" + other.origin + "," + other.direction + "," + other.length + "," + other.halfAngle + ")"; } @@ -292,108 +292,108 @@ namespace cage } } - CAGE_CORE_API Line makeSegment(const Vec3 &a, const Vec3 &b); - CAGE_CORE_API Line makeRay(const Vec3 &a, const Vec3 &b); - CAGE_CORE_API Line makeLine(const Vec3 &a, const Vec3 &b); + CAGE_CORE_API Line makeSegment(Vec3 a, Vec3 b); + CAGE_CORE_API Line makeRay(Vec3 a, Vec3 b); + CAGE_CORE_API Line makeLine(Vec3 a, Vec3 b); - inline Sphere::Sphere(const Aabb &other) : center(other.center()), radius(other.diagonal() * 0.5) {} + inline Sphere::Sphere(Aabb other) : center(other.center()), radius(other.diagonal() * 0.5) {} CAGE_CORE_API Sphere makeSphere(PointerRange points); // minimum bounding sphere - CAGE_CORE_API Rads angle(const Line &a, const Line &b); - CAGE_CORE_API Rads angle(const Line &a, const Triangle &b); - CAGE_CORE_API Rads angle(const Line &a, const Plane &b); - CAGE_CORE_API Rads angle(const Triangle &a, const Triangle &b); - CAGE_CORE_API Rads angle(const Triangle &a, const Plane &b); - CAGE_CORE_API Rads angle(const Plane &a, const Plane &b); - - CAGE_CORE_API Real distance(const Vec3 &a, const Line &b); - CAGE_CORE_API Real distance(const Vec3 &a, const Triangle &b); - CAGE_CORE_API Real distance(const Vec3 &a, const Plane &b); - CAGE_CORE_API Real distance(const Vec3 &a, const Sphere &b); - CAGE_CORE_API Real distance(const Vec3 &a, const Aabb &b); - CAGE_CORE_API Real distance(const Vec3 &a, const Cone &b); - CAGE_CORE_API Real distance(const Vec3 &a, const Frustum &b); - CAGE_CORE_API Real distance(const Line &a, const Line &b); - CAGE_CORE_API Real distance(const Line &a, const Triangle &b); - CAGE_CORE_API Real distance(const Line &a, const Plane &b); - CAGE_CORE_API Real distance(const Line &a, const Sphere &b); - CAGE_CORE_API Real distance(const Line &a, const Aabb &b); - CAGE_CORE_API Real distance(const Line &a, const Cone &b); - CAGE_CORE_API Real distance(const Line &a, const Frustum &b); - CAGE_CORE_API Real distance(const Triangle &a, const Triangle &b); - CAGE_CORE_API Real distance(const Triangle &a, const Plane &b); - CAGE_CORE_API Real distance(const Triangle &a, const Sphere &b); - CAGE_CORE_API Real distance(const Triangle &a, const Aabb &b); - CAGE_CORE_API Real distance(const Triangle &a, const Cone &b); - CAGE_CORE_API Real distance(const Triangle &a, const Frustum &b); - CAGE_CORE_API Real distance(const Plane &a, const Plane &b); - CAGE_CORE_API Real distance(const Plane &a, const Sphere &b); - CAGE_CORE_API Real distance(const Plane &a, const Aabb &b); - CAGE_CORE_API Real distance(const Plane &a, const Cone &b); - CAGE_CORE_API Real distance(const Plane &a, const Frustum &b); - CAGE_CORE_API Real distance(const Sphere &a, const Sphere &b); - CAGE_CORE_API Real distance(const Sphere &a, const Aabb &b); - CAGE_CORE_API Real distance(const Sphere &a, const Cone &b); - CAGE_CORE_API Real distance(const Sphere &a, const Frustum &b); - CAGE_CORE_API Real distance(const Aabb &a, const Aabb &b); - CAGE_CORE_API Real distance(const Aabb &a, const Cone &b); - CAGE_CORE_API Real distance(const Aabb &a, const Frustum &b); - CAGE_CORE_API Real distance(const Cone &a, const Cone &b); - CAGE_CORE_API Real distance(const Cone &a, const Frustum &b); + CAGE_CORE_API Rads angle(Line a, Line b); + CAGE_CORE_API Rads angle(Line a, Triangle b); + CAGE_CORE_API Rads angle(Line a, Plane b); + CAGE_CORE_API Rads angle(Triangle a, Triangle b); + CAGE_CORE_API Rads angle(Triangle a, Plane b); + CAGE_CORE_API Rads angle(Plane a, Plane b); + + CAGE_CORE_API Real distance(Vec3 a, Line b); + CAGE_CORE_API Real distance(Vec3 a, Triangle b); + CAGE_CORE_API Real distance(Vec3 a, Plane b); + CAGE_CORE_API Real distance(Vec3 a, Sphere b); + CAGE_CORE_API Real distance(Vec3 a, Aabb b); + CAGE_CORE_API Real distance(Vec3 a, Cone b); + CAGE_CORE_API Real distance(Vec3 a, const Frustum &b); + CAGE_CORE_API Real distance(Line a, Line b); + CAGE_CORE_API Real distance(Line a, Triangle b); + CAGE_CORE_API Real distance(Line a, Plane b); + CAGE_CORE_API Real distance(Line a, Sphere b); + CAGE_CORE_API Real distance(Line a, Aabb b); + CAGE_CORE_API Real distance(Line a, Cone b); + CAGE_CORE_API Real distance(Line a, const Frustum &b); + CAGE_CORE_API Real distance(Triangle a, Triangle b); + CAGE_CORE_API Real distance(Triangle a, Plane b); + CAGE_CORE_API Real distance(Triangle a, Sphere b); + CAGE_CORE_API Real distance(Triangle a, Aabb b); + CAGE_CORE_API Real distance(Triangle a, Cone b); + CAGE_CORE_API Real distance(Triangle a, const Frustum &b); + CAGE_CORE_API Real distance(Plane a, Plane b); + CAGE_CORE_API Real distance(Plane a, Sphere b); + CAGE_CORE_API Real distance(Plane a, Aabb b); + CAGE_CORE_API Real distance(Plane a, Cone b); + CAGE_CORE_API Real distance(Plane a, const Frustum &b); + CAGE_CORE_API Real distance(Sphere a, Sphere b); + CAGE_CORE_API Real distance(Sphere a, Aabb b); + CAGE_CORE_API Real distance(Sphere a, Cone b); + CAGE_CORE_API Real distance(Sphere a, const Frustum &b); + CAGE_CORE_API Real distance(Aabb a, Aabb b); + CAGE_CORE_API Real distance(Aabb a, Cone b); + CAGE_CORE_API Real distance(Aabb a, const Frustum &b); + CAGE_CORE_API Real distance(Cone a, Cone b); + CAGE_CORE_API Real distance(Cone a, const Frustum &b); CAGE_CORE_API Real distance(const Frustum &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Vec3 &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Line &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Triangle &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Plane &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Sphere &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Aabb &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Cone &b); - CAGE_CORE_API bool intersects(const Vec3 &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Line &a, const Line &b); - CAGE_CORE_API bool intersects(const Line &a, const Triangle &b); - CAGE_CORE_API bool intersects(const Line &a, const Plane &b); - CAGE_CORE_API bool intersects(const Line &a, const Sphere &b); - CAGE_CORE_API bool intersects(const Line &a, const Aabb &b); - CAGE_CORE_API bool intersects(const Line &a, const Cone &b); - CAGE_CORE_API bool intersects(const Line &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Triangle &a, const Triangle &b); - CAGE_CORE_API bool intersects(const Triangle &a, const Plane &b); - CAGE_CORE_API bool intersects(const Triangle &a, const Sphere &b); - CAGE_CORE_API bool intersects(const Triangle &a, const Aabb &b); - CAGE_CORE_API bool intersects(const Triangle &a, const Cone &b); - CAGE_CORE_API bool intersects(const Triangle &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Plane &a, const Plane &b); - CAGE_CORE_API bool intersects(const Plane &a, const Sphere &b); - CAGE_CORE_API bool intersects(const Plane &a, const Aabb &b); - CAGE_CORE_API bool intersects(const Plane &a, const Cone &b); - CAGE_CORE_API bool intersects(const Plane &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Sphere &a, const Sphere &b); - CAGE_CORE_API bool intersects(const Sphere &a, const Aabb &b); - CAGE_CORE_API bool intersects(const Sphere &a, const Cone &b); - CAGE_CORE_API bool intersects(const Sphere &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Aabb &a, const Aabb &b); - CAGE_CORE_API bool intersects(const Aabb &a, const Cone &b); - CAGE_CORE_API bool intersects(const Aabb &a, const Frustum &b); - CAGE_CORE_API bool intersects(const Cone &a, const Cone &b); - CAGE_CORE_API bool intersects(const Cone &a, const Frustum &b); - - CAGE_CORE_API Vec3 intersection(const Line &a, const Triangle &b); - CAGE_CORE_API Vec3 intersection(const Line &a, const Plane &b); - CAGE_CORE_API Line intersection(const Line &a, const Sphere &b); - CAGE_CORE_API Line intersection(const Line &a, const Aabb &b); - CAGE_CORE_API Line intersection(const Line &a, const Cone &b); - CAGE_CORE_API Line intersection(const Line &a, const Frustum &b); - CAGE_CORE_API Aabb intersection(const Aabb &a, const Aabb &b); - - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Line &b); - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Triangle &b); - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Plane &b); - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Sphere &b); - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Aabb &b); - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Cone &b); - CAGE_CORE_API Vec3 closestPoint(const Vec3 &a, const Frustum &b); + CAGE_CORE_API bool intersects(Vec3 a, Vec3 b); + CAGE_CORE_API bool intersects(Vec3 a, Line b); + CAGE_CORE_API bool intersects(Vec3 a, Triangle b); + CAGE_CORE_API bool intersects(Vec3 a, Plane b); + CAGE_CORE_API bool intersects(Vec3 a, Sphere b); + CAGE_CORE_API bool intersects(Vec3 a, Aabb b); + CAGE_CORE_API bool intersects(Vec3 a, Cone b); + CAGE_CORE_API bool intersects(Vec3 a, const Frustum &b); + CAGE_CORE_API bool intersects(Line a, Line b); + CAGE_CORE_API bool intersects(Line a, Triangle b); + CAGE_CORE_API bool intersects(Line a, Plane b); + CAGE_CORE_API bool intersects(Line a, Sphere b); + CAGE_CORE_API bool intersects(Line a, Aabb b); + CAGE_CORE_API bool intersects(Line a, Cone b); + CAGE_CORE_API bool intersects(Line a, const Frustum &b); + CAGE_CORE_API bool intersects(Triangle a, Triangle b); + CAGE_CORE_API bool intersects(Triangle a, Plane b); + CAGE_CORE_API bool intersects(Triangle a, Sphere b); + CAGE_CORE_API bool intersects(Triangle a, Aabb b); + CAGE_CORE_API bool intersects(Triangle a, Cone b); + CAGE_CORE_API bool intersects(Triangle a, const Frustum &b); + CAGE_CORE_API bool intersects(Plane a, Plane b); + CAGE_CORE_API bool intersects(Plane a, Sphere b); + CAGE_CORE_API bool intersects(Plane a, Aabb b); + CAGE_CORE_API bool intersects(Plane a, Cone b); + CAGE_CORE_API bool intersects(Plane a, const Frustum &b); + CAGE_CORE_API bool intersects(Sphere a, Sphere b); + CAGE_CORE_API bool intersects(Sphere a, Aabb b); + CAGE_CORE_API bool intersects(Sphere a, Cone b); + CAGE_CORE_API bool intersects(Sphere a, const Frustum &b); + CAGE_CORE_API bool intersects(Aabb a, Aabb b); + CAGE_CORE_API bool intersects(Aabb a, Cone b); + CAGE_CORE_API bool intersects(Aabb a, const Frustum &b); + CAGE_CORE_API bool intersects(Cone a, Cone b); + CAGE_CORE_API bool intersects(Cone a, const Frustum &b); + + CAGE_CORE_API Vec3 intersection(Line a, Triangle b); + CAGE_CORE_API Vec3 intersection(Line a, Plane b); + CAGE_CORE_API Line intersection(Line a, Sphere b); + CAGE_CORE_API Line intersection(Line a, Aabb b); + CAGE_CORE_API Line intersection(Line a, Cone b); + CAGE_CORE_API Line intersection(Line a, const Frustum &b); + CAGE_CORE_API Aabb intersection(Aabb a, Aabb b); + + CAGE_CORE_API Vec3 closestPoint(Vec3 a, Line b); + CAGE_CORE_API Vec3 closestPoint(Vec3 a, Triangle b); + CAGE_CORE_API Vec3 closestPoint(Vec3 a, Plane b); + CAGE_CORE_API Vec3 closestPoint(Vec3 a, Sphere b); + CAGE_CORE_API Vec3 closestPoint(Vec3 a, Aabb b); + CAGE_CORE_API Vec3 closestPoint(Vec3 a, Cone b); + CAGE_CORE_API Vec3 closestPoint(Vec3 a, const Frustum &b); namespace privat { diff --git a/sources/include/cage-core/spatialStructure.h b/sources/include/cage-core/spatialStructure.h index 1e0f214e..82dc8a3d 100644 --- a/sources/include/cage-core/spatialStructure.h +++ b/sources/include/cage-core/spatialStructure.h @@ -10,25 +10,25 @@ namespace cage public: PointerRange result() const; - bool intersection(const Vec3 &shape); - bool intersection(const Line &shape); - bool intersection(const Triangle &shape); - bool intersection(const Plane &shape); - bool intersection(const Sphere &shape); - bool intersection(const Aabb &shape); - bool intersection(const Cone &shape); + bool intersection(Vec3 shape); + bool intersection(Line shape); + bool intersection(Triangle shape); + bool intersection(Plane shape); + bool intersection(Sphere shape); + bool intersection(Aabb shape); + bool intersection(Cone shape); bool intersection(const Frustum &shape); }; class CAGE_CORE_API SpatialStructure : private Immovable { public: - void update(uint32 name, const Vec3 &other); - void update(uint32 name, const Line &other); - void update(uint32 name, const Triangle &other); - void update(uint32 name, const Sphere &other); - void update(uint32 name, const Aabb &other); - void update(uint32 name, const Cone &other); + void update(uint32 name, Vec3 other); + void update(uint32 name, Line other); + void update(uint32 name, Triangle other); + void update(uint32 name, Sphere other); + void update(uint32 name, Aabb other); + void update(uint32 name, Cone other); void remove(uint32 name); void clear(); void rebuild(); diff --git a/sources/libcore/geometry/aabbCone.cpp b/sources/libcore/geometry/aabbCone.cpp index 98c6b79c..c5e7526d 100644 --- a/sources/libcore/geometry/aabbCone.cpp +++ b/sources/libcore/geometry/aabbCone.cpp @@ -26,7 +26,7 @@ namespace cage }; class TIQuery; - typedef void (TIQuery::*ConfigurationFunction)(uint16, const Face &); + typedef void (TIQuery::*ConfigurationFunction)(uint16, Face); class TIQuery { @@ -39,7 +39,7 @@ namespace cage mAdjacencyMatrix[r].fill(0); } - bool operator()(Aabb const &box, Cone const &cone) + bool operator()(Aabb box, Cone cone) { Real boxMinHeight(0), boxMaxHeight(0); ComputeBoxHeightInterval(box, cone, boxMinHeight, boxMaxHeight); @@ -61,7 +61,7 @@ namespace cage std::array mProjectionMin, mProjectionMax; uint16 mNumCandidateEdges = 0; - static void ComputeBoxHeightInterval(Aabb const &box, Cone const &cone, Real &boxMinHeight, Real &boxMaxHeight) + static void ComputeBoxHeightInterval(Aabb box, Cone cone, Real &boxMinHeight, Real &boxMaxHeight) { Vec3 C = box.center(), e = box.size() / 2; Vec3 const &V = cone.origin; @@ -73,9 +73,9 @@ namespace cage boxMaxHeight = DdCmV + radius; } - static bool ConeAxisIntersectsBox(Aabb const &box, Cone const &cone) { return intersects(box, makeSegment(cone.origin, cone.origin + cone.direction * cone.length)); } + static bool ConeAxisIntersectsBox(Aabb box, Cone cone) { return intersects(box, makeSegment(cone.origin, cone.origin + cone.direction * cone.length)); } - static bool HasPointInsideCone(Vec3 const &P0, Vec3 const &P1, Cone const &cone) + static bool HasPointInsideCone(Vec3 P0, Vec3 P1, Cone cone) { const Real coneCosAngle = cos(cone.halfAngle); Vec3 const &U = cone.direction; @@ -105,9 +105,9 @@ namespace cage return false; } - bool BoxFullyInConeSlab(Aabb const &box, Real boxMinHeight, Real boxMaxHeight, Cone const &cone); + bool BoxFullyInConeSlab(Aabb box, Real boxMinHeight, Real boxMaxHeight, Cone cone); - bool CandidatesHavePointInsideCone(Cone const &cone) const + bool CandidatesHavePointInsideCone(Cone cone) const { for (uint16 i = 0; i < mNumCandidateEdges; ++i) { @@ -120,7 +120,7 @@ namespace cage return false; } - void ComputeCandidatesOnBoxEdges(Cone const &cone); + void ComputeCandidatesOnBoxEdges(Cone cone); void ComputeCandidatesOnBoxFaces(); @@ -146,45 +146,45 @@ namespace cage } } - void NNNN_0(uint16, Face const &) {} + void NNNN_0(uint16, Face) {} - void NNNP_2(uint16 base, Face const &face) { InsertEdge(base + face.e[2], base + face.e[3]); } + void NNNP_2(uint16 base, Face face) { InsertEdge(base + face.e[2], base + face.e[3]); } - void NNZP_5(uint16 base, Face const &face) { InsertEdge(face.v[2], base + face.e[3]); } + void NNZP_5(uint16 base, Face face) { InsertEdge(face.v[2], base + face.e[3]); } - void NNPN_6(uint16 base, Face const &face) { InsertEdge(base + face.e[1], base + face.e[2]); } + void NNPN_6(uint16 base, Face face) { InsertEdge(base + face.e[1], base + face.e[2]); } - void NNPZ_7(uint16 base, Face const &face) { InsertEdge(base + face.e[1], face.v[3]); } + void NNPZ_7(uint16 base, Face face) { InsertEdge(base + face.e[1], face.v[3]); } - void NNPP_8(uint16 base, Face const &face) { InsertEdge(base + face.e[1], base + face.e[3]); } + void NNPP_8(uint16 base, Face face) { InsertEdge(base + face.e[1], base + face.e[3]); } - void NZNP_11(uint16 base, Face const &face) + void NZNP_11(uint16 base, Face face) { InsertEdge(base + face.e[2], face.v[3]); InsertEdge(base + face.e[3], face.v[3]); } - void NZZP_14(uint16 base, Face const &face) + void NZZP_14(uint16 base, Face face) { InsertEdge(face.v[2], face.v[3]); InsertEdge(base + face.e[3], face.v[3]); } - void NZPN_15(uint16 base, Face const &face) { InsertEdge(base + face.e[2], face.v[1]); } + void NZPN_15(uint16 base, Face face) { InsertEdge(base + face.e[2], face.v[1]); } - void NZPZ_16(uint16, Face const &face) { InsertEdge(face.v[1], face.v[3]); } + void NZPZ_16(uint16, Face face) { InsertEdge(face.v[1], face.v[3]); } - void NZPP_17(uint16 base, Face const &face) { InsertEdge(base + face.e[3], face.v[1]); } + void NZPP_17(uint16 base, Face face) { InsertEdge(base + face.e[3], face.v[1]); } - void NPNN_18(uint16 base, Face const &face) { InsertEdge(base + face.e[0], base + face.e[1]); } + void NPNN_18(uint16 base, Face face) { InsertEdge(base + face.e[0], base + face.e[1]); } - void NPNZ_19(uint16 base, Face const &face) + void NPNZ_19(uint16 base, Face face) { InsertEdge(base + face.e[0], face.v[1]); InsertEdge(base + face.e[1], face.v[1]); } - void NPNP_20(uint16 base, Face const &face) + void NPNP_20(uint16 base, Face face) { InsertEdge(base + face.e[0], face.v[1]); InsertEdge(base + face.e[1], face.v[1]); @@ -192,15 +192,15 @@ namespace cage InsertEdge(base + face.e[3], face.v[3]); } - void NPZN_21(uint16 base, Face const &face) { InsertEdge(base + face.e[0], face.v[2]); } + void NPZN_21(uint16 base, Face face) { InsertEdge(base + face.e[0], face.v[2]); } - void NPZZ_22(uint16 base, Face const &face) + void NPZZ_22(uint16 base, Face face) { InsertEdge(base + face.e[0], face.v[1]); InsertEdge(face.v[1], face.v[2]); } - void NPZP_23(uint16 base, Face const &face) + void NPZP_23(uint16 base, Face face) { InsertEdge(base + face.e[0], face.v[1]); InsertEdge(face.v[1], face.v[2]); @@ -208,63 +208,63 @@ namespace cage InsertEdge(face.v[2], face.v[3]); } - void NPPN_24(uint16 base, Face const &face) { InsertEdge(base + face.e[0], base + face.e[2]); } + void NPPN_24(uint16 base, Face face) { InsertEdge(base + face.e[0], base + face.e[2]); } - void NPPZ_25(uint16 base, Face const &face) { InsertEdge(base + face.e[0], face.v[3]); } + void NPPZ_25(uint16 base, Face face) { InsertEdge(base + face.e[0], face.v[3]); } - void NPPP_26(uint16 base, Face const &face) { InsertEdge(base + face.e[0], base + face.e[3]); } + void NPPP_26(uint16 base, Face face) { InsertEdge(base + face.e[0], base + face.e[3]); } - void ZNNP_29(uint16 base, Face const &face) { InsertEdge(base + face.e[2], face.v[0]); } + void ZNNP_29(uint16 base, Face face) { InsertEdge(base + face.e[2], face.v[0]); } - void ZNZP_32(uint16, Face const &face) { InsertEdge(face.v[0], face.v[2]); } + void ZNZP_32(uint16, Face face) { InsertEdge(face.v[0], face.v[2]); } - void ZNPN_33(uint16 base, Face const &face) + void ZNPN_33(uint16 base, Face face) { InsertEdge(base + face.e[1], face.v[2]); InsertEdge(base + face.e[2], face.v[2]); } - void ZNPZ_34(uint16 base, Face const &face) + void ZNPZ_34(uint16 base, Face face) { InsertEdge(base + face.e[1], face.v[2]); InsertEdge(face.v[2], face.v[3]); } - void ZNPP_35(uint16 base, Face const &face) { InsertEdge(face.v[0], base + face.e[1]); } + void ZNPP_35(uint16 base, Face face) { InsertEdge(face.v[0], base + face.e[1]); } - void ZZNP_38(uint16 base, Face const &face) + void ZZNP_38(uint16 base, Face face) { InsertEdge(face.v[0], face.v[3]); InsertEdge(face.v[3], base + face.e[2]); } - void ZZZP_41(uint16, Face const &face) + void ZZZP_41(uint16, Face face) { InsertEdge(face.v[0], face.v[3]); InsertEdge(face.v[3], face.v[2]); } - void ZZPN_42(uint16 base, Face const &face) + void ZZPN_42(uint16 base, Face face) { InsertEdge(face.v[1], face.v[2]); InsertEdge(face.v[2], base + face.e[2]); } - void ZZPZ_43(uint16, Face const &face) + void ZZPZ_43(uint16, Face face) { InsertEdge(face.v[1], face.v[2]); InsertEdge(face.v[2], face.v[3]); } - void ZPNN_45(uint16 base, Face const &face) { InsertEdge(face.v[0], base + face.e[1]); } + void ZPNN_45(uint16 base, Face face) { InsertEdge(face.v[0], base + face.e[1]); } - void ZPNZ_46(uint16 base, Face const &face) + void ZPNZ_46(uint16 base, Face face) { InsertEdge(face.v[0], face.v[1]); InsertEdge(face.v[1], base + face.e[1]); } - void ZPNP_47(uint16 base, Face const &face) + void ZPNP_47(uint16 base, Face face) { InsertEdge(face.v[0], face.v[1]); InsertEdge(face.v[1], base + face.e[1]); @@ -272,37 +272,37 @@ namespace cage InsertEdge(face.v[3], face.v[0]); } - void ZPZN_48(uint16, Face const &face) { InsertEdge(face.v[0], face.v[2]); } + void ZPZN_48(uint16, Face face) { InsertEdge(face.v[0], face.v[2]); } - void ZPZZ_49(uint16, Face const &face) + void ZPZZ_49(uint16, Face face) { InsertEdge(face.v[0], face.v[1]); InsertEdge(face.v[1], face.v[2]); } - void ZPPN_51(uint16 base, Face const &face) { InsertEdge(face.v[0], base + face.e[2]); } + void ZPPN_51(uint16 base, Face face) { InsertEdge(face.v[0], base + face.e[2]); } - void PNNN_54(uint16 base, Face const &face) { InsertEdge(base + face.e[3], base + face.e[0]); } + void PNNN_54(uint16 base, Face face) { InsertEdge(base + face.e[3], base + face.e[0]); } - void PNNZ_55(uint16 base, Face const &face) { InsertEdge(face.v[3], base + face.e[0]); } + void PNNZ_55(uint16 base, Face face) { InsertEdge(face.v[3], base + face.e[0]); } - void PNNP_56(uint16 base, Face const &face) { InsertEdge(base + face.e[2], base + face.e[0]); } + void PNNP_56(uint16 base, Face face) { InsertEdge(base + face.e[2], base + face.e[0]); } - void PNZN_57(uint16 base, Face const &face) + void PNZN_57(uint16 base, Face face) { InsertEdge(base + face.e[3], face.v[0]); InsertEdge(face.v[0], base + face.e[0]); } - void PNZZ_58(uint16 base, Face const &face) + void PNZZ_58(uint16 base, Face face) { InsertEdge(face.v[3], face.v[0]); InsertEdge(face.v[0], base + face.e[0]); } - void PNZP_59(uint16 base, Face const &face) { InsertEdge(face.v[2], base + face.e[0]); } + void PNZP_59(uint16 base, Face face) { InsertEdge(face.v[2], base + face.e[0]); } - void PNPN_60(uint16 base, Face const &face) + void PNPN_60(uint16 base, Face face) { InsertEdge(base + face.e[3], face.v[0]); InsertEdge(face.v[0], base + face.e[0]); @@ -310,7 +310,7 @@ namespace cage InsertEdge(face.v[2], base + face.e[2]); } - void PNPZ_61(uint16 base, Face const &face) + void PNPZ_61(uint16 base, Face face) { InsertEdge(face.v[3], face.v[0]); InsertEdge(face.v[0], base + face.e[0]); @@ -318,21 +318,21 @@ namespace cage InsertEdge(face.v[2], face.v[3]); } - void PNPP_62(uint16 base, Face const &face) { InsertEdge(base + face.e[0], base + face.e[1]); } + void PNPP_62(uint16 base, Face face) { InsertEdge(base + face.e[0], base + face.e[1]); } - void PZNN_63(uint16 base, Face const &face) { InsertEdge(base + face.e[3], face.v[1]); } + void PZNN_63(uint16 base, Face face) { InsertEdge(base + face.e[3], face.v[1]); } - void PZNZ_64(uint16, Face const &face) { InsertEdge(face.v[3], face.v[1]); } + void PZNZ_64(uint16, Face face) { InsertEdge(face.v[3], face.v[1]); } - void PZNP_65(uint16 base, Face const &face) { InsertEdge(base + face.e[2], face.v[1]); } + void PZNP_65(uint16 base, Face face) { InsertEdge(base + face.e[2], face.v[1]); } - void PZZN_66(uint16 base, Face const &face) + void PZZN_66(uint16 base, Face face) { InsertEdge(base + face.e[3], face.v[0]); InsertEdge(face.v[0], face.v[1]); } - void PZPN_69(uint16 base, Face const &face) + void PZPN_69(uint16 base, Face face) { InsertEdge(base + face.e[3], face.v[0]); InsertEdge(face.v[0], face.v[1]); @@ -340,15 +340,15 @@ namespace cage InsertEdge(face.v[2], base + face.e[2]); } - void PPNN_72(uint16 base, Face const &face) { InsertEdge(base + face.e[3], base + face.e[1]); } + void PPNN_72(uint16 base, Face face) { InsertEdge(base + face.e[3], base + face.e[1]); } - void PPNZ_73(uint16 base, Face const &face) { InsertEdge(face.v[3], base + face.e[1]); } + void PPNZ_73(uint16 base, Face face) { InsertEdge(face.v[3], base + face.e[1]); } - void PPNP_74(uint16 base, Face const &face) { InsertEdge(base + face.e[2], base + face.e[1]); } + void PPNP_74(uint16 base, Face face) { InsertEdge(base + face.e[2], base + face.e[1]); } - void PPZN_75(uint16 base, Face const &face) { InsertEdge(base + face.e[2], face.v[2]); } + void PPZN_75(uint16 base, Face face) { InsertEdge(base + face.e[2], face.v[2]); } - void PPPN_78(uint16 base, Face const &face) { InsertEdge(base + face.e[3], base + face.e[2]); } + void PPPN_78(uint16 base, Face face) { InsertEdge(base + face.e[3], base + face.e[2]); } }; consteval std::array initConfiguration() @@ -458,7 +458,7 @@ namespace cage } constexpr const std::array mFaces = initFaces(); - bool TIQuery::BoxFullyInConeSlab(Aabb const &box, Real boxMinHeight, Real boxMaxHeight, Cone const &cone) + bool TIQuery::BoxFullyInConeSlab(Aabb box, Real boxMinHeight, Real boxMaxHeight, Cone cone) { mVertices[0] = Vec3(box.a[0], box.a[1], box.a[2]); mVertices[1] = Vec3(box.b[0], box.a[1], box.a[2]); @@ -480,7 +480,7 @@ namespace cage return false; } - void TIQuery::ComputeCandidatesOnBoxEdges(Cone const &cone) + void TIQuery::ComputeCandidatesOnBoxEdges(Cone cone) { for (uint16 i = 0; i < NUM_BOX_VERTICES; ++i) { @@ -559,7 +559,7 @@ namespace cage } } - bool intersects(const Aabb &box, const Cone &cone) + bool intersects(Aabb box, Cone cone) { TIQuery query; return query(box, cone); diff --git a/sources/libcore/geometry/collider.cpp b/sources/libcore/geometry/collider.cpp index 23cf08bc..2e9bf643 100644 --- a/sources/libcore/geometry/collider.cpp +++ b/sources/libcore/geometry/collider.cpp @@ -129,7 +129,7 @@ namespace cage // actually split the triangles CAGE_ASSERT(axis < 3); CAGE_ASSERT(split > 0 && split < ts.size()); - std::sort(ts.begin(), ts.end(), [axis](const Triangle &a, const Triangle &b) { return a.center()[axis] < b.center()[axis]; }); + std::sort(ts.begin(), ts.end(), [axis](Triangle a, Triangle b) { return a.center()[axis] < b.center()[axis]; }); std::vector left(ts.begin(), ts.begin() + split); std::vector right(ts.begin() + split, ts.end()); @@ -156,7 +156,7 @@ namespace cage { // leaf for (uint32 i = n.left; i < n.right; i++) { - const Triangle &t = tris[i]; + Triangle t = tris[i]; CAGE_ASSERT(intersection(boxes[idx], Aabb(t)) == Aabb(t)); } } @@ -188,7 +188,7 @@ namespace cage return impl->tris; } - void Collider::addTriangle(const Triangle &t) + void Collider::addTriangle(Triangle t) { ColliderImpl *impl = (ColliderImpl *)this; impl->tris.push_back(t); @@ -210,7 +210,7 @@ namespace cage { struct Comparator { - bool operator()(const Vec3 &a, const Vec3 &b) const { return detail::memcmp(&a, &b, sizeof(a)) < 0; } + CAGE_FORCE_INLINE bool operator()(Vec3 a, Vec3 b) const { return detail::memcmp(&a, &b, sizeof(a)) < 0; } }; std::sort(std::begin(t.vertices), std::end(t.vertices), Comparator()); return t; @@ -218,12 +218,12 @@ namespace cage struct Comparator { - bool operator()(const Triangle &a, const Triangle &b) const { return detail::memcmp(&a, &b, sizeof(a)) < 0; } + CAGE_FORCE_INLINE bool operator()(Triangle a, Triangle b) const { return detail::memcmp(&a, &b, sizeof(a)) < 0; } }; std::vector vec; vec.reserve(impl->tris.size()); - for (const Triangle &t : impl->tris) + for (Triangle t : impl->tris) if (!t.degenerated()) vec.push_back(order(t)); auto st = makeFlatSet(std::move(vec)); @@ -260,7 +260,7 @@ namespace cage return impl->dirty; } - const Aabb &Collider::box() const + Aabb Collider::box() const { CAGE_ASSERT(!needsRebuild()); const ColliderImpl *impl = (const ColliderImpl *)this; @@ -368,15 +368,15 @@ namespace cage return systemMemory().createImpl(); } - bool operator<(const CollisionPair &l, const CollisionPair &r) - { - if (l.a == r.a) - return l.b < r.b; - return l.a < r.a; - } - namespace { + CAGE_FORCE_INLINE bool operator<(const CollisionPair &l, const CollisionPair &r) + { + if (l.a == r.a) + return l.b < r.b; + return l.a < r.a; + } + template class LazyData {}; @@ -387,21 +387,21 @@ namespace cage public: std::vector data; std::vector flags; - const Transform m; - const T *const original; + const Transform tr; + const T *const original = nullptr; - LazyData(const T *original, uint32 count, const Transform &m) : m(m), original(original) + LazyData(const T *original, uint32 count, Transform tr) : tr(tr), original(original) { data.resize(count); flags.resize(count, false); } - const T &operator[](uint32 idx) + CAGE_FORCE_INLINE T operator[](uint32 idx) { CAGE_ASSERT(idx < data.size()); if (!flags[idx]) { - data[idx] = original[idx] * m; + data[idx] = original[idx] * tr; flags[idx] = true; } return data[idx]; @@ -412,11 +412,11 @@ namespace cage class LazyData { public: - const T *const original; + const T *const original = nullptr; - LazyData(const T *original, uint32 count, const Transform &m) : original(original) { CAGE_ASSERT(m == Transform()); } + LazyData(const T *original, uint32 count, Transform m) : original(original) { CAGE_ASSERT(m == Transform()); } - const T &operator[](uint32 idx) const { return original[idx]; } + CAGE_FORCE_INLINE T operator[](uint32 idx) const { return original[idx]; } }; template @@ -428,12 +428,12 @@ namespace cage LazyData abs; LazyData bbs; - const ColliderImpl *const ao; - const ColliderImpl *const bo; + const ColliderImpl *const ao = nullptr; + const ColliderImpl *const bo = nullptr; Holder> &outputBuffer; PointerRangeHolder collisions; - CollisionDetector(const ColliderImpl *ao, const ColliderImpl *bo, const Transform &am, const Transform &bm, Holder> &outputBuffer) : ats(ao->tris.data(), numeric_cast(ao->tris.size()), am), bts(bo->tris.data(), numeric_cast(bo->tris.size()), bm), abs(ao->boxes.data(), numeric_cast(ao->boxes.size()), am), bbs(bo->boxes.data(), numeric_cast(bo->boxes.size()), bm), ao(ao), bo(bo), outputBuffer(outputBuffer) {} + CollisionDetector(const ColliderImpl *ao, const ColliderImpl *bo, Transform am, Transform bm, Holder> &outputBuffer) : ats(ao->tris.data(), numeric_cast(ao->tris.size()), am), bts(bo->tris.data(), numeric_cast(bo->tris.size()), bm), abs(ao->boxes.data(), numeric_cast(ao->boxes.size()), am), bbs(bo->boxes.data(), numeric_cast(bo->boxes.size()), bm), ao(ao), bo(bo), outputBuffer(outputBuffer) {} void process(uint32 a, uint32 b) { @@ -450,10 +450,10 @@ namespace cage { for (uint32 ai = an.left; ai < an.right; ai++) { - const Triangle &at = ats[ai]; + Triangle at = ats[ai]; for (uint32 bi = bn.left; bi < bn.right; bi++) { - const Triangle &bt = bts[bi]; + Triangle bt = bts[bi]; if (intersects(at, bt)) { CollisionPair p; @@ -495,7 +495,7 @@ namespace cage } }; - Real timeOfContact(const Collider *ao, const Collider *bo, const Transform &at1, const Transform &bt1, const Transform &at2, const Transform &bt2) + Real timeOfContact(const Collider *ao, const Collider *bo, Transform at1, Transform bt1, Transform at2, Transform bt2) { return 0; /* @@ -519,7 +519,7 @@ namespace cage return min(min(s[0], s[1]), s[2]); } - Real dist(const Line &l, const Vec3 &p) + Real dist(Line l, Vec3 p) { CAGE_ASSERT(l.normalized()); return dot(p - l.origin, l.direction); @@ -531,7 +531,7 @@ namespace cage const ColliderImpl *const col; const Transform m; - IntersectionDetector(const ColliderImpl *collider, const Transform &m) : col(collider), m(m) { CAGE_ASSERT(!collider->dirty); } + IntersectionDetector(const ColliderImpl *collider, Transform m) : col(collider), m(m) { CAGE_ASSERT(!collider->dirty); } template Real distance(const T &l, uint32 nodeIdx) @@ -557,7 +557,7 @@ namespace cage Real d = Real::Infinity(); for (uint32 ti = n.left; ti != n.right; ti++) { - const Triangle &t = col->tris[ti]; + Triangle t = col->tris[ti]; Real p = cage::distance(l, t); if (p.valid() && p < d) d = p; @@ -587,7 +587,7 @@ namespace cage { // leaf for (uint32 ti = n.left; ti != n.right; ti++) { - const Triangle &t = col->tris[ti]; + Triangle t = col->tris[ti]; if (cage::intersects(l, t)) return true; } @@ -601,7 +601,7 @@ namespace cage return intersects(shape * inverse(m), 0); } - bool intersection(const Line &l, uint32 nodeIdx, Vec3 &point, uint32 &triangleIndex) + bool intersection(Line l, uint32 nodeIdx, Vec3 &point, uint32 &triangleIndex) { const Aabb b = col->boxes[nodeIdx]; if (!cage::intersects(l, b)) @@ -651,7 +651,7 @@ namespace cage bool res = false; for (uint32 ti = n.left; ti != n.right; ti++) { - const Triangle &t = col->tris[ti]; + Triangle t = col->tris[ti]; const Vec3 p = cage::intersection(l, t); if (p.valid()) { @@ -669,7 +669,7 @@ namespace cage } } - bool intersection(const Line &l, Vec3 &point, uint32 &triangleIndex) + bool intersection(Line l, Vec3 &point, uint32 &triangleIndex) { Vec3 pt; uint32 ti = 0; @@ -689,10 +689,10 @@ namespace cage { const ColliderImpl *const ao = (const ColliderImpl *)params.ao; const ColliderImpl *const bo = (const ColliderImpl *)params.bo; - const Transform &at1 = params.at1; - const Transform &bt1 = params.bt1; - const Transform &at2 = params.at2; - const Transform &bt2 = params.bt2; + Transform at1 = params.at1; + Transform bt1 = params.bt1; + Transform at2 = params.at2; + Transform bt2 = params.bt2; Real &fractionBefore = params.fractionBefore; Real &fractionContact = params.fractionContact; Holder> &outputBuffer = params.collisionPairs; @@ -794,108 +794,108 @@ namespace cage } } - Real distance(const Line &shape, const Collider *collider, const Transform &t) + Real distance(Line shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Triangle &shape, const Collider *collider, const Transform &t) + Real distance(Triangle shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Plane &shape, const Collider *collider, const Transform &t) + Real distance(Plane shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Sphere &shape, const Collider *collider, const Transform &t) + Real distance(Sphere shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Aabb &shape, const Collider *collider, const Transform &t) + Real distance(Aabb shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Cone &shape, const Collider *collider, const Transform &t) + Real distance(Cone shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Frustum &shape, const Collider *collider, const Transform &t) + Real distance(const Frustum &shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.distance(shape); } - Real distance(const Collider *ao, const Collider *bo, const Transform &at, const Transform &bt) + Real distance(const Collider *ao, const Collider *bo, Transform at, Transform bt) { CAGE_THROW_CRITICAL(Exception, "collider-collider distance"); } - bool intersects(const Line &shape, const Collider *collider, const Transform &t) + bool intersects(Line shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Triangle &shape, const Collider *collider, const Transform &t) + bool intersects(Triangle shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Plane &shape, const Collider *collider, const Transform &t) + bool intersects(Plane shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Sphere &shape, const Collider *collider, const Transform &t) + bool intersects(Sphere shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Aabb &shape, const Collider *collider, const Transform &t) + bool intersects(Aabb shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Cone &shape, const Collider *collider, const Transform &t) + bool intersects(Cone shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Frustum &shape, const Collider *collider, const Transform &t) + bool intersects(const Frustum &shape, const Collider *collider, Transform t) { IntersectionDetector d((const ColliderImpl *)collider, t); return d.intersects(shape); } - bool intersects(const Collider *ao, const Collider *bo, const Transform &at, const Transform &bt) + bool intersects(const Collider *ao, const Collider *bo, Transform at, Transform bt) { CollisionDetectionConfig p(ao, bo, at, bt); return collisionDetection(p); } - Vec3 intersection(const Line &shape, const Collider *collider, const Transform &t) + Vec3 intersection(Line shape, const Collider *collider, Transform t) { uint32 triangleIndex = m; return intersection(shape, collider, t, triangleIndex); } - Vec3 intersection(const Line &shape, const Collider *collider, const Transform &t, uint32 &triangleIndex) + Vec3 intersection(Line shape, const Collider *collider, Transform t, uint32 &triangleIndex) { // todo IntersectionDetector d((const ColliderImpl *)collider, t); diff --git a/sources/libcore/geometry/collisionStructure.cpp b/sources/libcore/geometry/collisionStructure.cpp index 160a4143..e86f67af 100644 --- a/sources/libcore/geometry/collisionStructure.cpp +++ b/sources/libcore/geometry/collisionStructure.cpp @@ -48,7 +48,7 @@ namespace cage resultPairs.clear(); } - bool query(const Collider *collider, const Transform &t) + bool query(const Collider *collider, Transform t) { clear(); spatial->intersection(collider->box() * t); // broad phase @@ -68,7 +68,7 @@ namespace cage return !resultPairs.empty(); } - bool query(const Collider *collider, const Transform &t1, const Transform &t2) + bool query(const Collider *collider, Transform t1, Transform t2) { clear(); Real best = Real::Infinity(); @@ -98,12 +98,12 @@ namespace cage } template - void findPairs(const T &shape) + void findPairs(T shape) { const Item &item = data->allItems.at(resultName); uint32 i = 0; PointerRangeHolder pairs; - for (const Triangle &t : item.c->triangles()) + for (Triangle t : item.c->triangles()) { if (intersects(shape, t * item.t)) { @@ -119,7 +119,7 @@ namespace cage } template - bool query(const T &shape) + bool query(T shape) { clear(); spatial->intersection(Aabb(shape)); // broad phase @@ -144,7 +144,7 @@ namespace cage }; template<> - bool CollisionQueryImpl::query(const Line &shape) + bool CollisionQueryImpl::query(Line shape) { CAGE_ASSERT(shape.normalized()); clear(); @@ -208,49 +208,49 @@ namespace cage t = r.t; } - bool CollisionQuery::query(const Collider *collider, const Transform &t) + bool CollisionQuery::query(const Collider *collider, Transform t) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(collider, t); } - bool CollisionQuery::query(const Collider *collider, const Transform &t1, const Transform &t2) + bool CollisionQuery::query(const Collider *collider, Transform t1, Transform t2) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(collider, t1, t2); } - bool CollisionQuery::query(const Line &shape) + bool CollisionQuery::query(Line shape) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(shape); } - bool CollisionQuery::query(const Triangle &shape) + bool CollisionQuery::query(Triangle shape) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(shape); } - bool CollisionQuery::query(const Plane &shape) + bool CollisionQuery::query(Plane shape) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(shape); } - bool CollisionQuery::query(const Sphere &shape) + bool CollisionQuery::query(Sphere shape) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(shape); } - bool CollisionQuery::query(const Aabb &shape) + bool CollisionQuery::query(Aabb shape) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(shape); } - bool CollisionQuery::query(const Cone &shape) + bool CollisionQuery::query(Cone shape) { CollisionQueryImpl *impl = (CollisionQueryImpl *)this; return impl->query(shape); @@ -262,7 +262,7 @@ namespace cage return impl->query(shape); } - void CollisionStructure::update(uint32 name, Holder collider, const Transform &t) + void CollisionStructure::update(uint32 name, Holder collider, Transform t) { CollisionDataImpl *impl = (CollisionDataImpl *)this; remove(name); diff --git a/sources/libcore/geometry/geometry.cpp b/sources/libcore/geometry/geometry.cpp index 449c68e5..5e24b12b 100644 --- a/sources/libcore/geometry/geometry.cpp +++ b/sources/libcore/geometry/geometry.cpp @@ -8,17 +8,17 @@ namespace cage { namespace { - bool parallel(const Vec3 &dir1, const Vec3 &dir2) + CAGE_FORCE_INLINE bool parallel(Vec3 dir1, Vec3 dir2) { return abs(dot(dir1, dir2)) >= 1 - 1e-5; } - bool perpendicular(const Vec3 &dir1, const Vec3 &dir2) + CAGE_FORCE_INLINE bool perpendicular(Vec3 dir1, Vec3 dir2) { return abs(dot(dir1, dir2)) <= 1e-5; } - Rads angle(const Vec3 &a, const Vec3 &b) + CAGE_FORCE_INLINE Rads angle(Vec3 a, Vec3 b) { CAGE_ASSERT(abs(lengthSquared(a) - 1) < 1e-4); CAGE_ASSERT(abs(lengthSquared(b) - 1) < 1e-4); @@ -26,74 +26,74 @@ namespace cage } } - Rads angle(const Line &a, const Line &b) + Rads angle(Line a, Line b) { return angle(a.direction, b.direction); } - Rads angle(const Line &a, const Triangle &b) + Rads angle(Line a, Triangle b) { return Rads(Degs(90)) - angle(a.direction, b.normal()); } - Rads angle(const Line &a, const Plane &b) + Rads angle(Line a, Plane b) { return Rads(Degs(90)) - angle(a.direction, b.normal); } - Rads angle(const Triangle &a, const Triangle &b) + Rads angle(Triangle a, Triangle b) { return angle(a.normal(), b.normal()); } - Rads angle(const Triangle &a, const Plane &b) + Rads angle(Triangle a, Plane b) { return angle(a.normal(), b.normal); } - Rads angle(const Plane &a, const Plane &b) + Rads angle(Plane a, Plane b) { return angle(a.normal, b.normal); } - Real distance(const Vec3 &a, const Line &b) + Real distance(Vec3 a, Line b) { CAGE_ASSERT(b.normalized()); return distance(closestPoint(b, a), a); } - Real distance(const Vec3 &a, const Triangle &b) + Real distance(Vec3 a, Triangle b) { return distance(closestPoint(b, a), a); } - Real distance(const Vec3 &a, const Plane &b) + Real distance(Vec3 a, Plane b) { return distance(closestPoint(b, a), a); } - Real distance(const Vec3 &a, const Sphere &b) + Real distance(Vec3 a, Sphere b) { return max(distance(a, b.center) - b.radius, Real(0)); } - Real distance(const Vec3 &a, const Aabb &b) + Real distance(Vec3 a, Aabb b) { Vec3 c = max(min(a, b.b), b.a); return distance(c, a); } - Real distance(const Vec3 &a, const Cone &b) + Real distance(Vec3 a, Cone b) { return distance(a, closestPoint(a, b)); } - Real distance(const Vec3 &a, const Frustum &b) + Real distance(Vec3 a, const Frustum &b) { return distance(a, closestPoint(a, b)); } - Real distance(const Line &a, const Triangle &b) + Real distance(Line a, Triangle b) { Real d = Real::Infinity(); if (a.isSegment() || a.isRay() || a.isPoint()) @@ -113,34 +113,34 @@ namespace cage return min(distance(q, a), d); } - Real distance(const Line &a, const Plane &b) + Real distance(Line a, Plane b) { if (intersects(a, b)) return 0; return min(distance(a.a(), b), distance(a.b(), b)); } - Real distance(const Line &a, const Sphere &b) + Real distance(Line a, Sphere b) { return max(distance(a, b.center) - b.radius, Real(0)); } - Real distance(const Line &a, const Aabb &b) + Real distance(Line a, Aabb b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Line &a, const Cone &b) + Real distance(Line a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Line &a, const Frustum &b) + Real distance(Line a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Triangle &a, const Triangle &b) + Real distance(Triangle a, Triangle b) { if (intersects(a, b)) return 0; @@ -153,19 +153,19 @@ namespace cage return d; } - Real distance(const Triangle &a, const Plane &b) + Real distance(Triangle a, Plane b) { if (intersects(a, b)) return 0; return min(min(distance(a[0], b), distance(a[1], b)), distance(a[2], b)); } - Real distance(const Triangle &a, const Sphere &b) + Real distance(Triangle a, Sphere b) { return max(distance(a, b.center) - b.radius, Real(0)); } - Real distance(const Triangle &a, const Aabb &b) + Real distance(Triangle a, Aabb b) { if (intersects(a, b)) return 0; @@ -180,17 +180,17 @@ namespace cage return d; } - Real distance(const Triangle &a, const Cone &b) + Real distance(Triangle a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Triangle &a, const Frustum &b) + Real distance(Triangle a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Plane &a, const Plane &b) + Real distance(Plane a, Plane b) { CAGE_ASSERT(a.normalized() && b.normalized()); if (parallel(a.normal, b.normal)) @@ -198,47 +198,47 @@ namespace cage return 0; } - Real distance(const Plane &a, const Sphere &b) + Real distance(Plane a, Sphere b) { return max(distance(a, b.center) - b.radius, Real(0)); } - Real distance(const Plane &a, const Aabb &b) + Real distance(Plane a, Aabb b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Plane &a, const Cone &b) + Real distance(Plane a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Plane &a, const Frustum &b) + Real distance(Plane a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Sphere &a, const Sphere &b) + Real distance(Sphere a, Sphere b) { return max(distance(a.center, b.center) - a.radius - b.radius, Real(0)); } - Real distance(const Sphere &a, const Aabb &b) + Real distance(Sphere a, Aabb b) { return max(distance(a.center, b) - a.radius, Real(0)); } - Real distance(const Sphere &a, const Cone &b) + Real distance(Sphere a, Cone b) { return max(distance(a.center, b) - a.radius, Real(0)); } - Real distance(const Sphere &a, const Frustum &b) + Real distance(Sphere a, const Frustum &b) { return max(distance(a.center, b) - a.radius, Real(0)); } - Real distance(const Aabb &a, const Aabb &b) + Real distance(Aabb a, Aabb b) { // https://groups.google.com/g/comp.graphics.algorithms/c/hbu10Xc7JcY modified Real res = 0; @@ -252,22 +252,22 @@ namespace cage return sqrt(res); } - Real distance(const Aabb &a, const Cone &b) + Real distance(Aabb a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Aabb &a, const Frustum &b) + Real distance(Aabb a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Cone &a, const Cone &b) + Real distance(Cone a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Real distance(const Cone &a, const Frustum &b) + Real distance(Cone a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } @@ -277,32 +277,32 @@ namespace cage CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Vec3 &a, const Vec3 &b) + bool intersects(Vec3 a, Vec3 b) { return distance(a, b) <= 1e-5; } - bool intersects(const Vec3 &point, const Line &other) + bool intersects(Vec3 point, Line other) { return distance(point, other) <= 1e-5; } - bool intersects(const Vec3 &point, const Triangle &other) + bool intersects(Vec3 point, Triangle other) { return distance(point, other) <= 1e-5; } - bool intersects(const Vec3 &point, const Plane &other) + bool intersects(Vec3 point, Plane other) { return distance(point, other) <= 1e-5; } - bool intersects(const Vec3 &point, const Sphere &other) + bool intersects(Vec3 point, Sphere other) { return distanceSquared(point, other.center) <= sqr(other.radius); } - bool intersects(const Vec3 &point, const Aabb &other) + bool intersects(Vec3 point, Aabb other) { for (uint32 i = 0; i < 3; i++) { @@ -312,12 +312,12 @@ namespace cage return true; } - bool intersects(const Vec3 &a, const Cone &b) + bool intersects(Vec3 a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Vec3 &point, const Frustum &frustum) + bool intersects(Vec3 point, const Frustum &frustum) { for (uint32 i = 0; i < 6; i++) { @@ -329,12 +329,12 @@ namespace cage return true; } - bool intersects(const Line &a, const Line &b) + bool intersects(Line a, Line b) { return distance(a, b) <= 1e-5; } - bool intersects(const Line &ray, const Triangle &tri) + bool intersects(Line ray, Triangle tri) { Vec3 v0 = tri[0]; Vec3 v1 = tri[1]; @@ -360,7 +360,7 @@ namespace cage return true; } - bool intersects(const Line &a, const Plane &b) + bool intersects(Line a, Plane b) { if (a.isLine()) { @@ -384,27 +384,27 @@ namespace cage } } - bool intersects(const Line &a, const Sphere &b) + bool intersects(Line a, Sphere b) { return distance(a, b.center) <= b.radius; } - bool intersects(const Line &a, const Aabb &b) + bool intersects(Line a, Aabb b) { return intersection(a, b).valid(); } - bool intersects(const Line &a, const Cone &b) + bool intersects(Line a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Line &a, const Frustum &b) + bool intersects(Line a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Triangle &a, const Plane &b) + bool intersects(Triangle a, Plane b) { uint32 sigs[3] = { 0, 0, 0 }; for (uint32 i = 0; i < 3; i++) @@ -414,22 +414,22 @@ namespace cage return sigs[0] > 0 && sigs[2] > 0; } - bool intersects(const Triangle &a, const Sphere &b) + bool intersects(Triangle a, Sphere b) { return distance(a, b.center) <= b.radius; } - bool intersects(const Triangle &a, const Cone &b) + bool intersects(Triangle a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Triangle &a, const Frustum &b) + bool intersects(Triangle a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Plane &a, const Plane &b) + bool intersects(Plane a, Plane b) { CAGE_ASSERT(a.normalized() && b.normalized()); if (parallel(a.normal, b.normal)) @@ -437,12 +437,12 @@ namespace cage return true; } - bool intersects(const Plane &a, const Sphere &b) + bool intersects(Plane a, Sphere b) { return distance(a, b.center) <= b.radius; } - bool intersects(const Plane &a, const Aabb &b) + bool intersects(Plane a, Aabb b) { Vec3 c = b.center(); Vec3 e = b.size() * 0.5; @@ -451,27 +451,27 @@ namespace cage return abs(s) <= r; } - bool intersects(const Plane &a, const Cone &b) + bool intersects(Plane a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Plane &a, const Frustum &b) + bool intersects(Plane a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Sphere &a, const Sphere &b) + bool intersects(Sphere a, Sphere b) { return distanceSquared(a.center, b.center) <= sqr(a.radius + b.radius); } - bool intersects(const Sphere &a, const Aabb &b) + bool intersects(Sphere a, Aabb b) { return distance(a.center, b) <= a.radius; } - bool intersects(const Sphere &sphere, const Cone &cone) + bool intersects(Sphere sphere, Cone cone) { // https://bartwronski.com/2017/04/13/cull-that-cone/ modified const Vec3 V = sphere.center - cone.origin; @@ -484,7 +484,7 @@ namespace cage return !(angleCull || frontCull || backCull); } - bool intersects(const Sphere &sphere, const Frustum &frustum) + bool intersects(Sphere sphere, const Frustum &frustum) { // https://www.flipcode.com/archives/Frustum_Culling.shtml modified for (int i = 0; i < 6; i++) @@ -496,7 +496,7 @@ namespace cage return true; } - bool intersects(const Aabb &a, const Aabb &b) + bool intersects(Aabb a, Aabb b) { if (a.empty() || b.empty()) return false; @@ -510,7 +510,7 @@ namespace cage return true; } - bool intersects(const Aabb &box, const Frustum &frustum) + bool intersects(Aabb box, const Frustum &frustum) { const Vec3 b[] = { box.a, box.b }; for (uint32 i = 0; i < 6; i++) @@ -525,17 +525,17 @@ namespace cage return true; } - bool intersects(const Cone &a, const Cone &b) + bool intersects(Cone a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - bool intersects(const Cone &a, const Frustum &b) + bool intersects(Cone a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Vec3 intersection(const Line &ray, const Triangle &tri) + Vec3 intersection(Line ray, Triangle tri) { Vec3 v0 = tri[0]; Vec3 v1 = tri[1]; @@ -561,7 +561,7 @@ namespace cage return ray.origin + t * ray.direction; } - Vec3 intersection(const Line &a, const Plane &b) + Vec3 intersection(Line a, Plane b) { CAGE_ASSERT(a.normalized()); Real numer = dot(b.origin() - a.origin, b.normal); @@ -579,7 +579,7 @@ namespace cage return a.origin + a.direction * d; // single intersection } - Line intersection(const Line &a, const Sphere &b) + Line intersection(Line a, Sphere b) { CAGE_ASSERT(a.normalized()); Vec3 l = b.center - a.origin; @@ -597,7 +597,7 @@ namespace cage return Line(a.origin, a.direction, max(a.minimum, t0), min(a.maximum, t1)); } - Line intersection(const Line &a, const Aabb &b) + Line intersection(Line a, Aabb b) { CAGE_ASSERT(a.normalized()); Real tmin = a.minimum; @@ -615,17 +615,17 @@ namespace cage return Line(); } - Line intersection(const Line &a, const Cone &b) + Line intersection(Line a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Line intersection(const Line &a, const Frustum &b) + Line intersection(Line a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Aabb intersection(const Aabb &a, const Aabb &b) + Aabb intersection(Aabb a, Aabb b) { if (intersects(a, b)) return Aabb(max(a.a, b.a), min(a.b, b.b)); @@ -633,14 +633,14 @@ namespace cage return Aabb(); } - Vec3 closestPoint(const Vec3 &p, const Line &l) + Vec3 closestPoint(Vec3 p, Line l) { Real d = dot(p - l.origin, l.direction); d = clamp(d, l.minimum, l.maximum); return l.origin + l.direction * d; } - Vec3 closestPoint(const Vec3 &sourcePosition, const Triangle &trig) + Vec3 closestPoint(Vec3 sourcePosition, Triangle trig) { const Vec3 p = closestPoint(Plane(trig), sourcePosition); { @@ -670,30 +670,30 @@ namespace cage return pca; } - Vec3 closestPoint(const Vec3 &pt, const Plane &pl) + Vec3 closestPoint(Vec3 pt, Plane pl) { CAGE_ASSERT(pl.normalized()); return pt - dot(pl.normal, pt - pl.origin()) * pl.normal; } - Vec3 closestPoint(const Vec3 &a, const Sphere &b) + Vec3 closestPoint(Vec3 a, Sphere b) { if (distanceSquared(a, b.center) > sqr(b.radius)) return normalize(a - b.center) * b.radius + b.center; return a; } - Vec3 closestPoint(const Vec3 &a, const Aabb &b) + Vec3 closestPoint(Vec3 a, Aabb b) { return clamp(a, b.a, b.b); } - Vec3 closestPoint(const Vec3 &a, const Cone &b) + Vec3 closestPoint(Vec3 a, Cone b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Vec3 closestPoint(const Vec3 &a, const Frustum &b) + Vec3 closestPoint(Vec3 a, const Frustum &b) { CAGE_THROW_CRITICAL(Exception, "geometry"); } diff --git a/sources/libcore/geometry/linesDistances.cpp b/sources/libcore/geometry/linesDistances.cpp index 6814192e..8270dc32 100644 --- a/sources/libcore/geometry/linesDistances.cpp +++ b/sources/libcore/geometry/linesDistances.cpp @@ -4,7 +4,7 @@ namespace cage { namespace { - Real distanceLines(const Vec3 a1, const Vec3 &a2, const Vec3 &b1, const Vec3 &b2) + Real distanceLines(const Vec3 a1, const Vec3 a2, const Vec3 b1, const Vec3 b2) { // algorithm taken from http://geomalgorithms.com/a07-_distance.html and modified @@ -39,7 +39,7 @@ namespace cage return length(dP); } - Real distanceSegments(const Vec3 a1, const Vec3 &a2, const Vec3 &b1, const Vec3 &b2) + Real distanceSegments(const Vec3 a1, const Vec3 a2, const Vec3 b1, const Vec3 b2) { // algorithm taken from http://geomalgorithms.com/a07-_distance.html and modified @@ -118,7 +118,7 @@ namespace cage } } - Real distance(const Line &a, const Line &b) + Real distance(Line a, Line b) { if (a.isLine() && b.isLine()) return distanceLines(a.origin, a.origin + a.direction, b.origin, b.origin + b.direction); diff --git a/sources/libcore/geometry/minimumBoundingSphere.cpp b/sources/libcore/geometry/minimumBoundingSphere.cpp index f979e454..ca7fd13f 100644 --- a/sources/libcore/geometry/minimumBoundingSphere.cpp +++ b/sources/libcore/geometry/minimumBoundingSphere.cpp @@ -8,19 +8,19 @@ namespace cage namespace { - Sphere MbSphere(const Vec3 &O) + Sphere MbSphere(Vec3 O) { return Sphere(O, 1e-5); } - Sphere MbSphere(const Vec3 &O, const Vec3 &A) + Sphere MbSphere(Vec3 O, Vec3 A) { Vec3 a = A - O; Vec3 o = a * 0.5; return Sphere(O + o, length(o) + 1e-5); } - Sphere MbSphere(const Vec3 &O, const Vec3 &A, const Vec3 &B) + Sphere MbSphere(Vec3 O, Vec3 A, Vec3 B) { Vec3 a = A - O; Vec3 b = B - O; @@ -29,7 +29,7 @@ namespace cage return Sphere(O + o, length(o) + 1e-5); } - Sphere MbSphere(const Vec3 &O, const Vec3 &A, const Vec3 &B, const Vec3 &C) + Sphere MbSphere(Vec3 O, Vec3 A, Vec3 B, Vec3 C) { Vec3 a = A - O; Vec3 b = B - O; @@ -39,7 +39,7 @@ namespace cage return Sphere(O + o, length(o) + 1e-5); } - Real d2(const Sphere &s, const Vec3 &p) + Real d2(Sphere s, Vec3 p) { return distanceSquared(p, s.center) - sqr(s.radius); } diff --git a/sources/libcore/geometry/shapes.cpp b/sources/libcore/geometry/shapes.cpp index 3ffd9c89..d24f869e 100644 --- a/sources/libcore/geometry/shapes.cpp +++ b/sources/libcore/geometry/shapes.cpp @@ -2,11 +2,11 @@ namespace cage { - Line Line::operator*(const Mat4 &other) const + Line Line::operator*(Mat4 other) const { CAGE_ASSERT(normalized()); - const auto &tr = [&](const Vec3 &p) + const auto &tr = [&](Vec3 p) { Vec4 t = other * Vec4(p, 1); return Vec3(t) / t[3]; @@ -90,22 +90,22 @@ namespace cage return r; } - Line makeSegment(const Vec3 &a, const Vec3 &b) + Line makeSegment(Vec3 a, Vec3 b) { return Line(a, b - a, 0, 1).normalize(); } - Line makeRay(const Vec3 &a, const Vec3 &b) + Line makeRay(Vec3 a, Vec3 b) { return Line(a, b - a, 0, Real::Infinity()).normalize(); } - Line makeLine(const Vec3 &a, const Vec3 &b) + Line makeLine(Vec3 a, Vec3 b) { return Line(a, b - a, -Real::Infinity(), Real::Infinity()).normalize(); } - Triangle Triangle::operator*(const Mat4 &other) const + Triangle Triangle::operator*(Mat4 other) const { Triangle r = *this; for (uint32 i = 0; i < 3; i++) @@ -128,15 +128,15 @@ namespace cage return r; } - Plane::Plane(const Vec3 &point, const Vec3 &normal) : normal(normal), d(-dot(point, normal)) {} + Plane::Plane(Vec3 point, Vec3 normal) : normal(normal), d(-dot(point, normal)) {} - Plane::Plane(const Vec3 &a, const Vec3 &b, const Vec3 &c) : Plane(Triangle(a, b, c)) {} + Plane::Plane(Vec3 a, Vec3 b, Vec3 c) : Plane(Triangle(a, b, c)) {} - Plane::Plane(const Triangle &other) : Plane(other[0], other.normal()) {} + Plane::Plane(Triangle other) : Plane(other[0], other.normal()) {} - Plane::Plane(const Line &a, const Vec3 &b) : Plane(a.origin, a.origin + a.direction, b) {} + Plane::Plane(Line a, Vec3 b) : Plane(a.origin, a.origin + a.direction, b) {} - Plane Plane::operator*(const Mat4 &other) const + Plane Plane::operator*(Mat4 other) const { Vec3 p3 = normal * d; Vec4 p4 = Vec4(p3, 1) * other; @@ -155,7 +155,7 @@ namespace cage return Plane(normal / l, d * l); // d times or divided by l ? } - Sphere::Sphere(const Line &other) + Sphere::Sphere(Line other) { if (!other.valid()) *this = Sphere(); @@ -171,7 +171,7 @@ namespace cage *this = Sphere(Vec3(), Real::Infinity()); } - Sphere::Sphere(const Triangle &other) + Sphere::Sphere(Triangle other) { Vec3 a = other[0]; Vec3 b = other[1]; @@ -206,7 +206,7 @@ namespace cage radius = distance(center, referencePt); } - Sphere::Sphere(const Cone &other) + Sphere::Sphere(Cone other) { // https://bartwronski.com/2017/04/13/cull-that-cone/ modified if (other.halfAngle > Rads(Real::Pi() / 4)) @@ -220,7 +220,7 @@ namespace cage } } - Sphere Sphere::operator*(const Mat4 &other) const + Sphere Sphere::operator*(Mat4 other) const { Real sx2 = lengthSquared(Vec3(other[0], other[1], other[2])); Real sy2 = lengthSquared(Vec3(other[4], other[5], other[6])); @@ -230,7 +230,7 @@ namespace cage return Sphere(Vec3(p4) / p4[3], radius * s); } - Aabb::Aabb(const Line &other) + Aabb::Aabb(Line other) { if (!other.valid()) *this = Aabb(); @@ -244,7 +244,7 @@ namespace cage *this = Aabb::Universe(); } - Aabb::Aabb(const Plane &other) + Aabb::Aabb(Plane other) { CAGE_ASSERT(other.normalized()); *this = Aabb::Universe(); @@ -257,18 +257,18 @@ namespace cage } // todo optimize - Aabb::Aabb(const Cone &other) : Aabb(Sphere(other)) {} + Aabb::Aabb(Cone other) : Aabb(Sphere(other)) {} Aabb::Aabb(const Frustum &other) { Aabb box; Frustum::Corners corners = other.corners(); - for (const Vec3 &v : corners.data) + for (Vec3 v : corners.data) box += Aabb(v); *this = box; } - Aabb Aabb::operator+(const Aabb &other) const + Aabb Aabb::operator+(Aabb other) const { if (other.empty()) return *this; @@ -277,7 +277,7 @@ namespace cage return Aabb(min(a, other.a), max(b, other.b)); } - Aabb Aabb::operator*(const Mat4 &other) const + Aabb Aabb::operator*(Mat4 other) const { Vec3 tmp[8]; tmp[0] = Vec3(b.data[0], a.data[1], a.data[2]); @@ -310,14 +310,14 @@ namespace cage return (wx * wy + wx * wz + wy * wz) * 2; } - Cone Cone::operator*(const Mat4 &other) const + Cone Cone::operator*(Mat4 other) const { CAGE_THROW_CRITICAL(Exception, "geometry"); } - Frustum::Frustum(const Transform &camera, const Mat4 &proj) : Frustum(proj * Mat4(inverse(camera))) {} + Frustum::Frustum(Transform camera, Mat4 proj) : Frustum(proj * Mat4(inverse(camera))) {} - Frustum::Frustum(const Mat4 &viewProj) : viewProj(viewProj) + Frustum::Frustum(Mat4 viewProj) : viewProj(viewProj) { const auto &column = [&](uint32 index) { return Vec4(viewProj[index], viewProj[index + 4], viewProj[index + 8], viewProj[index + 12]); }; const Vec4 c0 = column(0); @@ -332,7 +332,7 @@ namespace cage planes[5] = c3 - c2; } - Frustum Frustum::operator*(const Mat4 &other) const + Frustum Frustum::operator*(Mat4 other) const { return Frustum(viewProj * other); } @@ -352,7 +352,7 @@ namespace cage }; Frustum::Corners res; int i = 0; - for (const Vec3 &v : clipCorners) + for (Vec3 v : clipCorners) { const Vec4 p = invVP * Vec4(v, 1); res.data[i++] = Vec3(p) / p[3]; diff --git a/sources/libcore/geometry/spatialStructure.cpp b/sources/libcore/geometry/spatialStructure.cpp index b3bfc307..ec4e95cb 100644 --- a/sources/libcore/geometry/spatialStructure.cpp +++ b/sources/libcore/geometry/spatialStructure.cpp @@ -43,13 +43,13 @@ namespace cage high.v4 = Vec4(Vec3(-Real::Infinity()), 0.0f); } - CAGE_FORCE_INLINE explicit FastBox(const Aabb &b) + CAGE_FORCE_INLINE explicit FastBox(Aabb b) { low.s.v3 = b.a; high.s.v3 = b.b; } - CAGE_FORCE_INLINE FastBox operator+(const FastBox &other) const + CAGE_FORCE_INLINE FastBox operator+(FastBox other) const { FastBox r; r.low.v4 = min(low.v4, other.low.v4); @@ -57,7 +57,7 @@ namespace cage return r; } - CAGE_FORCE_INLINE FastBox &operator+=(const FastBox &other) { return *this = *this + other; } + CAGE_FORCE_INLINE FastBox &operator+=(FastBox other) { return *this = *this + other; } CAGE_FORCE_INLINE Real surface() const { @@ -77,7 +77,7 @@ namespace cage } }; - CAGE_FORCE_INLINE bool intersects(const FastBox &a, const FastBox &b) + CAGE_FORCE_INLINE bool intersects(FastBox a, FastBox b) { CAGE_ASSERT(uintPtr(&a) % alignof(FastBox) == 0); CAGE_ASSERT(uintPtr(&b) % alignof(FastBox) == 0); @@ -94,12 +94,12 @@ namespace cage const uint32 name; virtual Aabb getBox() const = 0; - virtual bool intersects(const Line &other) = 0; - virtual bool intersects(const Triangle &other) = 0; - virtual bool intersects(const Plane &other) = 0; - virtual bool intersects(const Sphere &other) = 0; - virtual bool intersects(const Aabb &other) = 0; - virtual bool intersects(const Cone &other) = 0; + virtual bool intersects(Line other) = 0; + virtual bool intersects(Triangle other) = 0; + virtual bool intersects(Plane other) = 0; + virtual bool intersects(Sphere other) = 0; + virtual bool intersects(Aabb other) = 0; + virtual bool intersects(Cone other) = 0; virtual bool intersects(const Frustum &other) = 0; CAGE_FORCE_INLINE ItemBase(uint32 name) : name(name) {} @@ -115,15 +115,15 @@ namespace cage template struct ItemShape : public ItemBase, public T { - CAGE_FORCE_INLINE ItemShape(uint32 name, const T &other) : ItemBase(name), T(other) { update(); } + CAGE_FORCE_INLINE ItemShape(uint32 name, T other) : ItemBase(name), T(other) { update(); } virtual Aabb getBox() const { return Aabb(*(T *)this); } - virtual bool intersects(const Line &other) { return cage::intersects(*(T *)this, other); }; - virtual bool intersects(const Triangle &other) { return cage::intersects(*(T *)this, other); }; - virtual bool intersects(const Plane &other) { return cage::intersects(*(T *)this, other); }; - virtual bool intersects(const Sphere &other) { return cage::intersects(*(T *)this, other); }; - virtual bool intersects(const Aabb &other) { return cage::intersects(*(T *)this, other); }; - virtual bool intersects(const Cone &other) { return cage::intersects(*(T *)this, other); }; + virtual bool intersects(Line other) { return cage::intersects(*(T *)this, other); }; + virtual bool intersects(Triangle other) { return cage::intersects(*(T *)this, other); }; + virtual bool intersects(Plane other) { return cage::intersects(*(T *)this, other); }; + virtual bool intersects(Sphere other) { return cage::intersects(*(T *)this, other); }; + virtual bool intersects(Aabb other) { return cage::intersects(*(T *)this, other); }; + virtual bool intersects(Cone other) { return cage::intersects(*(T *)this, other); }; virtual bool intersects(const Frustum &other) { return cage::intersects(*(T *)this, other); }; }; @@ -131,7 +131,7 @@ namespace cage { FastBox box; - CAGE_FORCE_INLINE Node(const FastBox &box, sint32 a, sint32 b) : box(box) + CAGE_FORCE_INLINE Node(FastBox box, sint32 a, sint32 b) : box(box) { this->a() = a; this->b() = b; @@ -271,7 +271,7 @@ namespace cage node.b() = -rightNodeIndex; } - static bool similar(const FastBox &a, const FastBox &b) { return (length(a.low.s.v3 - b.low.s.v3) + length(a.high.s.v3 - b.high.s.v3)) < 1e-3; } + static bool similar(FastBox a, FastBox b) { return (length(a.low.s.v3 - b.low.s.v3) + length(a.high.s.v3 - b.high.s.v3)) < 1e-3; } void validate(uint32 nodeIndex) { @@ -381,7 +381,7 @@ namespace cage }; template - CAGE_FORCE_INLINE bool intersection(const T &other) + CAGE_FORCE_INLINE bool intersection(T other) { CAGE_ASSERT(!data->dirty); clear(); @@ -399,42 +399,42 @@ namespace cage return impl->resultNames; } - bool SpatialQuery::intersection(const Vec3 &shape) + bool SpatialQuery::intersection(Vec3 shape) { return intersection(Aabb(shape, shape)); } - bool SpatialQuery::intersection(const Line &shape) + bool SpatialQuery::intersection(Line shape) { SpatialQueryImpl *impl = (SpatialQueryImpl *)this; return impl->intersection(shape); } - bool SpatialQuery::intersection(const Triangle &shape) + bool SpatialQuery::intersection(Triangle shape) { SpatialQueryImpl *impl = (SpatialQueryImpl *)this; return impl->intersection(shape); } - bool SpatialQuery::intersection(const Plane &shape) + bool SpatialQuery::intersection(Plane shape) { SpatialQueryImpl *impl = (SpatialQueryImpl *)this; return impl->intersection(shape); } - bool SpatialQuery::intersection(const Sphere &shape) + bool SpatialQuery::intersection(Sphere shape) { SpatialQueryImpl *impl = (SpatialQueryImpl *)this; return impl->intersection(shape); } - bool SpatialQuery::intersection(const Aabb &shape) + bool SpatialQuery::intersection(Aabb shape) { SpatialQueryImpl *impl = (SpatialQueryImpl *)this; return impl->intersection(shape); } - bool SpatialQuery::intersection(const Cone &shape) + bool SpatialQuery::intersection(Cone shape) { SpatialQueryImpl *impl = (SpatialQueryImpl *)this; return impl->intersection(shape); @@ -446,12 +446,12 @@ namespace cage return impl->intersection(shape); } - void SpatialStructure::update(uint32 name, const Vec3 &other) + void SpatialStructure::update(uint32 name, Vec3 other) { update(name, Aabb(other, other)); } - void SpatialStructure::update(uint32 name, const Line &other) + void SpatialStructure::update(uint32 name, Line other) { CAGE_ASSERT(other.valid()); CAGE_ASSERT(other.isPoint() || other.isSegment()); @@ -460,7 +460,7 @@ namespace cage impl->itemsTable[name] = impl->itemsArena.createImpl>(name, other); } - void SpatialStructure::update(uint32 name, const Triangle &other) + void SpatialStructure::update(uint32 name, Triangle other) { CAGE_ASSERT(other.valid()); CAGE_ASSERT(other.area() < Real::Infinity()); @@ -469,7 +469,7 @@ namespace cage impl->itemsTable[name] = impl->itemsArena.createImpl>(name, other); } - void SpatialStructure::update(uint32 name, const Sphere &other) + void SpatialStructure::update(uint32 name, Sphere other) { CAGE_ASSERT(other.valid()); CAGE_ASSERT(other.volume() < Real::Infinity()); @@ -478,7 +478,7 @@ namespace cage impl->itemsTable[name] = impl->itemsArena.createImpl>(name, other); } - void SpatialStructure::update(uint32 name, const Aabb &other) + void SpatialStructure::update(uint32 name, Aabb other) { CAGE_ASSERT(other.valid()); CAGE_ASSERT(other.volume() < Real::Infinity()); @@ -487,7 +487,7 @@ namespace cage impl->itemsTable[name] = impl->itemsArena.createImpl>(name, other); } - void SpatialStructure::update(uint32 name, const Cone &other) + void SpatialStructure::update(uint32 name, Cone other) { CAGE_ASSERT(other.valid()); SpatialDataImpl *impl = (SpatialDataImpl *)this; diff --git a/sources/libcore/geometry/triangleBox.cpp b/sources/libcore/geometry/triangleBox.cpp index 55b1c111..f76fc773 100644 --- a/sources/libcore/geometry/triangleBox.cpp +++ b/sources/libcore/geometry/triangleBox.cpp @@ -45,7 +45,7 @@ namespace cage return false; } - bool axisTestX01(Real a, Real b, Real fa, Real fb, const Vec3 &v0, const Vec3 &v2, const Vec3 &boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p2) + bool axisTestX01(Real a, Real b, Real fa, Real fb, Vec3 v0, Vec3 v2, Vec3 boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p2) { p0 = a * v0[1] - b * v0[2]; p2 = a * v2[1] - b * v2[2]; @@ -65,7 +65,7 @@ namespace cage return true; } - bool axisTestX2(Real a, Real b, Real fa, Real fb, const Vec3 &v0, const Vec3 &v1, const Vec3 &boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p1) + bool axisTestX2(Real a, Real b, Real fa, Real fb, Vec3 v0, Vec3 v1, Vec3 boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p1) { p0 = a * v0[1] - b * v0[2]; p1 = a * v1[1] - b * v1[2]; @@ -85,7 +85,7 @@ namespace cage return true; } - bool axisTestY02(Real a, Real b, Real fa, Real fb, const Vec3 &v0, const Vec3 &v2, const Vec3 &boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p2) + bool axisTestY02(Real a, Real b, Real fa, Real fb, Vec3 v0, Vec3 v2, Vec3 boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p2) { p0 = -a * v0[0] + b * v0[2]; p2 = -a * v2[0] + b * v2[2]; @@ -105,7 +105,7 @@ namespace cage return true; } - bool axisTestY1(Real a, Real b, Real fa, Real fb, const Vec3 &v0, const Vec3 &v1, const Vec3 &boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p1) + bool axisTestY1(Real a, Real b, Real fa, Real fb, Vec3 v0, Vec3 v1, Vec3 boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p1) { p0 = -a * v0[0] + b * v0[2]; p1 = -a * v1[0] + b * v1[2]; @@ -125,7 +125,7 @@ namespace cage return true; } - bool axisTestZ12(Real a, Real b, Real fa, Real fb, const Vec3 &v1, const Vec3 &v2, const Vec3 &boxhalfsize, Real &rad, Real &min, Real &max, Real &p1, Real &p2) + bool axisTestZ12(Real a, Real b, Real fa, Real fb, Vec3 v1, Vec3 v2, Vec3 boxhalfsize, Real &rad, Real &min, Real &max, Real &p1, Real &p2) { p1 = a * v1[0] - b * v1[1]; p2 = a * v2[0] - b * v2[1]; @@ -145,7 +145,7 @@ namespace cage return true; } - bool axisTestZ0(Real a, Real b, Real fa, Real fb, const Vec3 &v0, const Vec3 &v1, const Vec3 &boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p1) + bool axisTestZ0(Real a, Real b, Real fa, Real fb, Vec3 v0, Vec3 v1, Vec3 boxhalfsize, Real &rad, Real &min, Real &max, Real &p0, Real &p1) { p0 = a * v0[0] - b * v0[1]; p1 = a * v1[0] - b * v1[1]; @@ -165,7 +165,7 @@ namespace cage return true; } - bool triBoxOverlap(const Vec3 &boxcenter, const Vec3 &boxhalfsize, const Vec3 &tv0, const Vec3 &tv1, const Vec3 &tv2) + bool triBoxOverlap(Vec3 boxcenter, Vec3 boxhalfsize, Vec3 tv0, Vec3 tv1, Vec3 tv2) { Vec3 v0, v1, v2; Real min, max, p0, p1, p2, rad, fex, fey, fez; @@ -219,7 +219,7 @@ namespace cage } } - bool intersects(const Triangle &a, const Aabb &b) + bool intersects(Triangle a, Aabb b) { return triBoxOverlap(b.center(), b.size() * 0.5, a[0], a[1], a[2]); } diff --git a/sources/libcore/geometry/triangleTriangle.cpp b/sources/libcore/geometry/triangleTriangle.cpp index 496c01e9..d24570f0 100644 --- a/sources/libcore/geometry/triangleTriangle.cpp +++ b/sources/libcore/geometry/triangleTriangle.cpp @@ -536,13 +536,13 @@ namespace cage { Number data[3] = {}; CAGE_FORCE_INLINE V() {} - CAGE_FORCE_INLINE V(const Vec3 &a) : data{ a[0].value, a[1].value, a[2].value } {} + CAGE_FORCE_INLINE V(Vec3 a) : data{ a[0].value, a[1].value, a[2].value } {} CAGE_FORCE_INLINE operator Number *() noexcept { return data; }; CAGE_FORCE_INLINE operator Vec3() const noexcept { return Vec3(data[0], data[1], data[2]); } }; } - bool intersects(const Triangle &a, const Triangle &b) + bool intersects(Triangle a, Triangle b) { return tri_tri_overlap_test_3d(V(a[0]), V(a[1]), V(a[2]), V(b[0]), V(b[1]), V(b[2])); }