浏览代码

29-debugdraw: Display intersection normal.

Branimir Karadžić 8 年之前
父节点
当前提交
07f5e1184c
共有 2 个文件被更改,包括 29 次插入3 次删除
  1. 26 0
      examples/29-debugdraw/debugdraw.cpp
  2. 3 3
      examples/common/bounds.cpp

+ 26 - 0
examples/29-debugdraw/debugdraw.cpp

@@ -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) )

+ 3 - 3
examples/common/bounds.cpp

@@ -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);