-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathanimation.h
62 lines (54 loc) · 1.86 KB
/
animation.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
#pragma once
namespace Tmpl8
{
// minimalist triangle struct
struct Tri { float3 vertex0, vertex1, vertex2; float3 centroid; };
// 32-byte BVH node struct
struct BVHNode
{
union { struct { float3 aabbMin; uint leftFirst; }; __m128 aabbMin4; };
union { struct { float3 aabbMax; uint triCount; }; __m128 aabbMax4; };
bool isLeaf() { return triCount > 0; }
};
// minimalist AABB struct with grow functionality
struct aabb
{
float3 bmin = 1e30f, bmax = -1e30f;
void grow( float3 p ) { bmin = fminf( bmin, p ); bmax = fmaxf( bmax, p ); }
void grow( aabb& b ) { if (b.bmin.x != 1e30f) { grow( b.bmin ); grow( b.bmax ); } }
float area()
{
float3 e = bmax - bmin; // box extent
return e.x * e.y + e.y * e.z + e.z * e.x;
}
};
// bin struct for binned BVH building
struct Bin { aabb bounds; int triCount = 0; };
// ray struct, prepared for SIMD AABB intersection
__declspec(align(64)) struct Ray
{
Ray() { O4 = D4 = rD4 = _mm_set1_ps( 1 ); }
union { struct { float3 O; float dummy1; }; __m128 O4; };
union { struct { float3 D; float dummy2; }; __m128 D4; };
union { struct { float3 rD; float dummy3; }; __m128 rD4; };
float t = 1e30f;
};
// game class
class AnimationApp : public TheApp
{
public:
// game flow methods
void Init();
void Tick( float deltaTime );
void Shutdown() { /* implement if you want to do something on exit */ }
// input handling
void MouseUp( int button ) { /* implement if you want to detect mouse button presses */ }
void MouseDown( int button ) { /* implement if you want to detect mouse button presses */ }
void MouseMove( int x, int y ) { mousePos.x = x, mousePos.y = y; }
void MouseWheel( float y ) { /* implement if you want to handle the mouse wheel */ }
void KeyUp( int key ) { /* implement if you want to handle keys */ }
void KeyDown( int key ) { /* implement if you want to handle keys */ }
// data members
int2 mousePos;
};
} // namespace Tmpl8