ICT290 / src / ShaysWorld / camera.h
camera.h
Raw
//  camera.h
//  Header file for the camera class
//	Allows the camera to be navigated around the world.
//	Also sets Planes, Bounding Boxes and view Maps
//
//  Shay Leary, March 2005
//--------------------------------------------------------------------------------------
#ifndef CAMERA_H
#define CAMERA_H

#define PI 3.1415962654

#include "EasySound.h"
#include "PlaneLinkedList.h"
#include "cameraMap.h"
#include "collision.h"

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

class Camera {
   public:
    Camera();
    virtual ~Camera() = default;

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

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

    //----------------------------------------------------------------------------------
    //  Set Methods
    //----------------------------------------------------------------------------------
    // sets initial value for bounding boxes (in the array AABB)
    void SetAABBMaxX(const int& tempIndex, const GLdouble& tempX) {
        m_colDetect.m_AABB.SetMaxX(tempIndex, tempX);
    }
    void SetAABBMinX(const int& tempIndex, const GLdouble& tempX) {
        m_colDetect.m_AABB.SetMinX(tempIndex, tempX);
    }
    void SetAABBMaxY(const int& tempIndex, const GLdouble& tempY) {
        m_colDetect.m_AABB.SetMaxY(tempIndex, tempY);
    }
    void SetAABBMinY(const int& tempIndex, const GLdouble& tempY) {
        m_colDetect.m_AABB.SetMinY(tempIndex, tempY);
    }
    void SetAABBMaxZ(const int& tempIndex, const GLdouble& tempZ) {
        m_colDetect.m_AABB.SetMaxZ(tempIndex, tempZ);
    }
    void SetAABBMinZ(const int& tempIndex, const GLdouble& tempZ) {
        m_colDetect.m_AABB.SetMinZ(tempIndex, tempZ);
    }

    // set step and rotation size
    void SetRotateSpeed(const GLdouble& tempSpeed) {
        m_rotateSpeed = tempSpeed;
    }
    void SetMoveSpeed(const GLdouble& tempSpeed) { m_moveSpeed = tempSpeed; }

    // COLLSION DETECTION FUNCTIONS
    // set collision detection (TRUE = on)
    void SetCollisionDetectionOn(const bool& tempCol) {
        m_CollisionDetectionOn = tempCol;
    }

    // set the co-ordinates of the world
    void SetWorldCoordinates(const GLdouble& tempX, const GLdouble& tempZ);
    // creates a linked list for each quadrant of the world and places the
    // bounding box data in each.  Then clears and deletes AABB array.
    void InitiateBoundingBoxes() { m_colDetect.CreateLinkedList(); }

    // sets the co-ordinate of each plain
    void SetPlanes(const int tempType,
                   const GLdouble tempXs,
                   const GLdouble tempXe,
                   const GLdouble tempYs,
                   const GLdouble tempYe,
                   const GLdouble tempZs,
                   const GLdouble tempZe);

    //----------------------------------------------------------------------------------
    //  Get Methods
    //----------------------------------------------------------------------------------
    GLdouble GetLR() { return m_x; }
    GLdouble GetUD() { return m_y; }
    GLdouble GetFB() { return m_z; }
    void AddBoundingBox() { m_colDetect.AddBoundingBox(); }
    GLdouble GetAABBMaxX(const int& tempIndex) const {
        return m_colDetect.m_AABB.GetMaxX(tempIndex);
    }
    GLdouble GetAABBMinX(const int& tempIndex) const {
        return m_colDetect.m_AABB.GetMinX(tempIndex);
    }
    GLdouble GetAABBMaxY(const int& tempIndex) const {
        return m_colDetect.m_AABB.GetMaxY(tempIndex);
    }
    GLdouble GetAABBMinY(const int& tempIndex) const {
        return m_colDetect.m_AABB.GetMinY(tempIndex);
    }
    GLdouble GetAABBMaxZ(const int& tempIndex) const {
        return m_colDetect.m_AABB.GetMaxZ(tempIndex);
    }
    GLdouble GetAABBMinZ(const int& tempIndex) const {
        return m_colDetect.m_AABB.GetMinZ(tempIndex);
    }

    // position the camera
    void Position(GLdouble const& tempX,
                  GLdouble const& tempY,
                  GLdouble const& tempZ,
                  GLdouble const& tempAngle);

    // check whether ok to move
    void CheckCamera();

    // Used to pass direction to move or rotate  (i.e. 1, -1 or 0)
    void DirectionLR(int const& tempMove);
    void DirectionLookUD(int const& tempMove);

    // display map
    void DisplayMap(const int& screenWidth,
                    const int& screenHeight,
                    const GLuint& tempImage);
    // display welcome screen
    void DisplayWelcomeScreen(const int& screenWidth,
                              const int& screenHeight,
                              const int& tempExit,
                              const GLuint& tempImage);
    // display no exit
    void DisplayNoExit(const int& screenWidth,
                       const int& screenHeight,
                       const GLuint& tempImage);

    Collision m_colDetect;

    // overloaded function for setting plain
    void SetPlanes(const float& moveX, const float& moveZ);

   private:
    // steep incline increments
    GLdouble m_incrementX;
    GLdouble m_incrementZ;
    int m_No_Planes = 0;
    int m_plainNo = 0;
    GLdouble m_plainHeight;

    // rotation variables
    GLdouble m_rotateAngleLR = 0.0;
    GLdouble m_deltaAngleLR = 0.0;
    GLdouble m_rotateAngleUD = 0.0;
    GLdouble m_deltaAngleUD = 0.0;

    // movement variables
    GLdouble m_x, m_y, m_z, m_zLast, m_xLast;
    GLdouble m_lookX, m_lookY, m_lookZ;
    GLdouble m_lookXX, m_lookYY, m_lookZZ;
    GLdouble m_deltaMoveLR = 0;
    GLdouble m_deltaMoveFB = 0;
    GLdouble m_deltaMoveUD = 0;

    // movement speed (step size)
    GLdouble m_rotateSpeed = 0.0f;
    GLdouble m_moveSpeed = 0.0f;

    // resets camera
    void ResetXYZ();
    // display new view
    void callGLLookAt();

    bool m_CollisionDetectionOn = true;

    // objects
    CameraMap m_map;
    PlaneLinkedList m_Plain;

    // CEasySound* es;
    // CSound* stepSound;
};

#endif