From 9b5cc10c1a8ae593cd74722c6865be80e713a08e Mon Sep 17 00:00:00 2001 From: Warwick Date: Wed, 12 Jan 2022 15:43:10 +0000 Subject: [PATCH] added glm and template for a player camera --- CMakeLists.txt | 3 +++ cmake/FindGLM.cmake | 63 +++++++++++++++++++++++++++++++++++++++++++ src/PlayerCamera.cpp | 12 +++++++++ src/PlayerCamera.h | 35 ++++++++++++++++++++++++ src/helpers/RootDir.h | 2 ++ 5 files changed, 115 insertions(+) create mode 100644 cmake/FindGLM.cmake create mode 100644 src/PlayerCamera.cpp create mode 100644 src/PlayerCamera.h create mode 100644 src/helpers/RootDir.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d8db254..764ade4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ find_package(SDL2_image REQUIRED) find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) +find_package(GLM REQUIRED) +message(STATUS "GLM included: ${GLM_INCLUDE_DIR}") + include_directories( ${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_DIRS} diff --git a/cmake/FindGLM.cmake b/cmake/FindGLM.cmake new file mode 100644 index 0000000..2d90092 --- /dev/null +++ b/cmake/FindGLM.cmake @@ -0,0 +1,63 @@ +# FindGLM - attempts to locate the glm matrix/vector library. +# +# This module defines the following variables (on success): +# GLM_INCLUDE_DIRS - where to find glm/glm.hpp +# GLM_FOUND - if the library was successfully located +# +# It is trying a few standard installation locations, but can be customized +# with the following variables: +# GLM_ROOT_DIR - root directory of a glm installation +# Headers are expected to be found in either: +# /glm/glm.hpp OR +# /include/glm/glm.hpp +# This variable can either be a cmake or environment +# variable. Note however that changing the value +# of the environment varible will NOT result in +# re-running the header search and therefore NOT +# adjust the variables set by this module. + +#============================================================================= +# Copyright 2012 Carsten Neumann +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# default search dirs +SET(_glm_HEADER_SEARCH_DIRS + "/usr/include" + "/usr/local/include") + +# check environment variable +SET(_glm_ENV_ROOT_DIR "$ENV{GLM_ROOT_DIR}") + +IF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) + SET(GLM_ROOT_DIR "${_glm_ENV_ROOT_DIR}") +ENDIF(NOT GLM_ROOT_DIR AND _glm_ENV_ROOT_DIR) + +# put user specified location at beginning of search +IF(GLM_ROOT_DIR) + SET(_glm_HEADER_SEARCH_DIRS "${GLM_ROOT_DIR}" + "${GLM_ROOT_DIR}/include" + ${_glm_HEADER_SEARCH_DIRS}) +ENDIF(GLM_ROOT_DIR) + +# locate header +FIND_PATH(GLM_INCLUDE_DIR "glm/glm.hpp" + PATHS ${_glm_HEADER_SEARCH_DIRS}) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLM DEFAULT_MSG + GLM_INCLUDE_DIR) + +IF(GLM_FOUND) + SET(GLM_INCLUDE_DIRS "${GLM_INCLUDE_DIR}") + + MESSAGE(STATUS "GLM_INCLUDE_DIR = ${GLM_INCLUDE_DIR}") +ENDIF(GLM_FOUND) diff --git a/src/PlayerCamera.cpp b/src/PlayerCamera.cpp new file mode 100644 index 0000000..a9ddde5 --- /dev/null +++ b/src/PlayerCamera.cpp @@ -0,0 +1,12 @@ +#include "PlayerCamera.h" + +PlayerCamera::PlayerCamera() { + SDL_SetRelativeMouseMode(SDL_TRUE); + SDL_GetRelativeMouseState(nullptr, nullptr); +} + +PlayerCamera::~PlayerCamera() {} + +void PlayerCamera::tick() {} + +glm::mat4 PlayerCamera::getMVP() {} diff --git a/src/PlayerCamera.h b/src/PlayerCamera.h new file mode 100644 index 0000000..e6e88bf --- /dev/null +++ b/src/PlayerCamera.h @@ -0,0 +1,35 @@ +#pragma once +#include +#include +#include +#include +#include + +class PlayerCamera { +private: + // Constants for speed and sensitivity + const float movementSpeed = 0.05f; + const float mouseSensitivity = 0.05f; + + // Player position + struct position { + glm::vec4 location; + float pitch; + float yaw; + }; + + // Mouse position + int mouseX, mouseY; + + // Camera position + glm::mat4 MVP; + +public: + PlayerCamera(); + + ~PlayerCamera(); + + void tick(); + + glm::mat4 getMVP(); +}; diff --git a/src/helpers/RootDir.h b/src/helpers/RootDir.h new file mode 100644 index 0000000..415955a --- /dev/null +++ b/src/helpers/RootDir.h @@ -0,0 +1,2 @@ +#pragma once +#define ROOT_DIR "/"