Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ void OttApplication::mainLoop()
//----------------------------------------------------------------------------
void OttApplication::drawFrame()
{
if (viewportCamera->getRenderState() == false)
return;
if (static_cast<float>(appSwapChain.width()) > 0.0f && static_cast<float>(appSwapChain.height()) > 0.0f)
{
const auto startTime = std::chrono::high_resolution_clock::now();
Expand Down
4 changes: 4 additions & 0 deletions lib/camera.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdexcept>
#include <fmt/core.h>
#include "macros.h"
#include "camera_param_component.h"

#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
Expand Down Expand Up @@ -92,7 +93,10 @@ void OttCamera::viewportInputHandle(float deltaTime)
rotateFixedAmount(rotateDirection::RD_DOWN);

if (Input::isKeyDown(windowHandle, GLFW_KEY_KP_0))
{
resetToInitialPos();
render = false;
}

if (Input::isKeyDown(windowHandle, GLFW_KEY_KP_1))
Input::isKeyDownRepeat(windowHandle, GLFW_KEY_LEFT_CONTROL) ?
Expand Down
3 changes: 3 additions & 0 deletions lib/camera_system.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "camera_system.h"
#include "camera_param_component.h"
#include "camera_pos_component.h"
3 changes: 3 additions & 0 deletions lib/include/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class OttCamera
// "Redundant" name for it not to be mistaken with the world rightVector.
glm::vec3 getCameraRightVector() const { return glm::cross(forwardDirection, upVector); }
glm::mat4 getViewMatrix() const { return ViewMatrix; }

bool getRenderState() const { return render; }

//----------------------------------------------------------------------------
private:
Expand All @@ -68,6 +70,7 @@ class OttCamera
float rotationSpeed = 0.3f;
bool walkNavigation = false;
bool perspective = true;
bool render = true;

glm::vec2 lastMousePosition{ 0.0f, 0.0f };

Expand Down
31 changes: 31 additions & 0 deletions lib/include/camera_param_component.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Ottocento Engine. Architectural BIM Engine.
// Copyright (C) 2024 Lucas M. Faria.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#pragma once

struct OttCameraParametersComponent
{
double resetAnimationStart = 0.;
double orbitAnimationStart{0.};

float VerticalFOV{38.0f};
float NearClip{0.1f};
float FarClip{1000.0f};
float speed{2.0f};
float orthoZoomFactor{10.f};
float rotationSpeed{0.3f};
};

31 changes: 31 additions & 0 deletions lib/include/camera_pos_component.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Ottocento Engine. Architectural BIM Engine.
// Copyright (C) 2024 Lucas M. Faria.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#pragma once

struct OttCameraPositionComponent
{
glm::vec2 lastMousePosition{ 0.0f, 0.0f };

glm::vec3 CenterPosition{0.0f, 0.0f, 0.0f};

glm::vec3 EyePosition{5.0f, -5.0f, 5.0f};
glm::vec3 startEye, startCenter, targetEyePosition, targetCenterPosition;

glm::vec3 rightVector{0.0f, 0.0f, 0.0f};
glm::vec3 upVector{0.0f, 0.0f, 1.0f};
glm::vec3 forwardDirection{};
};
78 changes: 78 additions & 0 deletions lib/include/camera_system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Ottocento Engine. Architectural BIM Engine.
// Copyright (C) 2024 Lucas M. Faria.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#define GLM_ENABLE_EXPERIMENTAL

#include "window.h"
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

struct OttCameraSystem
{
//----------------------------------------------------------------------------
glm::mat4 recalculateView(float deltaTime);

//----------------------------------------------------------------------------
// Projection and Direction functions
//----------------------------------------------------------------------------
enum struct ViewType
{
VT_FRONT,
VT_BACK,
VT_RIGHT,
VT_LEFT,
VT_TOP,
VT_BOTTOM,
VT_ISOMETRIC,
VT_INVERT_ISOMETRIC
};

enum struct rotateDirection
{
RD_RIGHT,
RD_LEFT,
RD_UP,
RD_DOWN
};

glm::mat4 projection(float height, float width) const;
glm::mat4 inverseProjection(glm::mat4 perspectiveProjection, glm::mat4 view);

//----------------------------------------------------------------------------
glm::vec3 SetViewOrbit(ViewType view);
void viewportInputHandle(float deltaTime);
void walkNavigationInputHandle(float deltaTime);
void rotateFixedAmount(rotateDirection direction);
void resetToInitialPos();
void orbitStartAnimation(ViewType view);
void animateResetUpdate();
void wrapAroundMousePos(glm::vec2& mousePos);

//----------------------------------------------------------------------------
void moveUpDirection(float deltaTime);
void moveDownDirection(float deltaTime);
void moveForward(float deltaTime);
void moveBack(float deltaTime);
void moveRightDirection(float deltaTime);
void moveLeftDirection(float deltaTime);
void zoomIn(double yoffset);
void zoomOut(double yoffset);
}; // class OttCameraSystem
Loading