include/octree.h
branchpyrit
changeset 95 ca7d4c665531
parent 94 4c8abb8977dc
child 98 64638385798a
equal deleted inserted replaced
94:4c8abb8977dc 95:ca7d4c665531
    59 	void setLeaf() { leaf = leaf | 1; };
    59 	void setLeaf() { leaf = leaf | 1; };
    60 
    60 
    61 	void makeChildren() { children = new OctreeNode[8]; assert(!isLeaf()); }; // this also cleans leaf bit
    61 	void makeChildren() { children = new OctreeNode[8]; assert(!isLeaf()); }; // this also cleans leaf bit
    62 	OctreeNode *getChild(const int num) { assert(!isLeaf()); return children + num; };
    62 	OctreeNode *getChild(const int num) { assert(!isLeaf()); return children + num; };
    63 
    63 
    64 	void addShape(Shape* aShape) { getShapes()->push_back(aShape); };
    64 	void addShape(const Shape* aShape) { getShapes()->push_back(aShape); };
    65 	ShapeList *getShapes() { return (ShapeList*)((size_t)shapes & ~(size_t)1); };
    65 	ShapeList *getShapes() { return (ShapeList*)((size_t)shapes & ~(size_t)1); };
    66 	void setShapes(ShapeList *const ashapes) { shapes = ashapes; assert(!isLeaf()); setLeaf(); };
    66 	void setShapes(ShapeList *const ashapes) { shapes = ashapes; assert(!isLeaf()); setLeaf(); };
    67 
    67 
    68 	void subdivide(const BBox &bbox, int maxdepth);
    68 	void subdivide(const BBox &bbox, int maxdepth);
    69 };
    69 };
    78 	bool built;
    78 	bool built;
    79 public:
    79 public:
    80 	Octree() : Container(), root(NULL), max_depth(10), built(false) {};
    80 	Octree() : Container(), root(NULL), max_depth(10), built(false) {};
    81 	Octree(int maxdepth) : Container(), root(NULL), max_depth(maxdepth), built(false) {};
    81 	Octree(int maxdepth) : Container(), root(NULL), max_depth(maxdepth), built(false) {};
    82 	~Octree() { if (root) delete root; };
    82 	~Octree() { if (root) delete root; };
    83 	void addShape(Shape* aShape) { Container::addShape(aShape); built = false; };
    83 	void addShape(const Shape* aShape) { Container::addShape(aShape); built = false; };
    84 	Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    84 	const Shape *nearest_intersection(const Shape *origin_shape, const Ray &ray,
    85 		Float &nearest_distance);
    85 		Float &nearest_distance);
    86 	void optimize() { build(); };
    86 	void optimize() { build(); };
    87 	void build();
    87 	void build();
    88 	void save(ostream &str, OctreeNode *node = NULL) {};
    88 	void save(ostream &str, OctreeNode *node = NULL) {};
    89 	void load(istream &str, OctreeNode *node = NULL) {};
    89 	void load(istream &str, OctreeNode *node = NULL) {};