mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Cleanup.
This commit is contained in:
@@ -10,6 +10,20 @@
|
||||
|
||||
namespace bx
|
||||
{
|
||||
///
|
||||
struct Line
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 dir = init::None;
|
||||
};
|
||||
|
||||
///
|
||||
struct LineSegment
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
};
|
||||
|
||||
///
|
||||
struct Aabb
|
||||
{
|
||||
@@ -20,33 +34,33 @@ namespace bx
|
||||
///
|
||||
struct Capsule
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
float radius;
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Cone
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
float radius;
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Cylinder
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
float radius;
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Disk
|
||||
{
|
||||
Vec3 center = init::None;
|
||||
Vec3 normal = init::None;
|
||||
float radius;
|
||||
Vec3 center = init::None;
|
||||
Vec3 normal = init::None;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
@@ -58,8 +72,8 @@ namespace bx
|
||||
///
|
||||
struct Sphere
|
||||
{
|
||||
Vec3 center = init::None;
|
||||
float radius;
|
||||
Vec3 center = init::None;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
@@ -84,9 +98,37 @@ namespace bx
|
||||
Plane plane = init::None;
|
||||
};
|
||||
|
||||
///
|
||||
struct Interval
|
||||
{
|
||||
///
|
||||
Interval(float _val);
|
||||
|
||||
///
|
||||
Interval(float _min, float _max);
|
||||
|
||||
///
|
||||
void set(float _val);
|
||||
|
||||
///
|
||||
void setCenter(float _val);
|
||||
|
||||
///
|
||||
void expand(float _val);
|
||||
|
||||
float min;
|
||||
float max;
|
||||
};
|
||||
|
||||
///
|
||||
Vec3 getPointAt(const Ray& _ray, float _t);
|
||||
|
||||
///
|
||||
Vec3 getPointAt(const Line& _line, float _t);
|
||||
|
||||
///
|
||||
Vec3 getPointAt(const LineSegment& _line, float _t);
|
||||
|
||||
///
|
||||
Vec3 getCenter(const Aabb& _aabb);
|
||||
|
||||
@@ -183,6 +225,30 @@ namespace bx
|
||||
/// Intersect ray / triangle.
|
||||
bool intersect(const Ray& _ray, const Triangle& _triangle, Hit* _hit = NULL);
|
||||
|
||||
///
|
||||
Vec3 closestPoint(const Line& _line, const Vec3& _point);
|
||||
|
||||
///
|
||||
Vec3 closestPoint(const LineSegment& _line, const Vec3& _point);
|
||||
|
||||
///
|
||||
Vec3 closestPoint(const Plane& _plane, const Vec3& _point);
|
||||
|
||||
///
|
||||
Vec3 closestPoint(const Aabb& _aabb, const Vec3& _point);
|
||||
|
||||
///
|
||||
Vec3 closestPoint(const Obb& _obb, const Vec3& _point);
|
||||
|
||||
///
|
||||
Vec3 closestPoint(const Triangle& _triangle, const Vec3& _point);
|
||||
|
||||
///
|
||||
bool overlap(const Interval& _interval, float _pos);
|
||||
|
||||
///
|
||||
bool overlap(const Interval& _intervalA, const Interval& _intervalB);
|
||||
|
||||
///
|
||||
bool overlap(const Aabb& _aabb, const Vec3& _pos);
|
||||
|
||||
|
||||
@@ -9,16 +9,71 @@
|
||||
|
||||
namespace bx
|
||||
{
|
||||
inline Interval::Interval(float _val)
|
||||
: min(_val)
|
||||
, max(_val)
|
||||
{
|
||||
}
|
||||
|
||||
inline Interval::Interval(float _min, float _max)
|
||||
: min(_min)
|
||||
, max(_max)
|
||||
{
|
||||
}
|
||||
|
||||
inline void Interval::set(float _val)
|
||||
{
|
||||
min = _val;
|
||||
max = _val;
|
||||
}
|
||||
|
||||
inline void Interval::setCenter(float _val)
|
||||
{
|
||||
const float extents = (max - min) * 0.5f;
|
||||
min = _val - extents;
|
||||
max = _val + extents;
|
||||
}
|
||||
|
||||
inline void Interval::expand(float _val)
|
||||
{
|
||||
min = bx::min(min, _val);
|
||||
max = bx::max(max, _val);
|
||||
}
|
||||
|
||||
inline Vec3 getPointAt(const Ray& _ray, float _t)
|
||||
{
|
||||
return mad(_ray.dir, _t, _ray.pos);
|
||||
}
|
||||
|
||||
inline Vec3 getPointAt(const Line& _line, float _t)
|
||||
{
|
||||
return mad(_line.dir, _t, _line.pos);
|
||||
}
|
||||
|
||||
inline Vec3 getPointAt(const LineSegment& _line, float _t)
|
||||
{
|
||||
return lerp(_line.pos, _line.end, _t);
|
||||
}
|
||||
|
||||
inline bool intersect(const Ray& _ray, const Plane& _plane, Hit* _hit)
|
||||
{
|
||||
return intersect(_ray, _plane, false, _hit);
|
||||
}
|
||||
|
||||
inline bool overlap(const Interval& _interval, float _t)
|
||||
{
|
||||
return _t > _interval.min
|
||||
&& _t < _interval.max
|
||||
;
|
||||
}
|
||||
|
||||
inline bool overlap(const Interval& _intervalA, const Interval& _intervalB)
|
||||
{
|
||||
return _intervalA.max > _intervalB.min
|
||||
&& _intervalB.max > _intervalA.min
|
||||
;
|
||||
}
|
||||
|
||||
inline bool overlap(const Aabb& _aabb, const Sphere& _sphere)
|
||||
{
|
||||
return overlap(_sphere, _aabb);
|
||||
|
||||
Reference in New Issue
Block a user