1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 
22 // Triangle.h: interface for the Triangle class.
23 //
24 //////////////////////////////////////////////////////////////////////
25 
26 #if !defined(AFX_TRIANGLE_H__B076B031_36ED_11D3_BE80_000000000000__INCLUDED_)
27 #define AFX_TRIANGLE_H__B076B031_36ED_11D3_BE80_000000000000__INCLUDED_
28 
29 #include <common/Line.h>
30 
31 class Triangle
32 {
33 public:
34 	Triangle();
35 	virtual ~Triangle();
36 
getNormal()37 	Vector &getNormal() { return faceN_; }
38 
39 	void setPointComponents(const float ptA1, const float ptA2, const float ptA3,
40 		Vector &normalA,
41 		const float ptB1, const float ptB2, const float ptB3,
42 		Vector &normalB,
43 		const float ptC1, const float ptC2, const float ptC3,
44 		Vector &normalC);
45 
46 	bool pointInBoundingBox(const Vector &pt);
47 	bool pointInTriangle(const Vector &pt);
48 
49 	virtual bool rayIntersect(
50 		const Line &ray,
51 		Vector &intersectPt,
52 		Vector &intersectN,
53 		float &intersectDist,
54 		const bool checkPtOnLine = true);
55 
56 	virtual bool sphereIntersect(
57 		Vector &sphereCentre,
58 		float &sphereRadius,
59 		Vector &intersectPt,
60 		Vector &intersectN,
61 		float &intersectDist);
62 
63 protected:
64 	enum largestNormalPart
65 	{
66 		scalarX,
67 		scalarY,
68 		scalarZ
69 	} largest_;
70 
71 	Vector ptA_, ptB_, ptC_;
72 	Vector faceN_;
73 
74 	void calcNormal();
75 	void calcLargest();
76 };
77 
78 #endif // !defined(AFX_TRIANGLE_H__B076B031_36ED_11D3_BE80_000000000000__INCLUDED_)
79