00001
00002
00003 #ifndef TRIANGLE_H
00004 #define TRIANGLE_H
00005
00006
00007 #include "Plane.h"
00008 #include "Texture.h"
00009 #include "Vector2f.h"
00010 #include "Vector3f.h"
00011
00012
00013 namespace pge {
00014
00015 struct Triangle {
00016
00017
00018
00019
00020 Triangle(void) {
00021 m_texture = NULL;
00022 m_plane = NULL;
00023 }
00024
00025
00026 Vector3f m_vertices[3];
00027
00028
00029 Vector2f m_texCoords[3];
00030
00031
00032 Texture* m_texture;
00033
00034
00035 Plane *m_plane;
00036 };
00037
00038
00039 namespace triangle {
00040
00041
00042
00043 static bool sameSide(Vector3f p0, Vector3f p1, Vector3f a, Vector3f b) {
00044 Vector3f cp0;
00045 Vector3f cp1;
00046
00047 cp0 = (b.subtract(a)).crossProduct(p0.subtract(a));
00048 cp1 = (b.subtract(a)).crossProduct(p1.subtract(a));
00049
00050 if (cp0.dotProduct(cp1) >= 0.0f) {
00051 return true;
00052 }
00053 return false;
00054 }
00055
00056
00057
00058
00059 static bool isPointInside(const Vector3f &point, const Triangle &triangle) {
00060 if(sameSide(point, triangle.m_vertices[0], triangle.m_vertices[1], triangle.m_vertices[2])
00061 && sameSide(point, triangle.m_vertices[1], triangle.m_vertices[0], triangle.m_vertices[2])
00062 && sameSide(point, triangle.m_vertices[2], triangle.m_vertices[0], triangle.m_vertices[1])) {
00063 return true;
00064 }
00065 return false;
00066 }
00067
00068
00069
00070
00071
00072 static bool isPointInside(const Vector3f &point, const Vector3f &a, const Vector3f &b, const Vector3f &c) {
00073 if (sameSide(point, a, b, c) && sameSide(point, b, a, c) && sameSide(point, c, a, b)) {
00074 return true;
00075 }
00076 return false;
00077 }
00078 };
00079 };
00080
00081 #endif