29-debugdraw: Display intersection normal.

This commit is contained in:
Branimir Karadžić 2017-09-28 22:52:23 -07:00
parent c89a4106b3
commit 07f5e1184c
2 changed files with 29 additions and 3 deletions

View File

@ -94,6 +94,32 @@ public:
return 0;
}
template<typename Ty>
bool intersect(const Ray& _ray, const Ty& _shape)
{
Hit hit;
if (::intersect(_ray, _shape, &hit) )
{
ddPush();
ddSetColor(0xff0000ff);
float tmp[3];
bx::vec3Mul(tmp, hit.m_normal, 0.7f);
float end[3];
bx::vec3Add(end, hit.m_pos, tmp);
ddDrawCone(hit.m_pos, end, 0.1f);
ddPop();
return true;
}
return false;
}
bool update() override
{
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )

View File

@ -729,14 +729,14 @@ bool intersect(const Ray& _ray, const Capsule& _capsule, Hit* _hit)
bool intersect(const Ray& _ray, const Cone& _cone, Hit* _hit)
{
float axis[3];
bx::vec3Sub(axis, _cone.m_end, _cone.m_pos);
bx::vec3Sub(axis, _cone.m_pos, _cone.m_end);
float normal[3];
const float len = bx::vec3Norm(normal, axis);
Disk disk;
bx::vec3Move(disk.m_center, _cone.m_pos);
bx::vec3Neg(disk.m_normal, normal);
bx::vec3Move(disk.m_normal, normal);
disk.m_radius = _cone.m_radius;
Hit tmpInt;
@ -783,7 +783,7 @@ bool intersect(const Ray& _ray, const Cone& _cone, Hit* _hit)
getPointAt(hitPos, _ray, tt);
float point[3];
bx::vec3Sub(point, hitPos, _cone.m_pos);
bx::vec3Sub(point, hitPos, _cone.m_end);
const float hh = bx::vec3Dot(normal, point);