From 29e978ea9111482500d473587f338b0bde881410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Wed, 6 Feb 2019 23:10:01 -0800 Subject: [PATCH] Cleanup. --- examples/29-debugdraw/debugdraw.cpp | 815 +++++++++++----------------- examples/common/bounds.cpp | 292 +++++++++- examples/common/bounds.h | 150 +++++ 3 files changed, 762 insertions(+), 495 deletions(-) diff --git a/examples/29-debugdraw/debugdraw.cpp b/examples/29-debugdraw/debugdraw.cpp index 90e9f4872..1dcac8a84 100644 --- a/examples/29-debugdraw/debugdraw.cpp +++ b/examples/29-debugdraw/debugdraw.cpp @@ -464,6 +464,291 @@ static const uint16_t s_bunnyTriList[] = 146, 72, 147, }; +struct Shape +{ + struct Type + { + enum Enum + { + Aabb, + Capsule, + Cone, + Cylinder, + Disk, + Obb, + Plane, + Sphere, + Triangle, + + Count + }; + }; + + Shape() : type(uint8_t(Type::Count) ) {} + Shape(const Aabb & _a) : type(uint8_t(Type::Aabb ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Capsule & _a) : type(uint8_t(Type::Capsule ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Cone & _a) : type(uint8_t(Type::Cone ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Cylinder & _a) : type(uint8_t(Type::Cylinder) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Disk & _a) : type(uint8_t(Type::Disk ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Obb & _a) : type(uint8_t(Type::Obb ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const bx::Plane& _a) : type(uint8_t(Type::Plane ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Sphere & _a) : type(uint8_t(Type::Sphere ) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + Shape(const Triangle & _a) : type(uint8_t(Type::Triangle) ) { bx::memCopy(data, &_a, sizeof(_a) ); } + + uint8_t data[64]; + uint8_t type; +}; + +#define OVERLAP(_shapeType) \ + bool overlap(const _shapeType& _shapeA, const Shape& _shapeB) \ + { \ + switch (_shapeB.type) \ + { \ + case Shape::Type::Aabb: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Capsule: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Cone: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Cylinder: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Disk: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Obb: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Plane: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Sphere: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + case Shape::Type::Triangle: return ::overlap(_shapeA, *reinterpret_cast(_shapeB.data) ); \ + } \ + return false; \ + } + +OVERLAP(Aabb); +OVERLAP(Capsule); +OVERLAP(Cone); +OVERLAP(Cylinder); +OVERLAP(Disk); +OVERLAP(Obb); +OVERLAP(bx::Plane); +OVERLAP(Sphere); +OVERLAP(Triangle); + +#undef OVERLAP + +void initA(Shape& _outShape, Shape::Type::Enum _type, bx::Vec3 _pos) +{ + switch (_type) + { + case Shape::Type::Aabb: + { + Aabb aabb; + toAabb(aabb, _pos, { 0.5f, 0.5f, 0.5f }); + _outShape = Shape(aabb); + } + break; + + case Shape::Type::Capsule: + _outShape = Shape(Capsule + { + { bx::add(_pos, {0.0f, -1.0f, 0.0f}) }, + { bx::add(_pos, {0.0f, 1.0f, 0.0f}) }, + 0.5f, + }); + break; + + case Shape::Type::Cone: + _outShape = Shape(Cone + { + { bx::add(_pos, {0.0f, -1.0f, 0.0f}) }, + { bx::add(_pos, {0.0f, 1.0f, 0.0f}) }, + 0.5f, + }); + break; + + case Shape::Type::Cylinder: + _outShape = Shape(Cylinder + { + { bx::add(_pos, {0.0f, -1.0f, 0.0f}) }, + { bx::add(_pos, {0.0f, 1.0f, 0.0f}) }, + 0.5f, + }); + break; + + case Shape::Type::Disk: + _outShape = Shape(Disk + { + _pos, + bx::normalize(bx::Vec3{0.0f, 1.0f, 1.0f}), + 0.5f, + }); + break; + + case Shape::Type::Obb: + { + Obb obb; + bx::mtxSRT(obb.mtx + , 0.25f + , 1.0f + , 0.25f + , bx::toRad(50.0f) + , bx::toRad(15.0f) + , bx::toRad(45.0f) + , _pos.x + , _pos.y + , _pos.z + ); + _outShape = Shape(obb); + } + break; + + case Shape::Type::Sphere: + _outShape = Shape(Sphere{_pos, 0.5f}); + break; + + case Shape::Type::Plane: + { + bx::Plane plane; + bx::calcPlane(plane, bx::normalize(bx::Vec3{0.0f, 1.0f, 1.0f}), _pos); + _outShape = Shape(plane); + } + break; + + case Shape::Type::Triangle: + _outShape = Shape(Triangle + { + { bx::add(_pos, {-0.4f, 0.0f, -0.4f}) }, + { bx::add(_pos, { 0.0f, -0.3f, 0.5f}) }, + { bx::add(_pos, { 0.0f, 0.5f, 0.3f}) }, + }); + break; + + default: break; + } +} + +void initB(Shape& _outShape, Shape::Type::Enum _type, bx::Vec3 _pos) +{ + switch (_type) + { + case Shape::Type::Aabb: + { + Aabb aabb; + toAabb(aabb, _pos, { 0.5f, 0.5f, 0.5f }); + _outShape = Shape(aabb); + } + break; + + case Shape::Type::Capsule: + _outShape = Shape(Capsule + { + { bx::add(_pos, {0.0f, -1.0f, 0.1f}) }, + { bx::add(_pos, {0.0f, 1.0f, 0.0f}) }, + 0.2f, + }); + break; + + case Shape::Type::Cone: + _outShape = Shape(Cone + { + { bx::add(_pos, {0.0f, -1.0f, 0.1f}) }, + { bx::add(_pos, {0.0f, 1.0f, 0.0f}) }, + 0.2f, + }); + break; + + case Shape::Type::Cylinder: + _outShape = Shape(Cylinder + { + { bx::add(_pos, {0.0f, -1.0f, 0.1f}) }, + { bx::add(_pos, {0.0f, 1.0f, 0.0f}) }, + 0.2f, + }); + break; + + case Shape::Type::Disk: + _outShape = Shape(Disk + { + _pos, + bx::normalize(bx::Vec3{1.0f, 1.0f, 0.0f}), + 0.5f, + }); + break; + + case Shape::Type::Obb: + { + Obb obb; + bx::mtxSRT(obb.mtx + , 1.0f + , 0.25f + , 0.25f + , bx::toRad(10.0f) + , bx::toRad(30.0f) + , bx::toRad(70.0f) + , _pos.x + , _pos.y + , _pos.z + ); + _outShape = Shape(obb); + } + break; + + case Shape::Type::Plane: + { + bx::Plane plane; + bx::calcPlane(plane, bx::normalize(bx::Vec3{1.0f, 1.0f, 0.0f}), _pos); + _outShape = Shape(plane); + } + break; + + case Shape::Type::Sphere: + _outShape = Shape(Sphere{_pos, 0.5f}); + break; + + case Shape::Type::Triangle: + _outShape = Shape(Triangle + { + { bx::add(_pos, {-0.4f, 0.0f, -0.4f}) }, + { bx::add(_pos, {-0.5f, -0.3f, 0.0f}) }, + { bx::add(_pos, { 0.3f, 0.5f, 0.0f}) }, + }); + break; + + default: break; + } +} + +int32_t overlap(const Shape& _shapeA, const Shape& _shapeB) +{ + switch (_shapeA.type) + { + case Shape::Type::Aabb: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Capsule: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Cone: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Cylinder: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Disk: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Obb: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Plane: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Sphere: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + case Shape::Type::Triangle: return overlap(*reinterpret_cast(_shapeA.data), _shapeB); + } + + return 2; +} + +void draw(DebugDrawEncoder& _dde, const Shape& _shape, const bx::Vec3 _pos) +{ + switch (_shape.type) + { + case Shape::Type::Aabb: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Capsule: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Cone: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Cylinder: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Disk: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Obb: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Plane: + { + _dde.drawGrid(reinterpret_cast(_shape.data)->normal, _pos, 10, 0.3f); + } + break; + case Shape::Type::Sphere: _dde.draw(*reinterpret_cast(_shape.data) ); break; + case Shape::Type::Triangle: _dde.draw(*reinterpret_cast(_shape.data) ); break; + } +} + void imageCheckerboard(void* _dst, uint32_t _width, uint32_t _height, uint32_t _step, uint32_t _0, uint32_t _1) { uint32_t* dst = (uint32_t*)_dst; @@ -477,13 +762,6 @@ void imageCheckerboard(void* _dst, uint32_t _width, uint32_t _height, uint32_t _ } } -void translate(Triangle& _inout, bx::Vec3 _pos) -{ - _inout.v0 = bx::add(_inout.v0, _pos); - _inout.v1 = bx::add(_inout.v1, _pos); - _inout.v2 = bx::add(_inout.v2, _pos); -} - class ExampleDebugDraw : public entry::AppI { public: @@ -866,509 +1144,62 @@ public: dde.push(); { - bool olp; - - constexpr float kStepX = 3.0f; - constexpr float kStepZ = 3.0f; - - const float px = -5.0f*kStepX; - const float py = 1.0f; - const float pz = 20.0f; - const float xx = amplitudeMul*bx::sin(time*0.39f) * 1.03f + px; - const float yy = amplitudeMul*bx::cos(time*0.79f) * 1.03f + py; - const float zz = amplitudeMul*bx::cos(time) * 1.03f + pz; - - // Sphere --- + constexpr uint32_t colorA[] = { - Sphere sphereA = { { px+kStepX*0.0f, py, pz+kStepZ*0.0f }, 0.5f }; - Sphere sphereB = { { xx+kStepX*0.0f, yy, zz+kStepZ*0.0f }, 0.5f }; - olp = overlap(sphereA, sphereB);; - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(sphereB); - } + 0xffffffff, + kOverlapA, + 0xff666666, + }; + constexpr uint32_t colorB[] = { - Sphere sphereA = { { px+kStepX*1.0f, py, pz+kStepZ*0.0f }, 0.5f }; - Aabb aabbB; - toAabb(aabbB, { xx+kStepX*1.0f, yy, zz+kStepZ*0.0f }, { 0.5f, 0.5f, 0.5f }); - olp = overlap(sphereA, aabbB); + 0xffffffff, + kOverlapB, + 0xff888888, + }; - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(aabbB); - } + constexpr float kStep = 3.0f; + bx::Vec3 posA = { - Sphere sphereA = { { px+kStepX*2.0f, py, pz+kStepZ*0.0f }, 0.5f }; - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*2.0f, 0.0f, kStepZ*0.0f}); - - olp = overlap(sphereA, triangleB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(triangleB); - } + -4.5f*kStep, + 1.0f, + 20.0f, + }; + for (uint32_t ii = 0; ii < Shape::Type::Count; ++ii) { - Sphere sphereA = { { px+kStepX*3.0f, py, pz+kStepZ*0.0f }, 0.5f }; - Triangle triangleB = + const bx::Vec3 posB = bx::add(posA, { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; + amplitudeMul*bx::sin(time*0.39f) * 1.03f, + amplitudeMul*bx::cos(time*0.79f) * 1.03f, + amplitudeMul*bx::cos(time) * 1.03f, + }); - translate(triangleB, {kStepX*3.0f, 0.0f, kStepZ*0.0f}); - - bx::Plane planeB; - bx::calcPlane(planeB, triangleB.v0, triangleB.v1, triangleB.v2); - - olp = overlap(sphereA, planeB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.drawGrid(planeB.normal, triangleB.v0, 10, 0.3f); - } - - { - Sphere sphereA = { { px+kStepX*4.0f, py, pz+kStepZ*0.0f }, 0.5f }; - Triangle triangleB = + for (uint32_t jj = 0; jj < Shape::Type::Count; ++jj) { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; + const bx::Vec3 pa = bx::add(posA, {jj*kStep, 0.0f, 0.0f}); + const bx::Vec3 pb = bx::add(posB, {jj*kStep, 0.0f, 0.0f}); - translate(triangleB, {kStepX*4.0f, 0.0f, kStepZ*0.0f}); + Shape shapeA, shapeB; + initA(shapeA, Shape::Type::Enum(ii), pa); + initB(shapeB, Shape::Type::Enum(jj), pb); - bx::Plane planeB; - bx::calcPlane(planeB, triangleB.v0, triangleB.v1, triangleB.v2); + int32_t olp = overlap(shapeA, shapeB); - const Disk diskB = { getCenter(triangleB), planeB.normal, 0.5f }; + dde.setColor(colorA[olp]); + dde.setWireframe(false); + draw(dde, shapeA, pa); - olp = overlap(sphereA, diskB); + dde.setColor(colorB[olp]); + dde.setWireframe(true); + draw(dde, shapeB, pb); + } - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(diskB); - } - - { - Sphere sphereA = { { px+kStepX*5.0f, py, pz+kStepZ*0.0f }, 0.5f }; - - Obb obbB; - bx::mtxSRT(obbB.mtx - , 1.0f - , 0.25f - , 0.25f - , bx::toRad(10.0f) - , bx::toRad(30.0f) - , bx::toRad(70.0f) - , xx+kStepX*5.0f - , yy - , zz+kStepZ*0.0f - ); - - olp = overlap(sphereA, obbB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(obbB); - } - - { - Sphere sphereA = { { px+kStepX*6.0f, py, pz+kStepZ*0.0f }, 0.5f }; - - Capsule capsuleB = - { - { xx+kStepX*5.9f, yy-1.0f, zz+kStepZ*0.0f+0.1f }, - { xx+kStepX*6.0f, yy+1.0f, zz+kStepZ*0.0f }, - 0.2f, - }; - - olp = overlap(sphereA, capsuleB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(capsuleB); - } - - { - Sphere sphereA = { { px+kStepX*7.0f, py, pz+kStepZ*0.0f }, 0.5f }; - - Cylinder cylinderB = - { - { xx+kStepX*6.9f, yy-1.0f, zz+kStepZ*0.0f+0.1f }, - { xx+kStepX*7.0f, yy+1.0f, zz+kStepZ*0.0f }, - 0.2f, - }; - - olp = overlap(sphereA, cylinderB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(cylinderB); - } - - { - Sphere sphereA = { { px+kStepX*8.0f, py, pz+kStepZ*0.0f }, 0.5f }; - - Cone coneB = - { - { xx+kStepX*7.9f, yy-1.0f, zz+kStepZ*0.0f+0.1f }, - { xx+kStepX*8.0f, yy+1.0f, zz+kStepZ*0.0f }, - 0.25f, - }; - - olp = overlap(sphereA, coneB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(sphereA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(coneB); - } - - // AABB --- - { - Aabb aabbA, aabbB; - toAabb(aabbA, { px+kStepX*1.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - toAabb(aabbB, { xx+kStepX*1.0f, yy, zz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - olp = overlap(aabbA, aabbB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(aabbA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(aabbB); - } - - { - Aabb aabbA; - toAabb(aabbA, { px+kStepX*2.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*2.0f, 0.0f, kStepZ*1.0f}); - - olp = overlap(aabbA, triangleB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(aabbA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(triangleB); - } - - { - Aabb aabbA; - toAabb(aabbA, { px+kStepX*3.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*3.0f, 0.0f, kStepZ*1.0f}); - - bx::Plane planeB; - bx::calcPlane(planeB, triangleB.v0, triangleB.v1, triangleB.v2); - - olp = overlap(aabbA, planeB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(aabbA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.drawGrid(planeB.normal, triangleB.v0, 10, 0.3f); - } - - { - Aabb aabbA; - toAabb(aabbA, { px+kStepX*4.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*4.0f, 0.0f, kStepZ*1.0f}); - - bx::Plane planeB; - bx::calcPlane(planeB, triangleB.v0, triangleB.v1, triangleB.v2); - - const Disk diskB = { getCenter(triangleB), planeB.normal, 0.5f }; - - olp = overlap(aabbA, diskB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(aabbA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(diskB); - } - - { - Aabb aabbA; - toAabb(aabbA, { px+kStepX*6.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - - Capsule capsuleB = - { - { xx+kStepX*5.9f, yy-1.0f, zz+kStepZ*1.0f+0.1f }, - { xx+kStepX*6.0f, yy+1.0f, zz+kStepZ*1.0f }, - 0.2f, - }; - - olp = overlap(aabbA, capsuleB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(aabbA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(capsuleB); - } - - { - Aabb aabbA; - toAabb(aabbA, { px+kStepX*8.0f, py, pz+kStepZ*1.0f }, { 0.5f, 0.5f, 0.5f }); - - Cone coneB = - { - { xx+kStepX*7.9f, yy-1.0f, zz+kStepZ*1.0f+0.1f }, - { xx+kStepX*8.0f, yy+1.0f, zz+kStepZ*1.0f }, - 0.25f, - }; - - olp = overlap(aabbA, coneB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(aabbA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(coneB); - } - - // Triangle --- - { - Triangle triangleA = - { - { px-0.4f, py+0.0f, pz-0.4f }, - { px+0.0f, py-0.3f, pz-0.5f }, - { px+0.0f, py+0.5f, pz+0.3f }, - }; - - translate(triangleA, {kStepX*2.0f, 0.0f, kStepZ*2.0f}); - - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*2.0f, 0.0f, kStepZ*2.0f}); - - olp = overlap(triangleA, triangleB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(triangleA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(triangleB); - } - - { - Triangle triangleA = - { - { px-0.4f, py+0.0f, pz-0.4f }, - { px+0.0f, py-0.3f, pz-0.5f }, - { px+0.0f, py+0.5f, pz+0.3f }, - }; - - translate(triangleA, {kStepX*3.0f, 0.0f, kStepZ*2.0f}); - - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*3.0f, 0.0f, kStepZ*2.0f}); - - bx::Plane planeB; - bx::calcPlane(planeB, triangleB.v0, triangleB.v1, triangleB.v2); - - olp = overlap(triangleA, planeB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(triangleA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.drawGrid(planeB.normal, triangleB.v0, 10, 0.3f); - } - - { - Triangle triangleA = - { - { px-0.4f, py+0.0f, pz-0.4f }, - { px+0.0f, py-0.3f, pz-0.5f }, - { px+0.0f, py+0.5f, pz+0.3f }, - }; - - translate(triangleA, {kStepX*4.0f, 0.0f, kStepZ*2.0f}); - - Triangle triangleB = - { - { xx-0.4f, yy+0.0f, zz-0.4f }, - { xx-0.5f, yy-0.3f, zz+0.0f }, - { xx+0.3f, yy+0.5f, zz+0.0f }, - }; - - translate(triangleB, {kStepX*4.0f, 0.0f, kStepZ*2.0f}); - - bx::Plane planeB; - bx::calcPlane(planeB, triangleB.v0, triangleB.v1, triangleB.v2); - - const Disk diskB = { getCenter(triangleB), planeB.normal, 0.5f }; - - olp = overlap(triangleA, diskB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(triangleA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(diskB); - } - - { - Triangle triangleA = - { - { px-0.4f, py+0.0f, pz-0.4f }, - { px+0.0f, py-0.3f, pz-0.5f }, - { px+0.0f, py+0.5f, pz+0.3f }, - }; - - translate(triangleA, {kStepX*5.0f, 0.0f, kStepZ*2.0f}); - - Obb obbB; - bx::mtxSRT(obbB.mtx - , 1.0f - , 0.25f - , 0.25f - , bx::toRad(10.0f) - , bx::toRad(30.0f) - , bx::toRad(70.0f) - , xx+kStepX*5.0f - , yy - , zz+kStepZ*2.0f - ); - - olp = overlap(triangleA, obbB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(triangleA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(obbB); - } - - // Capsule --- - { - Capsule capsuleA = - { - { 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*6.0f+0.1f }, - { xx+kStepX*6.0f, yy+1.0f, zz+kStepZ*6.0f }, - 0.2f, - }; - - olp = overlap(capsuleA, capsuleB); - - dde.setColor(olp ? kOverlapA : 0xffffffff); - dde.setWireframe(false); - dde.draw(capsuleA); - - dde.setColor(olp ? kOverlapB : 0xffffffff); - dde.setWireframe(true); - dde.draw(capsuleB); + posA = bx::add(posA, {0.0f, 0.0f, kStep}); } } + dde.pop(); dde.end(); diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index b09b949c9..57355a13f 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -24,7 +24,7 @@ Vec3 getCenter(const Triangle& _triangle) return mul(add(add(_triangle.v0, _triangle.v1), _triangle.v2), 1.0f/3.0f); } -void toAabb(Aabb& _outAabb, const bx::Vec3& _extents) +void toAabb(Aabb& _outAabb, const Vec3& _extents) { _outAabb.min = neg(_extents); _outAabb.max = _extents; @@ -1288,7 +1288,7 @@ bool overlap(const Aabb& _aabb, const Obb& _obb) return false; } -bool overlap(const Capsule& _capsule, const bx::Vec3& _pos) +bool overlap(const Capsule& _capsule, const Vec3& _pos) { const Vec3 pos = closestPoint(LineSegment{_capsule.pos, _capsule.end}, _pos); return overlap(Sphere{pos, _capsule.radius}, _pos); @@ -1304,7 +1304,7 @@ bool overlap(const Capsule& _capsule, const Aabb& _aabb) return overlap(_aabb, _capsule); } -bool overlap(const Capsule& _capsule, const bx::Plane& _plane) +bool overlap(const Capsule& _capsule, const Plane& _plane) { BX_UNUSED(_capsule, _plane); return false; @@ -1386,6 +1386,292 @@ bool overlap(const Capsule& _capsule, const Obb& _obb) return false; } +bool overlap(const Cone& _cone, const Vec3& _pos) +{ + BX_UNUSED(_cone, _pos); + return false; +} + +bool overlap(const Cone& _cone, const Sphere& _sphere) +{ + return overlap(_sphere, _cone); +} + +bool overlap(const Cone& _cone, const Aabb& _aabb) +{ + return overlap(_aabb, _cone); +} + +bool overlap(const Cone& _cone, const Plane& _plane) +{ + BX_UNUSED(_cone, _plane); + return false; +} + +bool overlap(const Cone& _cone, const Triangle& _triangle) +{ + BX_UNUSED(_cone, _triangle); + return false; +} + +bool overlap(const Cone& _cone, const Cylinder& _cylinder) +{ + BX_UNUSED(_cone, _cylinder); + return false; +} + +bool overlap(const Cone& _cone, const Capsule& _capsule) +{ + BX_UNUSED(_cone, _capsule); + return false; +} + +bool overlap(const Cone& _coneA, const Cone& _coneB) +{ + BX_UNUSED(_coneA, _coneB); + return false; +} + +bool overlap(const Cone& _cone, const Disk& _disk) +{ + BX_UNUSED(_cone, _disk); + return false; +} + +bool overlap(const Cone& _cone, const Obb& _obb) +{ + BX_UNUSED(_cone, _obb); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Vec3& _pos) +{ + BX_UNUSED(_cylinder, _pos); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Sphere& _sphere) +{ + BX_UNUSED(_cylinder, _sphere); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Aabb& _aabb) +{ + BX_UNUSED(_cylinder, _aabb); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Plane& _plane) +{ + BX_UNUSED(_cylinder, _plane); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Triangle& _triangle) +{ + BX_UNUSED(_cylinder, _triangle); + return false; +} + +bool overlap(const Cylinder& _cylinderA, const Cylinder& _cylinderB) +{ + BX_UNUSED(_cylinderA, _cylinderB); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Capsule& _capsule) +{ + BX_UNUSED(_cylinder, _capsule); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Cone& _cone) +{ + BX_UNUSED(_cylinder, _cone); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Disk& _disk) +{ + BX_UNUSED(_cylinder, _disk); + return false; +} + +bool overlap(const Cylinder& _cylinder, const Obb& _obb) +{ + BX_UNUSED(_cylinder, _obb); + return false; +} + +bool overlap(const Disk& _disk, const Vec3& _pos) +{ + BX_UNUSED(_disk, _pos); + return false; +} + +bool overlap(const Disk& _disk, const Sphere& _sphere) +{ + return overlap(_sphere, _disk); +} + +bool overlap(const Disk& _disk, const Aabb& _aabb) +{ + return overlap(_aabb, _disk); +} + +bool overlap(const Disk& _disk, const Plane& _plane) +{ + BX_UNUSED(_disk, _plane); + return false; +} + +bool overlap(const Disk& _disk, const Triangle& _triangle) +{ + return overlap(_triangle, _disk); +} + +bool overlap(const Disk& _disk, const Cylinder& _cylinder) +{ + BX_UNUSED(_disk, _cylinder); + return false; +} + +bool overlap(const Disk& _disk, const Capsule& _capsule) +{ + return overlap(_capsule, _disk); +} + +bool overlap(const Disk& _disk, const Cone& _cone) +{ + BX_UNUSED(_disk, _cone); + return false; +} + +bool overlap(const Disk& _diskA, const Disk& _diskB) +{ + BX_UNUSED(_diskA, _diskB); + return false; +} + +bool overlap(const Disk& _disk, const Obb& _obb) +{ + BX_UNUSED(_disk, _obb); + return false; +} + +bool overlap(const Obb& _obb, const Vec3& _pos) +{ + BX_UNUSED(_obb, _pos); + return false; +} + +bool overlap(const Obb& _obb, const Sphere& _sphere) +{ + return overlap(_sphere, _obb); +} + +bool overlap(const Obb& _obb, const Aabb& _aabb) +{ + return overlap(_aabb, _obb); +} + +bool overlap(const Obb& _obb, const Plane& _plane) +{ + BX_UNUSED(_obb, _plane); + return false; +} + +bool overlap(const Obb& _obb, const Triangle& _triangle) +{ + return overlap(_triangle, _obb); +} + +bool overlap(const Obb& _obb, const Cylinder& _cylinder) +{ + BX_UNUSED(_obb, _cylinder); + return false; +} + +bool overlap(const Obb& _obb, const Capsule& _capsule) +{ + return overlap(_capsule, _obb); +} + +bool overlap(const Obb& _obb, const Cone& _cone) +{ + BX_UNUSED(_obb, _cone); + return false; +} + +bool overlap(const Obb& _obb, const Disk& _disk) +{ + BX_UNUSED(_obb, _disk); + return false; +} + +bool overlap(const Obb& _obbA, const Obb& _obbB) +{ + BX_UNUSED(_obbA, _obbB); + return false; +} + +bool overlap(const Plane& _plane, const Vec3& _pos) +{ + BX_UNUSED(_plane, _pos); + return false; +} + +bool overlap(const Plane& _plane, const Sphere& _sphere) +{ + return overlap(_sphere, _plane); +} + +bool overlap(const Plane& _plane, const Aabb& _aabb) +{ + return overlap(_aabb, _plane); +} + +bool overlap(const Plane& _planeA, const Plane& _planeB) +{ + BX_UNUSED(_planeA, _planeB); + return false; +} + +bool overlap(const Plane& _plane, const Triangle& _triangle) +{ + return overlap(_triangle, _plane); +} + +bool overlap(const Plane& _plane, const Cylinder& _cylinder) +{ + BX_UNUSED(_plane, _cylinder); + return false; +} + +bool overlap(const Plane& _plane, const Capsule& _capsule) +{ + return overlap(_capsule, _plane); +} + +bool overlap(const Plane& _plane, const Cone& _cone) +{ + BX_UNUSED(_plane, _cone); + return false; +} + +bool overlap(const Plane& _plane, const Disk& _disk) +{ + BX_UNUSED(_plane, _disk); + return false; +} + +bool overlap(const Plane& _plane, const Obb& _obb) +{ + BX_UNUSED(_plane, _obb); + return false; +} + bool overlap(const Sphere& _sphere, const Vec3& _pos) { const Vec3 ba = sub(_sphere.center, _pos); diff --git a/examples/common/bounds.h b/examples/common/bounds.h index 1997e3855..dff84a1de 100644 --- a/examples/common/bounds.h +++ b/examples/common/bounds.h @@ -235,6 +235,156 @@ bool overlap(const Capsule& _capsule, const Disk& _disk); /// bool overlap(const Capsule& _capsule, const Obb& _obb); +/// +bool overlap(const Cone& _cone, const bx::Vec3& _pos); + +/// +bool overlap(const Cone& _cone, const Sphere& _sphere); + +/// +bool overlap(const Cone& _cone, const Aabb& _aabb); + +/// +bool overlap(const Cone& _cone, const bx::Plane& _plane); + +/// +bool overlap(const Cone& _cone, const Triangle& _triangle); + +/// +bool overlap(const Cone& _cone, const Cylinder& _cylinder); + +/// +bool overlap(const Cone& _cone, const Capsule& _capsule); + +/// +bool overlap(const Cone& _coneA, const Cone& _coneB); + +/// +bool overlap(const Cone& _cone, const Disk& _disk); + +/// +bool overlap(const Cone& _cone, const Obb& _obb); + +/// +bool overlap(const Cylinder& _cylinder, const bx::Vec3& _pos); + +/// +bool overlap(const Cylinder& _cylinder, const Sphere& _sphere); + +/// +bool overlap(const Cylinder& _cylinder, const Aabb& _aabb); + +/// +bool overlap(const Cylinder& _cylinder, const bx::Plane& _plane); + +/// +bool overlap(const Cylinder& _cylinder, const Triangle& _triangle); + +/// +bool overlap(const Cylinder& _cylinderA, const Cylinder& _cylinderB); + +/// +bool overlap(const Cylinder& _cylinder, const Capsule& _capsule); + +/// +bool overlap(const Cylinder& _cylinder, const Cone& _cone); + +/// +bool overlap(const Cylinder& _cylinder, const Disk& _disk); + +/// +bool overlap(const Cylinder& _cylinder, const Obb& _obb); + +/// +bool overlap(const Disk& _disk, const bx::Vec3& _pos); + +/// +bool overlap(const Disk& _disk, const Sphere& _sphere); + +/// +bool overlap(const Disk& _disk, const Aabb& _aabb); + +/// +bool overlap(const Disk& _disk, const bx::Plane& _plane); + +/// +bool overlap(const Disk& _disk, const Triangle& _triangle); + +/// +bool overlap(const Disk& _disk, const Cylinder& _cylinder); + +/// +bool overlap(const Disk& _disk, const Capsule& _capsule); + +/// +bool overlap(const Disk& _disk, const Cone& _cone); + +/// +bool overlap(const Disk& _diskA, const Disk& _diskB); + +/// +bool overlap(const Disk& _disk, const Obb& _obb); + +/// +bool overlap(const Obb& _obb, const bx::Vec3& _pos); + +/// +bool overlap(const Obb& _obb, const Sphere& _sphere); + +/// +bool overlap(const Obb& _obb, const Aabb& _aabb); + +/// +bool overlap(const Obb& _obb, const bx::Plane& _plane); + +/// +bool overlap(const Obb& _obb, const Triangle& _triangle); + +/// +bool overlap(const Obb& _obb, const Cylinder& _cylinder); + +/// +bool overlap(const Obb& _obb, const Capsule& _capsule); + +/// +bool overlap(const Obb& _obb, const Cone& _cone); + +/// +bool overlap(const Obb& _obb, const Disk& _disk); + +/// +bool overlap(const Obb& _obbA, const Obb& _obbB); + +/// +bool overlap(const bx::Plane& _plane, const bx::Vec3& _pos); + +/// +bool overlap(const bx::Plane& _plane, const Sphere& _sphere); + +/// +bool overlap(const bx::Plane& _plane, const Aabb& _aabb); + +/// +bool overlap(const bx::Plane& _planeA, const bx::Plane& _planeB); + +/// +bool overlap(const bx::Plane& _plane, const Triangle& _triangle); + +/// +bool overlap(const bx::Plane& _plane, const Cylinder& _cylinder); + +/// +bool overlap(const bx::Plane& _plane, const Capsule& _capsule); + +/// +bool overlap(const bx::Plane& _plane, const Cone& _cone); + +/// +bool overlap(const bx::Plane& _plane, const Disk& _disk); + +/// +bool overlap(const bx::Plane& _plane, const Obb& _obb); + /// bool overlap(const Sphere& _sphere, const bx::Vec3& _pos);