forked from evan69/RayTrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
triangle.h
53 lines (48 loc) · 1.15 KB
/
triangle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include "all.h"
namespace HYF
{
class Triangle : public Primitive
{
public:
Triangle(vector3 A,vector3 B,vector3 C)
{
vertex[0] = A;vertex[1] = B;vertex[2] = C;
/*
std::cout << A.x << " "<< A.y << " " << A.z << '\n';
std::cout << B.x << " "<< B.y << " " << B.z << '\n';
std::cout << C.x << " "<< C.y << " " << C.z << '\n';
*/
N = -(B - A).Cross(C - B);
NORMALIZE(N);
}
double GetMinCoord(int coord){
double x0 = vertex[0][coord];
double x1 = vertex[1][coord];
double x2 = vertex[2][coord];
if (x0 < x1)
return (x0 < x2) ? x0 : x2;
return (x1 < x2) ? x1 : x2;
}
double GetMaxCoord(int coord) {
double x0 = vertex[0][coord];
double x1 = vertex[1][coord];
double x2 = vertex[2][coord];
if (x0 > x1)
return (x0 > x2) ? x0 : x2;
return (x1 > x2) ? x1 : x2;
}
int getType() {return TRIANGLE;}
int Intersect( Ray& p_Ray, double& p_Dist );
bool H_IntersectBox( BoundingBox& );
inline vector3 getNormal( vector3& p_Pos ){return N;}
inline vector3 getNormal(){return N;}
//Color getColor(vector3& p_Pos);
BoundingBox getBoundingBox();
protected:
vector3 vertex[3];
vector3 N;
};
}
#endif