diff --git a/examples/29-debugdraw/debugdraw.cpp b/examples/29-debugdraw/debugdraw.cpp index 29f1cde2a..f0950a205 100644 --- a/examples/29-debugdraw/debugdraw.cpp +++ b/examples/29-debugdraw/debugdraw.cpp @@ -187,12 +187,18 @@ class DebugDrawApp : public entry::AppI 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 ); - } + { + float from[3] = { -11.0f, 4.0f, 0.0f }; + float to[3] = { -13.0f, 6.0f, 1.0f }; + ddDrawCone(from, to, 1.0f ); + } + + { + float from[3] = { -9.0f, 2.0f, -1.0f }; + float to[3] = { -11.0f, 4.0f, 0.0f }; + ddDrawCylinder(from, to, 0.5f ); + } ddPop(); ddDrawOrb(-11.0f, 0.0f, 0.0f, 1.0f); diff --git a/examples/common/debugdraw/debugdraw.cpp b/examples/common/debugdraw/debugdraw.cpp index 6b0ae7145..f02e4d652 100644 --- a/examples/common/debugdraw/debugdraw.cpp +++ b/examples/common/debugdraw/debugdraw.cpp @@ -1085,6 +1085,65 @@ struct DebugDraw drawCone( (const float*)_from, (const float*)_to, _radius, _weight); } + void drawCylinder(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); + + float pos1[3]; + 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); + bx::vec3Add(pos1, tmp1, _to); + + for (uint32_t ii = 1; ii < num+1; ++ii) + { + float angle = step * ii; + circle(xy0, angle); + squircle(xy1, angle); + + moveTo(pos); lineTo(pos1); + + moveTo(pos); + 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); + + moveTo(pos1); + bx::vec3Add(pos1, tmp1, _to); + lineTo(pos1); + } + } + + void drawCylinder(const void* _from, const void* _to, float _radius, float _weight = 0.0f) + { + drawCylinder( (const float*)_from, (const float*)_to, _radius, _weight); + } + void drawAxis(float _x, float _y, float _z, float _len, Axis::Enum _highlight) { push(); @@ -1554,6 +1613,11 @@ void ddDrawCone(const void* _from, const void* _to, float _radius, float _weight s_dd.drawCone(_from, _to, _radius, _weight); } +void ddDrawCylinder(const void* _from, const void* _to, float _radius, float _weight) +{ + s_dd.drawCylinder(_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); diff --git a/examples/common/debugdraw/debugdraw.h b/examples/common/debugdraw/debugdraw.h index 84502297f..0888ffdae 100644 --- a/examples/common/debugdraw/debugdraw.h +++ b/examples/common/debugdraw/debugdraw.h @@ -105,6 +105,9 @@ void ddDrawCircle(Axis::Enum _axis, float _x, float _y, float _z, float _radius, /// void ddDrawCone(const void* _from, const void* _to, float _radius, float _weight = 0.0f); +/// +void ddDrawCylinder(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);