-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOctree.h
More file actions
66 lines (60 loc) · 1.63 KB
/
Octree.h
File metadata and controls
66 lines (60 loc) · 1.63 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
/**
* \author Marie DARRIGOL & Anthony LEONARD & Ophélie PELLOUX-PRAYER & Olivier SOLDANO
* \project Ray-Tracing
* \class Octree.h
* \brief Octree representation of the scene and Octree collision
*/
#pragma once
#include <vector>
#include "SceneObject.h"
#include <iostream>
using namespace std;
// base on http://www.gamedev.net/page/resources/_/technical/game-programming/introduction-to-octrees-r3529
#define MIN_SIZE 0.1
class Node{
public:
Node();
Node(Vec3 min, Vec3 max, vector<SceneObject*>* sceneObjects);
~Node();
void addChild(Node* child){ children->push_back(child); };
void addSceneObject(SceneObject* sceneObject){ sceneObjects->push_back(sceneObject); };
/**
* recursive fonction for build the tree
**/
void buildTree();
/**
* Check if the scene object is in the region
**/
bool Contains(SceneObject*);
/**
* Determine the best scene objet collide
* return : impact point and the best scene object collide
* if not object was collide return ray's origin and nullptr
**/
pair<Vec3, SceneObject*> collide(Ray &ray);
/**
* Check if the ray intersect the region
**/
bool intersectRegion(Ray &ray);
private:
Vec3 minim;
Vec3 maxim;
vector<Node*>* children;
vector<SceneObject*>* sceneObjects;
};
class Octree{
public:
Octree();
Octree(vector<SceneObject*>* sceneObjects);
~Octree();
vector<SceneObject*>* copy(vector<SceneObject*>* sceneObjects);
/**
* Determine the best scene objet collide
* return : impact point and the best scene object collide
* if not object was collide return ray's origin and nullptr
**/
pair<Vec3, SceneObject*> collide(Ray &ray);
private:
// root node represent the all space
Node* root;
};