[Player] No longer holds gk::Camera, ownership moved to GameState.

This commit is contained in:
Quentin Bazin 2018-12-30 04:32:29 +01:00
parent e76051ed90
commit de62bcb413
4 changed files with 9 additions and 7 deletions

View File

@ -19,6 +19,7 @@
#include <gk/core/ApplicationState.hpp>
#include <gk/gl/RenderTarget.hpp>
#include "Config.hpp"
#include "HUD.hpp"
#include "Player.hpp"
#include "Skybox.hpp"
@ -46,7 +47,8 @@ class GameState : public gk::ApplicationState {
Skybox m_skybox;
World m_world;
Player m_player;
gk::Camera m_camera{45.0f, DIST_NEAR, DIST_FAR};
Player m_player{m_camera};
HUD m_hud{m_player, m_world, m_viewMatrix, m_orthoMatrix};
};

View File

@ -34,7 +34,7 @@ class World;
class Player {
public:
Player();
Player(gk::Camera &camera);
void turnH(float angle);
void turnV(float angle);
@ -64,7 +64,7 @@ class Player {
static Player *s_instance;
gk::Camera m_camera{45.0f, 0.1f, 1000.0f};
gk::Camera &m_camera;
float m_x;
float m_y;

View File

@ -22,7 +22,6 @@
#include <gk/gl/OpenGL.hpp>
#include <gk/system/GameClock.hpp>
#include "Config.hpp"
#include "GameKey.hpp"
#include "GameState.hpp"
#include "InventoryState.hpp"
@ -31,9 +30,10 @@
#include "ScriptEngine.hpp"
GameState::GameState() {
m_perspectiveMatrix = glm::perspective(45.0f, (float)SCREEN_WIDTH / SCREEN_HEIGHT, DIST_NEAR, DIST_FAR);
m_orthoMatrix = glm::ortho(0.0f, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT, 0.0f);
m_camera.setAspectRatio((float)SCREEN_WIDTH / SCREEN_HEIGHT);
try {
auto &lua = ScriptEngine::getInstance().lua();
lua["player"] = &m_player;
@ -109,7 +109,7 @@ void GameState::initShaders() {
void GameState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
states.shader = &m_shader;
states.projectionMatrix = m_perspectiveMatrix;
states.projectionMatrix = m_camera.getProjectionMatrix();
states.viewMatrix = m_viewMatrix;
target.draw(m_world, states);

View File

@ -22,7 +22,7 @@
Player *Player::s_instance = nullptr;
Player::Player() {
Player::Player(gk::Camera &camera) : m_camera(camera) {
m_x = 0;
m_y = 18;
m_z = 20;