mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-18 04:53:06 +01:00
debugdraw: Added cone.
This commit is contained in:
@@ -174,6 +174,15 @@ class DebugDrawApp : public entry::AppI
|
||||
ddDrawCircle(Axis::Z, -8.0f, 0.0f, 0.0f, 1.25f, 2.0f);
|
||||
ddPop();
|
||||
|
||||
ddPush();
|
||||
{
|
||||
ddSetLod(UINT8_MAX);
|
||||
float from[3] = { -11.0f, 4.0f, 0.0f };
|
||||
float to[3] = { -13.0f, 6.0f, 1.0f };
|
||||
ddDrawCone(from, to, 0.5f );
|
||||
}
|
||||
ddPop();
|
||||
|
||||
ddDrawOrb(-11.0f, 0.0f, 0.0f, 1.0f);
|
||||
ddEnd();
|
||||
|
||||
|
||||
@@ -1018,6 +1018,73 @@ struct DebugDraw
|
||||
close();
|
||||
}
|
||||
|
||||
void drawCone(const float* _from, const float* _to, float _radius, float _weight = 0.0f)
|
||||
{
|
||||
const Attrib& attrib = m_attrib[m_stack];
|
||||
const uint32_t num = getCircleLod(attrib.m_lod);
|
||||
const float step = bx::pi * 2.0f / num;
|
||||
_weight = bx::fclamp(_weight, 0.0f, 2.0f);
|
||||
|
||||
float pos[3];
|
||||
float tmp0[3];
|
||||
float tmp1[3];
|
||||
|
||||
bx::vec3Sub(tmp0, _from, _to);
|
||||
|
||||
Plane plane;
|
||||
plane.m_dist = 0.0f;
|
||||
bx::vec3Norm(plane.m_normal, tmp0);
|
||||
|
||||
float udir[3];
|
||||
float vdir[3];
|
||||
calcPlaneUv(plane, udir, vdir);
|
||||
|
||||
float xy0[2];
|
||||
float xy1[2];
|
||||
circle(xy0, 0.0f);
|
||||
squircle(xy1, 0.0f);
|
||||
|
||||
bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
|
||||
bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
|
||||
bx::vec3Add(tmp1, pos, tmp0);
|
||||
bx::vec3Add(pos, tmp1, _from);
|
||||
moveTo(pos);
|
||||
|
||||
for (uint32_t ii = 1; ii < num; ++ii)
|
||||
{
|
||||
float angle = step * ii;
|
||||
circle(xy0, angle);
|
||||
squircle(xy1, angle);
|
||||
|
||||
bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
|
||||
bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
|
||||
bx::vec3Add(tmp1, pos, tmp0);
|
||||
bx::vec3Add(pos, tmp1, _from);
|
||||
lineTo(pos);
|
||||
}
|
||||
|
||||
close();
|
||||
|
||||
for (uint32_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
float angle = step * ii;
|
||||
circle(xy0, angle);
|
||||
squircle(xy1, angle);
|
||||
|
||||
bx::vec3Mul(pos, udir, bx::flerp(xy0[0], xy1[0], _weight)*_radius);
|
||||
bx::vec3Mul(tmp0, vdir, bx::flerp(xy0[1], xy1[1], _weight)*_radius);
|
||||
bx::vec3Add(tmp1, pos, tmp0);
|
||||
bx::vec3Add(pos, tmp1, _from);
|
||||
moveTo(pos);
|
||||
lineTo(_to);
|
||||
}
|
||||
}
|
||||
|
||||
void drawCone(const void* _from, const void* _to, float _radius, float _weight = 0.0f)
|
||||
{
|
||||
drawCone( (const float*)_from, (const float*)_to, _radius, _weight);
|
||||
}
|
||||
|
||||
void drawAxis(float _x, float _y, float _z, float _len, Axis::Enum _highlight)
|
||||
{
|
||||
push();
|
||||
@@ -1481,6 +1548,11 @@ void ddDrawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius,
|
||||
s_dd.drawCircle(_axis, _x, _y, _z, _radius, _weight);
|
||||
}
|
||||
|
||||
void ddDrawCone(const void* _from, const void* _to, float _radius, float _weight)
|
||||
{
|
||||
s_dd.drawCone(_from, _to, _radius, _weight);
|
||||
}
|
||||
|
||||
void ddDrawAxis(float _x, float _y, float _z, float _len, Axis::Enum _hightlight)
|
||||
{
|
||||
s_dd.drawAxis(_x, _y, _z, _len, _hightlight);
|
||||
|
||||
@@ -102,6 +102,9 @@ void ddDrawCircle(const void* _normal, const void* _center, float _radius, float
|
||||
///
|
||||
void ddDrawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _weight = 0.0f);
|
||||
|
||||
///
|
||||
void ddDrawCone(const void* _from, const void* _to, float _radius, float _weight = 0.0f);
|
||||
|
||||
///
|
||||
void ddDrawAxis(float _x, float _y, float _z, float _len = 1.0f, Axis::Enum _highlight = Axis::Count);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user