forked from evan69/RayTrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plane.cpp
74 lines (69 loc) · 1.55 KB
/
plane.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "all.h"
namespace HYF
{
Color PlanePrim::getColor(vector3& p_Pos)
{
if(m_Material.getTexure() == NULL)
{
return m_Material.getColor();
}
double u = DOT(p_Pos,x_Dir) * m_Material.getTexRatioDao();
double v = DOT(p_Pos,y_Dir) * m_Material.getTexRatioDao();
return m_Material.getTexure()->getUVColor(u,v);
//return m_Material.getColor();
}
int PlanePrim::Intersect( Ray& p_Ray, double& p_Dist )
{
double d = DOT( m_Plane.N, p_Ray.getDirection() );
if (d != 0)
//if (d < EPS && d > -EPS)
{
double dist = -(DOT( m_Plane.N, p_Ray.getOrigin() ) + m_Plane.D) / d;
if (dist > 0)
{
if (dist < p_Dist)
{
p_Dist = dist;
return HIT;
}
}
}
return MISS;
}
bool PlanePrim::H_IntersectBox(BoundingBox& p_b)
{
vector3 pos = p_b.getPos();
vector3 size = p_b.getSize();
int num1 = 0,num2 = 0;
for(int i = 0;i < 2;++i)
for(int j = 0;j < 2;++j)
for(int k = 0;k < 2;++k)
{
vector3 newpos = pos + vector3(i * size.x,j * size.y,k * size.z);
if((DOT(newpos,getNormal()) + m_Plane.D) < 0)
{
num1++;
}
else
{
num2++;
}
}
if(num1 == 0 || num2 == 0) return false;
else return true;
}
/*
bool PlanePrim::H_IntersectBox( BoundingBox& p_Box )
{
vector3 v[2];
v[0] = p_Box.getPos(), v[1] = p_Box.getPos() + p_Box.getSize();
int side1,side2,i;
for ( side1 = 0, side2 = 0, i = 0; i < 8; i++ )
{
vector3 p( v[i & 1].x, v[(i >> 1) & 1].y, v[(i >> 2) & 1].z );
if ((DOT( p, m_Plane.N ) + m_Plane.D) < 0) side1++; else side2++;
}
if ((side1 == 0) || (side2 == 0)) return false; else return true;
}
*/
}