-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAABB.h
64 lines (49 loc) · 1.31 KB
/
AABB.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
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <math.h>
#include "vectors_math.h"
#include "stdio.h"
class AABB
{
public:
float4 min, max;
AABB () {
clear() ;
} ;
void clear() {
min = make_float4 ( exp( 80.0f ), exp( 80.0f ), exp( 80.0f ), 1.0f );
max = make_float4 ( -exp( 80.0f ), -exp( 80.0f ), -exp( 80.0f ), 1.0f );
} ;
void set ( const float3 & m_min, const float3 & m_max ) {
min = make_float4 (m_min);
max = make_float4 (m_max);
} ;
void update ( float4 &v0 ) {
min = fminf1 ( min, v0 ); // fmin4
max = fmaxf1 ( max, v0 ); // fmax4
} ;
void update3 ( float4 &v0, float4 &v1, float4 &v2 ) {
update ( v0 );
update ( v1 );
update ( v2 );
} ;
void check_into ( AABB & box ) { // ñîìíèòåëüíî
min = fmaxf1 ( min, box.min ); // fmax4
max = fminf1 ( max, box.max ); // fmin4
} ;
float getVolume() {
return ( max.x - min.x ) * ( max.y - min.y ) * ( max.z - min.z );
} ;
float getSurfaceArea() {
float side1 = max.x - min.x;
float side2 = max.y - min.y;
float side3 = max.z - min.z;
// The current box has a cost of (No of triangles)*surfaceArea
return (side1*side2 + side2*side3 + side3*side1);
} ;
void print() {
printf ( "\n min = ( %.2f, %.2f, %.2f ) ", min.x, min.y, min.z );
printf ( "\n max = ( %.2f, %.2f, %.2f ) \n", max.x, max.y, max.z );
} ;
//AABB(void);
~AABB(void);
};