Skip to content

Commit

Permalink
camera limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Apr 19, 2024
1 parent 93b42a9 commit d053f03
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 29 deletions.
7 changes: 4 additions & 3 deletions include/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ constexpr float FOV_LOWER_LIMIT = 1.F;
class CameraClass {
public:
CameraClass() { setPosition(glm::vec2(0, 0)); }
CameraClass(glm::vec2 position) { setPosition(position); }
~CameraClass() {}

static float getCameraZoom() { return m_Zoom; }
Expand All @@ -24,7 +23,7 @@ class CameraClass {

static glm::vec2 getPosition() { return m_Position; }

void setPosition(glm::vec2 position) { m_Position = position; }
void setPosition(glm::vec2 position);

static glm::mat4x4 getProjectionMatrix() {

Expand All @@ -47,7 +46,7 @@ class CameraClass {
float getZoomingSpeed() { return m_ZoomingSpeed; }
void changeFOV(float offset);

void Start();
void Start(glm::vec2 minPosition, glm::vec2 maxPosition);
void Update();
void UpdateWhenCursorAtBoarder();
void UpdateWhenCursorScroll();
Expand All @@ -60,6 +59,8 @@ class CameraClass {
static float m_Fov;
static glm::vec2 s_boarderMaximum;
static glm::vec2 s_boarderMinimum;
glm::vec2 m_minPosition;
glm::vec2 m_maxPosition;
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_CAMERA_HPP
12 changes: 1 addition & 11 deletions include/Cursor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CursorClass {
DrawOverlays::OverlayShapes::R_CROSS);
}
~CursorClass() {}
void Start(std::shared_ptr<MapClass> map) { m_Map = map; }
void Start() {}
void Update(std::shared_ptr<TileClass> tile) {

if (m_showWalkable) {
Expand Down Expand Up @@ -63,16 +63,6 @@ class CursorClass {
}
}

std::vector<glm::vec2> getCursorSelectionRegionInCell() {
std::vector<glm::vec2> region = {

MapUtil::GlobalCoordToCellCoord(
glm::vec2(start_pos.x, start_pos.y)),
MapUtil::GlobalCoordToCellCoord(glm::vec2(end_pos.x, end_pos.y))};

return region;
}

void setShowWalkable(bool value) { m_showWalkable = value; }
void setShowBuildable(bool value) { m_showBuildable = value; }

Expand Down
8 changes: 0 additions & 8 deletions include/Mechanics/GameObjectManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ class GameObjectManager {
}
}

static bool ifObjectClicked(glm::vec2 objpos, glm::vec2 objsize,
glm::vec2 mousestart, glm::vec2 mouseend) {
mousestart = MapUtil::GlobalCoordToCellCoord(mousestart);
mouseend = MapUtil::GlobalCoordToCellCoord(mouseend);
objpos = MapUtil::GlobalCoordToCellCoord(objpos);
return (mousestart == objpos);
}

void Append(std::shared_ptr<Structure> newstruct) {
m_BuiltStructure.push_back(newstruct);
m_Map->AppendSelectableObjectByCellPosition(
Expand Down
3 changes: 2 additions & 1 deletion include/Scene/DefaultScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_DEFAULTSCENE_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_DEFAULTSCENE_HPP

#include "Cursor.hpp"
#include "Scene.hpp"
#include "Unit/Avatar.hpp"
#include "Unit/Hunter.hpp"
#include "Unit/Runner.hpp"
#include <glm/glm.hpp>

class DefaultScene : public Scene {

public:
Expand Down
5 changes: 1 addition & 4 deletions include/Scene/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ class Scene {
*/
virtual void Update() = 0;

CameraClass getCamera() { return m_SceneCamera; };

protected:
CameraClass m_SceneCamera;
std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();

CameraClass m_SceneCamera;
std::shared_ptr<GameObjectManager> m_GameObjectManager =
std::make_shared<GameObjectManager>();
Util::Renderer m_Renderer;
Expand Down
14 changes: 13 additions & 1 deletion src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ glm::vec2 CameraClass::m_Position(glm::vec2(0, 0));
float CameraClass::m_Zoom = 1.F;
float CameraClass::m_Fov = FOV_UPPER_LIMIT;

void CameraClass::Start() {}
void CameraClass::Start(glm::vec2 minPosition, glm::vec2 maxPosition) {
m_minPosition = minPosition;
m_maxPosition = maxPosition;
}

void CameraClass::Update() {
UpdateWhenCursorAtBoarder();
UpdateWhenCursorScroll();
}

void CameraClass::setPosition(glm::vec2 position) {
if (position.x >= m_minPosition.x && position.x <= m_maxPosition.x) {
m_Position.x = position.x;
}
if (position.y >= m_minPosition.y && position.y <= m_maxPosition.y) {
m_Position.y = position.y;
}
}

void CameraClass::UpdateWhenCursorAtBoarder() {
// TODO: where to put is cursor at boarder??
int cursorAtBoarder = Core::Context::IsCurosrAtBoarder();
Expand Down
2 changes: 2 additions & 0 deletions src/Scene/DefaultScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void DefaultScene::Start() {
// m_Cursor.Start(m_Map);
m_UI.Start(m_Map, m_Player, m_GameObjectManager);
m_Player->setTotalCurrency(5000);
m_SceneCamera.Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)),
MapUtil::CellCoordToGlobal(glm::vec2(100, 100)));

// m_hunter->setCurrentCell({20,10});
// m_runner->setCurrentCell({10,10});
Expand Down
3 changes: 2 additions & 1 deletion src/Scene/MapScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "DrawOverlays.hpp"
#include <iostream>
void MapScene::Start() {
// m_Map->Init(204, 161);
m_Map->Init(
MapBinReader::readBin("../assets/map/green-belt/map.bin", 98, 98), 98,
98);
m_SceneCamera.Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)),
MapUtil::CellCoordToGlobal(glm::vec2(98, 98)));
}

void MapScene::Update() {
Expand Down

0 comments on commit d053f03

Please sign in to comment.