This commit is contained in:
Бранимир Караџић 2019-02-05 18:52:00 -08:00
Родитель 0ead3539b2
Коммит d0146fdfbb
3 изменённых файлов: 134 добавлений и 124 удалений

Просмотреть файл

@ -1268,15 +1268,15 @@ public:
{
Capsule capsuleA =
{
{ px+kStepX*6.0f, py-1.0f, pz+kStepZ*3.0f },
{ px+kStepX*6.0f, py+1.0f, pz+kStepZ*3.0f },
{ px+kStepX*6.0f, py-1.0f, pz+kStepZ*6.0f },
{ px+kStepX*6.0f, py+1.0f, pz+kStepZ*6.0f },
0.5f,
};
Capsule capsuleB =
{
{ xx+kStepX*5.9f, yy-1.0f, zz+kStepZ*3.0f+0.1f },
{ xx+kStepX*6.0f, yy+1.0f, zz+kStepZ*3.0f },
{ xx+kStepX*5.9f, yy-1.0f, zz+kStepZ*6.0f+0.1f },
{ xx+kStepX*6.0f, yy+1.0f, zz+kStepZ*6.0f },
0.2f,
};

Просмотреть файл

@ -1126,89 +1126,6 @@ Vec3 closestPoint(const Triangle& _triangle, const Vec3& _point)
return cartesian(_triangle, clamp<Vec3>(uvw, 0.0f, 1.0f) );
}
bool overlap(const Sphere& _sphere, const Vec3& _pos)
{
const Vec3 ba = sub(_sphere.center, _pos);
const float rsq = square(_sphere.radius);
return dot(ba, ba) <= rsq;
}
bool overlap(const Sphere& _sphereA, const Sphere& _sphereB)
{
const Vec3 ba = sub(_sphereA.center, _sphereB.center);
const float rsq = square(_sphereA.radius + _sphereB.radius);
return dot(ba, ba) <= rsq;
}
bool overlap(const Sphere& _sphere, const Aabb& _aabb)
{
const Vec3 pos = closestPoint(_aabb, _sphere.center);
return overlap(_sphere, pos);
}
bool overlap(const Sphere& _sphere, const Plane& _plane)
{
return bx::abs(distance(_plane, _sphere.center) ) <= _sphere.radius;
}
bool overlap(const Sphere& _sphere, const Triangle& _triangle)
{
Plane plane;
calcPlane(plane, _triangle);
if (!overlap(_sphere, plane) )
{
return false;
}
const Vec3 pos = closestPoint(plane, _sphere.center);
const Vec3 uvw = barycentric(_triangle, pos);
const float nr = -_sphere.radius;
return uvw.x >= nr
&& uvw.y >= nr
&& uvw.z >= nr
;
}
bool overlap(const Sphere& _sphere, const Cylinder& _cylinder)
{
BX_UNUSED(_sphere, _cylinder);
return false;
}
bool overlap(const Sphere& _sphere, const Capsule& _capsule)
{
const Vec3 pos = closestPoint(LineSegment{_capsule.pos, _capsule.end}, _sphere.center);
return overlap(_sphere, Sphere{pos, _capsule.radius});
}
bool overlap(const Sphere& _sphere, const Cone& _cone)
{
float tt;
const Vec3 pos = closestPoint(LineSegment{_cone.pos, _cone.end}, _sphere.center, tt);
return overlap(_sphere, Sphere{pos, lerp(_cone.radius, 0.0f, tt)});
}
bool overlap(const Sphere& _sphere, const Disk& _disk)
{
if (!overlap(_sphere, Sphere{_disk.center, _disk.radius}) )
{
return false;
}
Plane plane;
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_sphere, plane);
}
bool overlap(const Sphere& _sphere, const Obb& _obb)
{
const Vec3 pos = closestPoint(_obb, _sphere.center);
return overlap(_sphere, pos);
}
bool overlap(const Aabb& _aabb, const Vec3& _pos)
{
const Vec3 ac = getCenter(_aabb);
@ -1469,6 +1386,89 @@ bool overlap(const Capsule& _capsule, const Obb& _obb)
return false;
}
bool overlap(const Sphere& _sphere, const Vec3& _pos)
{
const Vec3 ba = sub(_sphere.center, _pos);
const float rsq = square(_sphere.radius);
return dot(ba, ba) <= rsq;
}
bool overlap(const Sphere& _sphereA, const Sphere& _sphereB)
{
const Vec3 ba = sub(_sphereA.center, _sphereB.center);
const float rsq = square(_sphereA.radius + _sphereB.radius);
return dot(ba, ba) <= rsq;
}
bool overlap(const Sphere& _sphere, const Aabb& _aabb)
{
const Vec3 pos = closestPoint(_aabb, _sphere.center);
return overlap(_sphere, pos);
}
bool overlap(const Sphere& _sphere, const Plane& _plane)
{
return bx::abs(distance(_plane, _sphere.center) ) <= _sphere.radius;
}
bool overlap(const Sphere& _sphere, const Triangle& _triangle)
{
Plane plane;
calcPlane(plane, _triangle);
if (!overlap(_sphere, plane) )
{
return false;
}
const Vec3 pos = closestPoint(plane, _sphere.center);
const Vec3 uvw = barycentric(_triangle, pos);
const float nr = -_sphere.radius;
return uvw.x >= nr
&& uvw.y >= nr
&& uvw.z >= nr
;
}
bool overlap(const Sphere& _sphere, const Cylinder& _cylinder)
{
BX_UNUSED(_sphere, _cylinder);
return false;
}
bool overlap(const Sphere& _sphere, const Capsule& _capsule)
{
const Vec3 pos = closestPoint(LineSegment{_capsule.pos, _capsule.end}, _sphere.center);
return overlap(_sphere, Sphere{pos, _capsule.radius});
}
bool overlap(const Sphere& _sphere, const Cone& _cone)
{
float tt;
const Vec3 pos = closestPoint(LineSegment{_cone.pos, _cone.end}, _sphere.center, tt);
return overlap(_sphere, Sphere{pos, lerp(_cone.radius, 0.0f, tt)});
}
bool overlap(const Sphere& _sphere, const Disk& _disk)
{
if (!overlap(_sphere, Sphere{_disk.center, _disk.radius}) )
{
return false;
}
Plane plane;
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_sphere, plane);
}
bool overlap(const Sphere& _sphere, const Obb& _obb)
{
const Vec3 pos = closestPoint(_obb, _sphere.center);
return overlap(_sphere, pos);
}
bool overlap(const Triangle& _triangle, const Vec3& _pos)
{
const Vec3 uvw = barycentric(_triangle, _pos);

Просмотреть файл

@ -8,19 +8,14 @@
#include <bx/math.h>
///
struct Aabb
{
bx::Vec3 min;
bx::Vec3 max;
};
struct Cylinder
{
bx::Vec3 pos;
bx::Vec3 end;
float radius;
};
///
struct Capsule
{
bx::Vec3 pos;
@ -28,6 +23,7 @@ struct Capsule
float radius;
};
///
struct Cone
{
bx::Vec3 pos;
@ -35,6 +31,15 @@ struct Cone
float radius;
};
///
struct Cylinder
{
bx::Vec3 pos;
bx::Vec3 end;
float radius;
};
///
struct Disk
{
bx::Vec3 center;
@ -42,17 +47,20 @@ struct Disk
float radius;
};
///
struct Obb
{
float mtx[16];
};
///
struct Sphere
{
bx::Vec3 center;
float radius;
};
///
struct Triangle
{
bx::Vec3 v0;
@ -60,12 +68,14 @@ struct Triangle
bx::Vec3 v2;
};
///
struct Ray
{
bx::Vec3 pos;
bx::Vec3 dir;
};
///
struct Hit
{
bx::Vec3 pos;
@ -165,36 +175,6 @@ bool intersect(const Ray& _ray, const Sphere& _sphere, Hit* _hit = NULL);
/// Intersect ray / triangle.
bool intersect(const Ray& _ray, const Triangle& _triangle, Hit* _hit = NULL);
///
bool overlap(const Sphere& _sphere, const bx::Vec3& _pos);
///
bool overlap(const Sphere& _sphereA, const Sphere& _sphereB);
///
bool overlap(const Sphere& _sphere, const Aabb& _aabb);
///
bool overlap(const Sphere& _sphere, const bx::Plane& _plane);
///
bool overlap(const Sphere& _sphere, const Triangle& _triangle);
///
bool overlap(const Sphere& _sphere, const Cylinder& _cylinder);
///
bool overlap(const Sphere& _sphere, const Capsule& _capsule);
///
bool overlap(const Sphere& _sphere, const Cone& _cone);
///
bool overlap(const Sphere& _sphere, const Disk& _disk);
///
bool overlap(const Sphere& _sphere, const Obb& _obb);
///
bool overlap(const Aabb& _aabb, const bx::Vec3& _pos);
@ -255,6 +235,36 @@ bool overlap(const Capsule& _capsule, const Disk& _disk);
///
bool overlap(const Capsule& _capsule, const Obb& _obb);
///
bool overlap(const Sphere& _sphere, const bx::Vec3& _pos);
///
bool overlap(const Sphere& _sphereA, const Sphere& _sphereB);
///
bool overlap(const Sphere& _sphere, const Aabb& _aabb);
///
bool overlap(const Sphere& _sphere, const bx::Plane& _plane);
///
bool overlap(const Sphere& _sphere, const Triangle& _triangle);
///
bool overlap(const Sphere& _sphere, const Cylinder& _cylinder);
///
bool overlap(const Sphere& _sphere, const Capsule& _capsule);
///
bool overlap(const Sphere& _sphere, const Cone& _cone);
///
bool overlap(const Sphere& _sphere, const Disk& _disk);
///
bool overlap(const Sphere& _sphere, const Obb& _obb);
///
bool overlap(const Triangle& _triangle, const bx::Vec3& _pos);