ICT290 / src / ShaysWorld / camera.cpp
camera.cpp
Raw
//  camera.cpp
//
//  Implementation file for Camera Class
//  Defines all the methods declared, but not defined, in camera.h
//
//  Shay Leary, March 2005
//--------------------------------------------------------------------------------------

#include "camera.h"
#include <cmath>

//--------------------------------------------------------------------------------------
// Set initial values
//--------------------------------------------------------------------------------------
Camera::Camera() {
    ResetXYZ();

    // sound objects
    // es = CEasySound::Instance();
    // stepSound =
    // es->GetSound(es->Load("../res/ShaysWorldData/sounds/step.wav"));
}

//--------------------------------------------------------------------------------------
// Reset camera values
//--------------------------------------------------------------------------------------
void Camera::ResetXYZ() {
    m_x = 0.0f;
    m_y = 1.75f;
    m_z = 0.0f;

    m_lookX = 0.0f;
    m_lookY = 0.0f;
    m_lookZ = -1.0f;

    m_lookXX = 1.0f;
    m_lookYY = 1.0f;
    m_lookZZ = 0.0f;
}

//--------------------------------------------------------------------------------------
void Camera::DirectionLR(int const& tempMove) {
    m_deltaMoveLR = tempMove;
}

//--------------------------------------------------------------------------------------
void Camera::DirectionLookUD(int const& tempMove) {
    m_deltaAngleUD = tempMove * m_rotateSpeed;
}

//----------------------------------------------------------------------------------------
//  Places camera at the correct level on the current plane
//----------------------------------------------------------------------------------------
void Camera::SetPlanes(const float& moveX, const float& moveZ) {
    // store number of planes (stops from looping through linked list each time)
    if (m_No_Planes == 0)
        m_No_Planes = m_Plain.GetListSize();

    for (int i = 0; i < m_No_Planes; i++) {
        // if camera is positioned on a plain
        if ((m_z <= m_Plain.GetZend(i)) && (m_z >= m_Plain.GetZstart(i))
            && (m_x <= m_Plain.GetXend(i)) && (m_x >= m_Plain.GetXstart(i))) {
            // if flat plain
            if (m_Plain.GetType(i) == 0) {
                m_y = m_Plain.GetYstart(i);

                if ((m_plainNo != i) && m_plainHeight != m_Plain.GetYstart(i)) {
                    // stepSound->Play();
                }

                m_plainNo = i;
                m_plainHeight = m_Plain.GetYstart(i);
            }
            // if plain slopes in z direction
            if (m_Plain.GetType(i) == 2) {
                // if plain slopes up or down
                if (m_zLast > m_z) {
                    m_incrementZ = ((m_y - m_Plain.GetYstart(i))
                                    / (m_z - m_Plain.GetZstart(i)));
                } else {
                    m_incrementZ = ((m_Plain.GetYend(i) - m_y)
                                    / (m_Plain.GetZend(i) - m_z));
                }
                m_y += m_incrementZ * moveZ;
            }
            // if plain slopes in x direction
            if (m_Plain.GetType(i) == 1) {
                // if plain slopes up or down
                if (m_xLast > m_x) {
                    m_incrementX = ((m_y - m_Plain.GetYstart(i))
                                    / (m_x - m_Plain.GetXstart(i)));
                } else {
                    m_incrementX = ((m_Plain.GetYend(i) - m_y)
                                    / (m_Plain.GetXend(i) - m_x));
                }
                m_y += m_incrementX * moveX;
            }
        }
    }
}

//----------------------------------------------------------------------------------------
// Positions camera at co-ordinates of parameters
//----------------------------------------------------------------------------------------
void Camera::Position(GLdouble const& tempX,
                      GLdouble const& tempY,
                      GLdouble const& tempZ,
                      GLdouble const&) {
    m_xLast = m_x;
    m_zLast = m_z;
    m_x = tempX;
    m_y = tempY;
    m_z = tempZ;

    // rotate to correct angle
    // m_rotateAngleLR = tempAngle * (PI / 180);
    // m_lookX = sin(m_rotateAngleLR);
    // m_lookZ = -cos(m_rotateAngleLR);
    // m_lookXX = sin(m_rotateAngleLR + (float)PI / 2.0);
    // m_lookZZ = -cos(m_rotateAngleLR + (float)PI / 2.0);
    // m_rotateAngleUD = 0.0;
    // m_deltaAngleUD = 0.0;

    // redislay
    // callGLLookAt();
}

//----------------------------------------------------------------------------------------
//  Redisplay new camera view
//----------------------------------------------------------------------------------------
void Camera::callGLLookAt() {}

//--------------------------------------------------------------------------------------
// Display map of world
//----------------------------------------------------------------------------------------

void Camera::DisplayMap(const int& screenWidth,
                        const int& screenHeight,
                        const GLuint& tempImage) {
    m_map.DisplayMap(screenWidth, screenHeight, GetLR(), GetFB(), tempImage);
}

//--------------------------------------------------------------------------------------
// Display welcome or exit page
//----------------------------------------------------------------------------------------

void Camera::DisplayWelcomeScreen(const int& screenWidth,
                                  const int& screenHeight,
                                  const int& tempExit,
                                  const GLuint& tempImage) {
    m_map.DisplayWelcomeScreen(screenWidth, screenHeight, tempExit, tempImage);
}

//--------------------------------------------------------------------------------------
// Display welcome or exit page
//----------------------------------------------------------------------------------------

void Camera::DisplayNoExit(const int& screenWidth,
                           const int& screenHeight,
                           const GLuint& tempImage) {
    m_map.DisplayNoExit(screenWidth, screenHeight, tempImage);
}

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

void Camera::SetWorldCoordinates(const GLdouble& tempX, const GLdouble& tempZ) {
    m_colDetect.SetWorldX(tempX);
    m_colDetect.SetWorldZ(tempZ);
}

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

void Camera::SetPlanes(const int tempType,
                       const GLdouble tempXs,
                       const GLdouble tempXe,
                       const GLdouble tempYs,
                       const GLdouble tempYe,
                       const GLdouble tempZs,
                       const GLdouble tempZe) {
    m_Plain
        .AddToStart(tempType, tempXs, tempXe, tempYs, tempYe, tempZs, tempZe);
}