Skip to content

Commit

Permalink
Added camera supporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriiKoniushenko committed Oct 14, 2023
1 parent e80915a commit 38bf4a4
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_subdirectory(lib/glm)
add_subdirectory(lib/misc)

add_subdirectory(lib/core/animations)
add_subdirectory(lib/core/camera)
add_subdirectory(lib/core/core-wrappers)
add_subdirectory(lib/core/delegate)
add_subdirectory(lib/core/freetype-wrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include "Camera.hpp"
#include "Configuring.hpp"
#include "Shooting.hpp"


#include "../../../../../../lib/core/camera/include/Camera.h"

//////////////////////////////////////////////////////////////////////////////
NotShooting::NotShooting()
Expand Down
24 changes: 24 additions & 0 deletions lib/core/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
file(
GLOB Sources
"include/*.h"
"source/*.cpp"
)

add_library(
Camera STATIC
${Sources}
)

target_include_directories(
Camera PUBLIC
include
)

target_link_libraries(
Camera PUBLIC
glfw
Glad
Utils
Glm
Core-Wrappers
)
48 changes: 48 additions & 0 deletions lib/core/camera/include/Camera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// MIT License
//
// Copyright (c) 2023 Valerii Koniushenko
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#include "CopyableAndMoveable.h"
#include "Size.h"
#include "glm/glm.hpp"
#include "Updateable.h"

class Camera : public Utils::CopyableAndMoveable, public Updateable
{
public:
void setSize(const Utils::ISize2D& size);
[[nodiscard]] const Utils::ISize2D& getSize() const;

void setPosition(const glm::ivec2& position);
void move(const glm::ivec2& offset);
[[nodiscard]] const glm::ivec2& getPosition() const;

void update() override;

void zoom(float factor);

private:
Utils::ISize2D size_;
glm::ivec2 position_{};
float zoomFactor_ = 1.f;
};
59 changes: 59 additions & 0 deletions lib/core/camera/source/Camera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// MIT License
//
// Copyright (c) 2023 Valerii Koniushenko
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "Camera.h"
#include "Window.h"

void Camera::setSize(const Utils::ISize2D& size)
{
size_ = size;
}

const Utils::ISize2D& Camera::getSize() const
{
return size_;
}

void Camera::setPosition(const glm::ivec2& position)
{
position_ = position;
}

void Camera::move(const glm::ivec2& offset)
{
position_ += offset;
}

const glm::ivec2& Camera::getPosition() const
{
return position_;
}

void Camera::update()
{
GetWindow().viewport(-position_.x, position_.y, size_.width * zoomFactor_, size_.height * zoomFactor_);
}

void Camera::zoom(float factor)
{
zoomFactor_ = factor;
}

0 comments on commit 38bf4a4

Please sign in to comment.