-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcube.cpp
More file actions
99 lines (82 loc) · 2.17 KB
/
cube.cpp
File metadata and controls
99 lines (82 loc) · 2.17 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "cube.h"
bool Cube::isInside(float3 point)
{
float3 min = origin - size * 0.5f;
float3 max = origin + size * 0.5f;
if(point.x >= min.x && point.x <= max.x
&& point.y >= min.y && point.y <= max.y
&& point.z >= min.z && point.z <= max.z)
return true;
else
return false;
}
/* bool Cube::intersection(const float3& origin, const float3& normal, float3& output)
{
float3 p;
float3 n;
float3 l = origin;
float3 r = normal;
float3 point[6];
bool cross[6];
for(int = i; i<6; i++) cross=false;
// ---------------------------- X ------------------------------//
p = this->origin + float3(size.x/2.f, 0.f, 0.f);
n= float3(1.f, 0.f, 0.f);
if(dot(n, r) != 0.f)
{
float d = dot(p - l, n) / dot(n, r);
point[0] = origin + normal * d;
corss[0] = true;
}
//------------------------------ -X -------------------------------//
p = this->origin + float3(-size.x/2.f, 0.f, 0.f);
n = float3(1.f, 0.f, 0.f);
if(dot(n, r) != 0.f)
{
float d = dot(p - l, n) / dot(n, r);
point[1] = origin + normal * d;
corss[1] = true;
}
//------------------------------ Y -------------------------------//
p = this->origin + float3(0.f, +size.y/2.f, 0.f);
n = float3(0.f, 1.f, 0.f);
if(dot(n, r) != 0.f)
{
float d = dot(p - l, n) / dot(n, r);
point[2] = origin + normal * d;
corss[2] = true;
}
//------------------------------ Y -------------------------------//
p = this->origin + float3(0.f, -size.y/2.f, 0.f);
n = float3(0.f, 1.f, 0.f);
if(dot(n, r) != 0.f)
{
float d = dot(p - l, n) / dot(n, r);
point[3] = origin + normal * d;
corss[3] = true;
}
//------------------------------ Z -------------------------------//
p = this->origin + float3(0.f, 0.f, +size.z/2.f);
n = float3(0.f, 0.f, 1.f);
if(dot(n, r) != 0.f)
{
float d = dot(p - l, n) / dot(n, r);
point[4] = origin + normal * d;
corss[4] = true;
}
//------------------------------ Z -------------------------------//
p = this->origin + float3(0.f, 0.f, -size.z/2.f);
n = float3(0.f, 0.f, 1.f);
if(dot(n, r) != 0.f)
{
float d = dot(p - l, n) / dot(n, r);
point[5] = origin + normal * d;
corss[5] = true;
}
for(int i = 0; i < 6; i++)
{
if(cross[i] == true)
{
}
}
} */