소스 검색

Delete Triangle

Daniele Bartolini 12 년 전
부모
커밋
9758f583d0
4개의 변경된 파일14개의 추가작업 그리고 337개의 파일을 삭제
  1. 0 1
      engine/CMakeLists.txt
  2. 0 1
      engine/Crown.h
  3. 14 182
      engine/core/math/Intersection.h
  4. 0 153
      engine/core/math/Triangle.h

+ 0 - 1
engine/CMakeLists.txt

@@ -161,7 +161,6 @@ set (MATH_HEADERS
 	core/math/Plane.h
 	core/math/Quaternion.h
 	core/math/Random.h
-	core/math/Ray.h
 	core/math/Triangle.h
 	core/math/Vector2.h
 	core/math/Vector3.h

+ 0 - 1
engine/Crown.h

@@ -42,7 +42,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Quaternion.h"
 #include "Random.h"
 #include "Ray.h"
-#include "Triangle.h"
 #include "Vector2.h"
 #include "Vector3.h"
 #include "Vector4.h"

+ 14 - 182
engine/core/math/Intersection.h

@@ -32,7 +32,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Frustum.h"
 #include "MathUtils.h"
 #include "Types.h"
-#include "Triangle.h"
 #include "Circle.h"
 #include "Rect.h"
 
@@ -41,21 +40,20 @@ namespace crown
 
 /// Intersection test utils.
 /// Table of Intersection tests (3d)
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// |          | Ray      | Plane    | Sphere   | Box      | Frustum  | Triangle |
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// | Ray      | No       | Yes      | Yes      | No       | No       | Yes      |
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// | Plane    | -        | Yes (1)  | Yes (+)  | No       | No       | No       |
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// | Sphere   | -        | -        | Yes (+)  | No       | Yes      | Yes (+)  |
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// | Box      | -        | -        | -        | Yes (+)  | Yes      | No       |
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// | Frustum  | -        | -        | -        | -        | No       | No       |
-/// +----------+----------+----------+----------+----------+----------+----------+
-/// | Triangle | -        | -        | -        | -        | -        | No       |
-/// +----------+----------+----------+----------+----------+----------+----------+
+/// +----------+----------+----------+----------+----------+----------+
+/// |          | Ray      | Plane    | Sphere   | Box      | Frustum  |
+/// +----------+----------+----------+----------+----------+----------+
+/// | Ray      | No       | Yes      | Yes      | No       | No       |
+/// +----------+----------+----------+----------+----------+----------+
+/// | Plane    | -        | Yes (1)  | Yes (+)  | No       | No       |
+/// +----------+----------+----------+----------+----------+----------+
+/// | Sphere   | -        | -        | Yes (+)  | No       | Yes      |
+/// +----------+----------+----------+----------+----------+----------+
+/// | Box      | -        | -        | -        | Yes (+)  | Yes      |
+/// +----------+----------+----------+----------+----------+----------+
+/// | Frustum  | -        | -        | -        | -        | No       |
+/// +----------+----------+----------+----------+----------+----------+
+//
 /// Notes:
 /// (1): Intersection of three planes
 /// (-): Static intersection only
@@ -85,14 +83,12 @@ public:
 	static bool test_ray_plane(const Ray& r, const Plane& p, float& distance, Vector3& inttersectionPoint_t);
 	static bool test_ray_sphere(const Ray& r, const Sphere& s, float& distance, Vector3& intersectionPoint);
 	static bool test_ray_box(const Ray& r, const Box& b, float& distance, Vector3& intersectionPoint);
-	static bool test_ray_triangle(const Ray& r, const Triangle& t, float& distance, Vector3& intersectionPoint);
 
 	static bool test_plane_3(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip);
 
 	static bool test_static_sphere_plane(const Sphere& s, const Plane& p);
 	static bool test_static_sphere_sphere(const Sphere& a, const Sphere& b);
 	static bool test_dynamic_sphere_plane(const Sphere& s, const Vector3& d, const Plane& p, float& it, Vector3& intersectionPoint);
-	static bool test_dynamic_sphere_triangle(const Sphere& s, const Vector3& d, const Triangle& tri, float& it, Vector3& intersectionPoint);
 	static bool test_dynamic_sphere_sphere(const Sphere& s1, const Vector3& d1, const Sphere& s2, const Vector3& d2, float& it, Vector3& intersectionPoint);
 
 	static bool test_static_box_box(const Box& b1, const Box& b2);
@@ -207,20 +203,6 @@ inline bool Intersection::test_ray_box(const Ray& r, const Box& b, float& /*dist
 	// TODO
 }
 
-//-----------------------------------------------------------------------------
-inline bool Intersection::test_ray_triangle(const Ray& r, const Triangle& t, float& distance, Vector3& intersectionPoint)
-{
-	if (Intersection::test_ray_plane(r, t.to_plane(), distance, intersectionPoint))
-	{
-		if (t.contains_point(intersectionPoint))
-		{
-			return true;
-		}
-	}
-
-	return false;
-}
-
 //-----------------------------------------------------------------------------
 inline bool Intersection::test_plane_3(const Plane& p1, const Plane& p2, const Plane& p3, Vector3& ip)
 {
@@ -307,156 +289,6 @@ inline bool Intersection::test_dynamic_sphere_plane(const Sphere& s, const Vecto
 	return false;
 }
 
-//-----------------------------------------------------------------------------
-inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Vector3& d, const Triangle& tri, float& it, Vector3& intersectionPoint)
-{
-	Plane triPlane = tri.to_plane();
-
-	// Test against the plane containing the triangle
-	float spherePlaneIt;
-	if (!test_dynamic_sphere_plane(s, d, triPlane, spherePlaneIt, intersectionPoint))
-	{
-		return false;
-	}
-
-	// Check if the int32_tersection point32_t lies inside the triangle
-	if (tri.contains_point(intersectionPoint))
-	{
-		it = spherePlaneIt;
-		// intersectionPoint is already returned by the above call to test_dynamic_sphere_plane
-		return true;
-	}
-
-	it = spherePlaneIt;
-
-	// Sweep test
-	// Check for collision against the vertices
-	bool collisionFound = false;
-	float a, b, c;
-	float x1, x2;
-
-	// v1
-	a = vector3::dot(d, d);
-	b = 2.0 * (vector3::dot(d, s.center() - tri.m_vertex[0]));
-	c = vector3::dot(tri.m_vertex[0] - s.center(), tri.m_vertex[0] - s.center()) - (s.radius() * s.radius());
-
-	if (math::solve_quadratic_equation(a, b, c, x1, x2))
-	{
-		it = math::min(x1, it);
-		intersectionPoint = tri.m_vertex[0];
-		collisionFound = true;
-	}
-
-	// v2
-	b = 2.0 * (vector3::dot(d, s.center() - tri.m_vertex[1]));
-	c = vector3::dot(tri.m_vertex[1] - s.center(), tri.m_vertex[1] - s.center()) - (s.radius() * s.radius());
-
-	if (math::solve_quadratic_equation(a, b, c, x1, x2))
-	{
-		it = math::min(x1, it);
-		intersectionPoint = tri.m_vertex[1];
-		collisionFound = true;
-	}
-
-	// v3
-	b = 2.0 * (vector3::dot(d, s.center() - tri.m_vertex[2]));
-	c = vector3::dot(tri.m_vertex[2] - s.center(), tri.m_vertex[2] - s.center()) - (s.radius() * s.radius());
-
-	if (math::solve_quadratic_equation(a, b, c, x1, x2))
-	{
-		it = math::min(x1, it);
-		intersectionPoint = tri.m_vertex[2];
-		collisionFound = true;
-	}
-
-	// Check for collisions against the edges
-	Vector3 edge;
-	Vector3 centerToVertex;
-	float edgeDotVelocity;
-	float edgeDotCenterToVertex;
-	float edgeSquaredLength;
-	float velocitySquaredLength;
-
-	velocitySquaredLength = vector3::squared_length(d);
-
-	// e1
-	edge = tri.m_vertex[1] - tri.m_vertex[0];
-	centerToVertex = tri.m_vertex[0] - s.center();
-	edgeDotVelocity = vector3::dot(edge, d);
-	edgeDotCenterToVertex = vector3::dot(edge, centerToVertex);
-	edgeSquaredLength = vector3::squared_length(edge);
-
-
-	a = edgeSquaredLength * -velocitySquaredLength + edgeDotVelocity * edgeDotVelocity;
-	b = edgeSquaredLength * (2.0 * vector3::dot(d, centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
-
-	c = edgeSquaredLength * s.radius() * s.radius() - vector3::squared_length(centerToVertex) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
-
-	if (math::solve_quadratic_equation(a, b, c, x1, x2))
-	{
-		float f0 = (edgeDotVelocity * x1 - edgeDotCenterToVertex) / edgeSquaredLength;
-
-		if (f0 >= 0.0 && f0 <= 1.0)
-		{
-			it = math::min(x1, it);
-			intersectionPoint = tri.m_vertex[0] + f0 * edge;
-			collisionFound = true;
-		}
-	}
-
-	// e2
-	edge = tri.m_vertex[2] - tri.m_vertex[1];
-	centerToVertex = tri.m_vertex[1] - s.center();
-	edgeDotVelocity = vector3::dot(edge, d);
-	edgeDotCenterToVertex = vector3::dot(edge, centerToVertex);
-	edgeSquaredLength = vector3::squared_length(edge);
-
-
-	a = edgeSquaredLength * -velocitySquaredLength + edgeDotVelocity * edgeDotVelocity;
-	b = edgeSquaredLength * 2.0 * vector3::dot(d, centerToVertex) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
-
-	c = edgeSquaredLength * ((s.radius() * s.radius()) - vector3::squared_length(centerToVertex)) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
-
-	if (math::solve_quadratic_equation(a, b, c, x1, x2))
-	{
-		float f0 = (edgeDotVelocity * x1 - edgeDotCenterToVertex) / edgeSquaredLength;
-
-		if (f0 >= 0.0 && f0 <= 1.0)
-		{
-			it = math::min(x1, it);
-			intersectionPoint = tri.m_vertex[1] + f0 * edge;
-			collisionFound = true;
-		}
-	}
-
-	// e3
-	edge = tri.m_vertex[0] - tri.m_vertex[2];
-	centerToVertex = tri.m_vertex[2] - s.center();
-	edgeDotVelocity = vector3::dot(edge, d);
-	edgeDotCenterToVertex = vector3::dot(edge, centerToVertex);
-	edgeSquaredLength = vector3::squared_length(edge);
-
-
-	a = edgeSquaredLength * -velocitySquaredLength + edgeDotVelocity * edgeDotVelocity;
-	b = edgeSquaredLength * (2.0 * vector3::dot(d, centerToVertex)) - (2.0 * edgeDotVelocity * edgeDotCenterToVertex);
-
-	c = edgeSquaredLength * ((s.radius() * s.radius()) - vector3::squared_length(centerToVertex)) + (edgeDotCenterToVertex * edgeDotCenterToVertex);
-
-	if (math::solve_quadratic_equation(a, b, c, x1, x2))
-	{
-		float f0 = (edgeDotVelocity * x1 - edgeDotCenterToVertex) / edgeSquaredLength;
-
-		if (f0 >= 0.0 && f0 <= 1.0)
-		{
-			it = math::min(x1, it);
-			intersectionPoint = tri.m_vertex[2] + f0 * edge;
-			collisionFound = true;
-		}
-	}
-
-	return collisionFound;
-}
-
 //-----------------------------------------------------------------------------
 inline bool Intersection::test_dynamic_sphere_sphere(const Sphere& s1, const Vector3& d1, const Sphere& s2, const Vector3& d2, float& it, Vector3& /*intersectionPoint*/)
 {

+ 0 - 153
engine/core/math/Triangle.h

@@ -1,153 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Vector3.h"
-#include "Plane.h"
-#include "MathUtils.h"
-
-namespace crown
-{
-
-
-///	3D Triangle.
-///
-/// Used mainly for collision detection.
-struct Triangle
-{
-public:
-
-	/// Does nothing for efficiency.
-				Triangle();
-				Triangle(const Vector3& v1, const Vector3& v2, const Vector3& v3);
-				~Triangle();
-
-	float		area() const;
-
-	/// Returns the center of gravity (a.k.a. "centroid").
-	Vector3		centroid() const;
-
-	/// Returns the barycentric coordinates of point @a p in respect to the triangle.
-	Vector3		barycentric_coords(const Vector3& p) const;
-
-	/// Returns whether the triangle contains the @a p point.
-	bool		contains_point(const Vector3& p) const;
-
-	/// Returns the plane containing the triangle.
-	Plane		to_plane() const;
-
-private:
-
-	// Vertices in CCW order
-	Vector3		m_vertex[3];
-
-	friend class Intersection;
-};
-
-//-----------------------------------------------------------------------------
-inline Triangle::Triangle()
-{
-}
-
-//-----------------------------------------------------------------------------
-inline Triangle::Triangle(const Vector3& v1, const Vector3& v2, const Vector3& v3)
-{
-	m_vertex[0] = v1;
-	m_vertex[1] = v2;
-	m_vertex[2] = v3;
-}
-
-//-----------------------------------------------------------------------------
-inline Triangle::~Triangle()
-{
-}
-
-//-----------------------------------------------------------------------------
-inline float Triangle::area() const
-{
-	Vector3 cr = vector3::cross(m_vertex[1] - m_vertex[0], m_vertex[2] - m_vertex[0]);
-	return vector3::length(cr * 0.5);
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Triangle::centroid() const
-{
-	return (m_vertex[0] + m_vertex[1] + m_vertex[2]) * math::ONE_OVER_THREE;
-}
-
-//-----------------------------------------------------------------------------
-inline Vector3 Triangle::barycentric_coords(const Vector3& p) const
-{
-	Vector3 e1 = m_vertex[2] - m_vertex[1];
-	Vector3 e2 = m_vertex[0] - m_vertex[2];
-	Vector3 e3 = m_vertex[1] - m_vertex[0];
-
-	Vector3 d1 = p - m_vertex[0];
-	Vector3 d2 = p - m_vertex[1];
-	Vector3 d3 = p - m_vertex[2];
-
-	Vector3 n = vector3::cross(e1, e2) / vector3::length(vector3::cross(e1, e2));
-
-	// Signed areas
-	float at = (float)(vector3::dot(vector3::cross(e1, e2), n) * 0.5);
-
-	float at1 = (float)(vector3::dot(vector3::cross(e1, d3), n) * 0.5);
-	float at2 = (float)(vector3::dot(vector3::cross(e2, d1), n) * 0.5);
-	float at3 = (float)(vector3::dot(vector3::cross(e3, d2), n) * 0.5);
-
-	float oneOverAt = (float)(1.0 / at);
-
-	return Vector3(at1 * oneOverAt, at2 * oneOverAt, at3 * oneOverAt);
-}
-
-//-----------------------------------------------------------------------------
-inline bool Triangle::contains_point(const Vector3& p) const
-{
-	Vector3 bc = barycentric_coords(p);
-
-	if (bc.x < 0.0 || bc.y < 0.0 || bc.z < 0.0)
-	{
-		return false;
-	}
-
-	return true;
-}
-
-//-----------------------------------------------------------------------------
-inline Plane Triangle::to_plane() const
-{
-	Vector3 e1 = m_vertex[2] - m_vertex[1];
-	Vector3 e2 = m_vertex[1] - m_vertex[0];
-
-	Vector3 e2xe1 = vector3::cross(e2, e1);
-	Vector3 n = vector3::normalize(e2xe1);
-	float d = -vector3::dot(n, m_vertex[0]);
-
-	return Plane(n, d);
-}
-
-} // namespace crown