aboutsummaryrefslogtreecommitdiff
path: root/src/accelerate/kdtree.h
blob: e33aa59b76c1447d8cd41dc8bb540345eeabe953 (plain)
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 KDTREE_H
#define KDTREE_H
#include "utils/sceneparser.h"
#include <queue>
#include <vector>

typedef struct {
    glm::vec4 xmax;
    glm::vec4 xmin;
    glm::vec4 ymax;
    glm::vec4 ymin;
    glm::vec4 zmax;
    glm::vec4 zmin;
    glm::vec4 center;
} BoundingRegion;

typedef struct KdShape
{
    RenderShapeData shape;
    BoundingRegion region;
} KdShape;

class KdTree
{
public:

    KdTree(int pDimension, float pSplitCoord);

    bool empty;
    int dimension;
    float splitCoord;
    std::vector<KdShape> shapesWithinBounds;
    void insert(KdShape shape);

    KdTree *leftChild;
    KdTree *rightChild;

    // todo: make basis a matrix
    static BoundingRegion transformBoundingRegion(BoundingRegion region, glm::mat4 transformationMatrix, glm::vec3 basis=glm::vec3(1.0f, 1.0f, 1.0f));
};

const static BoundingRegion OBJECT_BOUNDS{
        glm::vec4(.5f, 0.f, 0.f, 1.f),
        glm::vec4(-.5f, 0.f, 0.f, 1.f),
        glm::vec4(0.f, .5f, 0.f, 1.f),
        glm::vec4(0.f, -.5f, 0.f, 1.f),
        glm::vec4(0.f, 0.f, .5f, 1.f),
        glm::vec4(0.f, 0.f, -.5f, 1.f),
        glm::vec4(0.f, 0.f, 0.f, 1.f)
};


#endif // KDTREE_H