/**
 * Skript reprezentujici datovou strukturu Octree pouzitou pro efektivnejsi prochazeni objektu ve scene.
 */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/**
 * Author:			Karel Zavrel
 * 
 * Thesis:			An interactive application for development of creativity
 * Application:		Little Builder
 */
public class MyOctree {
	/**
	 * promenne:
	 * 	- instance teto datove strktury
	 * 	- korenovy uzel stromu
	 */
	private static MyOctree myOctree;
	private MyOctreeNode rootNode;
	/**
	 * soukromy konstruktor
	 */
	private MyOctree(){
		rootNode = new MyOctreeNode (new Bounds (Vector3.zero, new Vector3 (64.0f, 64.0f, 64.0f)), null);
	}
	/**
	 * funkce pro ziskani instance stromu - Singleton
	 */
	public static MyOctree getInstance(){
		if (myOctree == null) {
			myOctree = new MyOctree ();
		}
		return myOctree;
	}
	/**
	 * funkce, ktera zkontroluje, zda je objekt v zakladnim vyhranicenem prostoru
	 */
	public bool intersectsWithRoot(Bounds bounds){
		return rootNode.getBoundsOfNode ().Intersects (bounds);
	}
	/**
	 * funkce pro vlozeni kosticky do stromu
	 */
	public bool addBrickToOctree(GameObject brick, Bounds bounds){
		return rootNode.addBrickToOctree (brick, bounds);
	}
	/**
	 * funkce, ktera odstrani kosticku ze stromu
	 */
	public bool removeBrickFromOctree(GameObject brick, Bounds bounds){
		return rootNode.removeBrickFromOctree (brick, bounds);
	}
	/**
	 * funkce pro kontrolu kolize s paprskem
	 */
	public bool checkCollisions(Ray ray){
		return rootNode.checkCollisions (ray);
	}
	/**
	 * funkce na vymazani obsahu celeho stromu
	 */
	public bool cleanTree(List<GameObject> allB, List<Bounds> allBB){
		return rootNode.cleanTree (allB, allBB);
	}
}