mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-10-24 09:50:51 +00:00
Adding bounds overlap tests.
This commit is contained in:
@@ -1420,46 +1420,46 @@ struct DebugDrawEncoderImpl
|
||||
const Attrib& attrib = m_attrib[m_stack];
|
||||
if (attrib.m_wireframe)
|
||||
{
|
||||
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_min.z);
|
||||
moveTo(_aabb.min.x, _aabb.min.y, _aabb.min.z);
|
||||
lineTo(_aabb.max.x, _aabb.min.y, _aabb.min.z);
|
||||
lineTo(_aabb.max.x, _aabb.max.y, _aabb.min.z);
|
||||
lineTo(_aabb.min.x, _aabb.max.y, _aabb.min.z);
|
||||
close();
|
||||
|
||||
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_max.z);
|
||||
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_max.z);
|
||||
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_max.z);
|
||||
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_max.z);
|
||||
moveTo(_aabb.min.x, _aabb.min.y, _aabb.max.z);
|
||||
lineTo(_aabb.max.x, _aabb.min.y, _aabb.max.z);
|
||||
lineTo(_aabb.max.x, _aabb.max.y, _aabb.max.z);
|
||||
lineTo(_aabb.min.x, _aabb.max.y, _aabb.max.z);
|
||||
close();
|
||||
|
||||
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_max.z);
|
||||
moveTo(_aabb.min.x, _aabb.min.y, _aabb.min.z);
|
||||
lineTo(_aabb.min.x, _aabb.min.y, _aabb.max.z);
|
||||
|
||||
moveTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_max.z);
|
||||
moveTo(_aabb.max.x, _aabb.min.y, _aabb.min.z);
|
||||
lineTo(_aabb.max.x, _aabb.min.y, _aabb.max.z);
|
||||
|
||||
moveTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_max.z);
|
||||
moveTo(_aabb.min.x, _aabb.max.y, _aabb.min.z);
|
||||
lineTo(_aabb.min.x, _aabb.max.y, _aabb.max.z);
|
||||
|
||||
moveTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_min.z);
|
||||
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_max.z);
|
||||
moveTo(_aabb.max.x, _aabb.max.y, _aabb.min.z);
|
||||
lineTo(_aabb.max.x, _aabb.max.y, _aabb.max.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
Obb obb;
|
||||
aabbToObb(obb, _aabb);
|
||||
draw(Mesh::Cube, obb.m_mtx, 1, false);
|
||||
toObb(obb, _aabb);
|
||||
draw(Mesh::Cube, obb.mtx, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void draw(const Cylinder& _cylinder, bool _capsule)
|
||||
{
|
||||
drawCylinder(_cylinder.m_pos, _cylinder.m_end, _cylinder.m_radius, _capsule);
|
||||
drawCylinder(_cylinder.pos, _cylinder.end, _cylinder.radius, _capsule);
|
||||
}
|
||||
|
||||
void draw(const Disk& _disk)
|
||||
{
|
||||
drawCircle(_disk.m_normal, _disk.m_center, _disk.m_radius, 0.0f);
|
||||
drawCircle(_disk.normal, _disk.center, _disk.radius, 0.0f);
|
||||
}
|
||||
|
||||
void draw(const Obb& _obb)
|
||||
@@ -1467,7 +1467,7 @@ struct DebugDrawEncoderImpl
|
||||
const Attrib& attrib = m_attrib[m_stack];
|
||||
if (attrib.m_wireframe)
|
||||
{
|
||||
pushTransform(_obb.m_mtx, 1);
|
||||
pushTransform(_obb.mtx, 1);
|
||||
|
||||
moveTo(-1.0f, -1.0f, -1.0f);
|
||||
lineTo( 1.0f, -1.0f, -1.0f);
|
||||
@@ -1497,7 +1497,7 @@ struct DebugDrawEncoderImpl
|
||||
}
|
||||
else
|
||||
{
|
||||
draw(Mesh::Cube, _obb.m_mtx, 1, false);
|
||||
draw(Mesh::Cube, _obb.mtx, 1, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1506,15 +1506,15 @@ struct DebugDrawEncoderImpl
|
||||
const Attrib& attrib = m_attrib[m_stack];
|
||||
float mtx[16];
|
||||
bx::mtxSRT(mtx
|
||||
, _sphere.m_radius
|
||||
, _sphere.m_radius
|
||||
, _sphere.m_radius
|
||||
, _sphere.radius
|
||||
, _sphere.radius
|
||||
, _sphere.radius
|
||||
, 0.0f
|
||||
, 0.0f
|
||||
, 0.0f
|
||||
, _sphere.m_center.x
|
||||
, _sphere.m_center.y
|
||||
, _sphere.m_center.z
|
||||
, _sphere.center.x
|
||||
, _sphere.center.y
|
||||
, _sphere.center.z
|
||||
);
|
||||
uint8_t lod = attrib.m_lod > Mesh::SphereMaxLod
|
||||
? uint8_t(Mesh::SphereMaxLod)
|
||||
@@ -1523,6 +1523,29 @@ struct DebugDrawEncoderImpl
|
||||
draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, 1, attrib.m_wireframe);
|
||||
}
|
||||
|
||||
void draw(const Triangle& _triangle)
|
||||
{
|
||||
Attrib& attrib = m_attrib[m_stack];
|
||||
if (attrib.m_wireframe)
|
||||
{
|
||||
moveTo(_triangle.v0);
|
||||
lineTo(_triangle.v1);
|
||||
lineTo(_triangle.v2);
|
||||
close();
|
||||
}
|
||||
else
|
||||
{
|
||||
BX_STATIC_ASSERT(sizeof(DdVertex) == sizeof(bx::Vec3), "");
|
||||
|
||||
uint64_t old = attrib.m_state;
|
||||
attrib.m_state &= ~BGFX_STATE_CULL_MASK;
|
||||
|
||||
draw(false, 3, reinterpret_cast<const DdVertex*>(&_triangle.v0.x), 0, NULL);
|
||||
|
||||
attrib.m_state = old;
|
||||
}
|
||||
}
|
||||
|
||||
void setUParams(const Attrib& _attrib, bool _wireframe)
|
||||
{
|
||||
const float flip = 0 == (_attrib.m_state & BGFX_STATE_CULL_CCW) ? 1.0f : -1.0f;
|
||||
@@ -1643,11 +1666,15 @@ struct DebugDrawEncoderImpl
|
||||
bgfx::allocTransientIndexBuffer(&tib, numIndices);
|
||||
bx::memCopy(tib.data, _indices, numIndices * sizeof(uint16_t) );
|
||||
}
|
||||
|
||||
m_encoder->setIndexBuffer(&tib);
|
||||
}
|
||||
|
||||
m_encoder->setTransform(m_mtxStack[m_mtxStackCurrent].mtx);
|
||||
bgfx::ProgramHandle program = s_dds.m_program[wireframe ? Program::FillMesh : Program::FillLitMesh];
|
||||
bgfx::ProgramHandle program = s_dds.m_program[wireframe
|
||||
? Program::FillMesh
|
||||
: Program::FillLitMesh
|
||||
];
|
||||
m_encoder->submit(m_viewId, program);
|
||||
}
|
||||
}
|
||||
@@ -1958,11 +1985,11 @@ struct DebugDrawEncoderImpl
|
||||
draw(Mesh::Enum(Mesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
|
||||
|
||||
Sphere sphere;
|
||||
sphere.m_center = _from;
|
||||
sphere.m_radius = _radius;
|
||||
sphere.center = _from;
|
||||
sphere.radius = _radius;
|
||||
draw(sphere);
|
||||
|
||||
sphere.m_center = _to;
|
||||
sphere.center = _to;
|
||||
draw(sphere);
|
||||
}
|
||||
else
|
||||
@@ -2035,10 +2062,10 @@ struct DebugDrawEncoderImpl
|
||||
const uint32_t num = (_size/2)*2+1;
|
||||
const float halfExtent = float(_size/2);
|
||||
|
||||
const bx::Vec3 umin = bx::mul(udir, -halfExtent);
|
||||
const bx::Vec3 umax = bx::mul(udir, halfExtent);
|
||||
const bx::Vec3 vmin = bx::mul(vdir, -halfExtent);
|
||||
const bx::Vec3 vmax = bx::mul(vdir, halfExtent);
|
||||
const bx::Vec3 umin = bx::mul(udir, -halfExtent);
|
||||
const bx::Vec3 umax = bx::mul(udir, halfExtent);
|
||||
const bx::Vec3 vmin = bx::mul(vdir, -halfExtent);
|
||||
const bx::Vec3 vmax = bx::mul(vdir, halfExtent);
|
||||
|
||||
bx::Vec3 xs = bx::add(_center, bx::add(umin, vmin) );
|
||||
bx::Vec3 xe = bx::add(_center, bx::add(umax, vmin) );
|
||||
@@ -2457,9 +2484,14 @@ void DebugDrawEncoder::draw(const Sphere& _sphere)
|
||||
DEBUG_DRAW_ENCODER(draw(_sphere) );
|
||||
}
|
||||
|
||||
void DebugDrawEncoder::draw(const Triangle& _triangle)
|
||||
{
|
||||
DEBUG_DRAW_ENCODER(draw(_triangle) );
|
||||
}
|
||||
|
||||
void DebugDrawEncoder::draw(const Cone& _cone)
|
||||
{
|
||||
DEBUG_DRAW_ENCODER(drawCone(_cone.m_pos, _cone.m_end, _cone.m_radius) );
|
||||
DEBUG_DRAW_ENCODER(drawCone(_cone.pos, _cone.end, _cone.radius) );
|
||||
}
|
||||
|
||||
void DebugDrawEncoder::draw(GeometryHandle _handle)
|
||||
|
||||
Reference in New Issue
Block a user