ICT290 / src / ShaysWorld / collision.h
collision.h
Raw
//  collsion.h
//  Header file for the collision class
//
//
//  Shay Leary, March 2005
//--------------------------------------------------------------------------------------
#ifndef COLLISION_H
#define COLLISION_H

//--------------------------------------------------------------------------------------

#include "AABB.H"
#include "AABBLinkedList.h"

//--------------------------------------------------------------------------------------

class Collision {
   public:
    Collision() = default;

    // Privatised copy constructor and assignment operator
    Collision(const Collision&) = delete;
    Collision& operator=(const Collision&) = delete;

    // sets the actual world co-ordinates
    void SetWorldX(const double& tempX) { m_worldSizeX = tempX; }
    void SetWorldZ(const double& tempZ) { m_worldSizeZ = tempZ; }

    // returns number of bounding boxes
    size_t GetNoBoundingBoxes() { return m_AABB.GetNoBoundingBoxes(); }
    void AddBoundingBox() { m_AABB.AddBoundingBox(); }

    // returns TRUE if a collsion occurred
    bool Collide(double endX, double endY, double endZ);

    // reads the BB info from AABB (dynamic array) and creates a Linked List
    // containing BB data
    void CreateLinkedList();

    // initially stores BB info in AABB (dynamic array) before copying to Linked
    // List
    AABB m_AABB;

   private:
    // lists to store bounding box info in each quadrant
    AABBLinkedList m_list[4];

    // Stores the list size of each linked list
    // Set to 4 has the world is split into 4 quadrants
    int m_listSize[4];

    // stores world co-ordinates
    double m_worldSizeX;
    double m_worldSizeZ;

    // checks if collsion occurred (called from Collide)
    bool CheckCollision(int index, double endX, double endY, double endZ);
};

#endif
//--------------------------------------------------------------------------------------