#ifndef ACCELERATOR_H #define ACCELERATOR_H #include #include "RigidBody.h" // need to include eric's vector libraries struct boxIndex { int x; int y; int z; }; class Accelerator { /* Acceleration class for a group of objects in space. Will allow access to the objects and a "get closest" option that will return all objects. Contains RigidBodies indexed from 0 to Size() */ //-------------------- Public methods ----------------------------- public: Accelerator(); //Don't use this, it's just to stop C++ from bitching. Accelerator(Vec3f min, Vec3f max, Vec3f resolution); // creates an empty accelerator with bounding box from min to max, and number of boxes resolution.xyz /* requires: min.x < max.x min.y < max.y min.z < max.z resolution.* != 0 */ ~Accelerator(); // Deletes grid int* GetClosest(int bodyNumber, int & size); // Returns a vector of pointers to the RigidBody objects closest to the body at bodyNumber // vector GetClosest(RigidBody * body); // Returns a vector of pointers to the RigidBody objects closest to *body // currently deprecated because this seems like a pain to do RigidBody& operator [](int bodyNumber); // Returns a reference to the RigidBody at index i void Add(RigidBody & body); // Adds body to the container void Update(); // Updates the acceleration structure to match the current locations of the RigidBodies void GetBounds(Vec3f &min, Vec3f &max); // gets the world bounds of the acceleration structure int Size(); // returns the number of RigidBodies in the Accelerator private: /*-------------------- Private members -----------------*/ vector bodies; // The actual container for all the bodies float xMax, yMax, zMax, xMin, yMin, zMin; // Defines the bounding box of the acceleration structure. float xWidth, yWidth, zWidth; // Width in all directions of the boxes in the grid float xRes, yRes, zRes; // number of boxes in each direction vector * grid; /* grid is a large list of pointers to vectors of integers. The way this structure works (hopefully). Grid is initialized to an array of vector's of size xRes*yRes*zRes. indexing in by x*(yRes*zRes)+ y*(zRez) + z gives you the vector representing the grid box at (x,y,z). This contains a list of integers which are the indices in bodies of all the RigidBodies that are in that box. */ vector> bodyBoxMap; // contains lists of all the boxes in which a body resides // bodyBoxMap[i] corresponds to the boxes which surround bodies[i] /*---------------- Private methods --------------------------*/ vector* GetBox(boxIndex i); // get the box with position boxIndex void UpdateOne(int bodyNumber); // Updates grid to reflex bodies[bodyNumber]'s current position };