editor camera!
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "open_engine/imgui/imgui_layer.hpp"
|
||||
#include "open_engine/events/key_event.hpp"
|
||||
#include "open_engine/application.hpp"
|
||||
#include "open_engine/math/math.hpp"
|
||||
#include "open_engine/ref_scope.hpp"
|
||||
#include "open_engine/logging.hpp"
|
||||
|
||||
|
||||
69
open_engine/include/open_engine/renderer/editor_camera.hpp
Normal file
69
open_engine/include/open_engine/renderer/editor_camera.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef EDITOR_CAMERA_HPP
|
||||
#define EDITOR_CAMERA_HPP
|
||||
|
||||
#include "camera.hpp"
|
||||
#include "open_engine/events/event.hpp"
|
||||
#include "open_engine/events/mouse_event.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
class EditorCamera : public OpenEngine::Camera
|
||||
{
|
||||
public:
|
||||
EditorCamera() = default;
|
||||
EditorCamera(float fov, float aspect_ratio, float near_clip, float far_clip);
|
||||
|
||||
void OnUpdate();
|
||||
void OnEvent(Event& e);
|
||||
|
||||
inline float GetDistance() const { return distance; }
|
||||
inline void SetDistance(float _distance) { distance = _distance; }
|
||||
|
||||
inline void SetViewportSize(float width, float height) { viewport_width = width; viewport_height = height; UpdateProjection(); }
|
||||
|
||||
const glm::mat4& GetViewMatrix() const { return view_matrix; }
|
||||
glm::mat4 GetViewProjection() const { return projection * view_matrix; }
|
||||
|
||||
glm::vec3 GetUpDirection() const;
|
||||
glm::vec3 GetRightDirection() const;
|
||||
glm::vec3 GetForwardDirection() const;
|
||||
const glm::vec3& GetPosition() const { return position; }
|
||||
glm::quat GetOrientation() const;
|
||||
|
||||
float GetPitch() const { return pitch; }
|
||||
float GetYaw() const { return yaw; }
|
||||
private:
|
||||
void UpdateProjection();
|
||||
void UpdateView();
|
||||
|
||||
bool OnMouseScroll(MouseScrolledEvent& e);
|
||||
|
||||
void MousePan(const glm::vec2& delta);
|
||||
void MouseRotate(const glm::vec2& delta);
|
||||
void MouseZoom(float delta);
|
||||
|
||||
glm::vec3 CalculatePosition() const;
|
||||
|
||||
std::pair<float, float> PanSpeed() const;
|
||||
float RotationSpeed() const;
|
||||
float ZoomSpeed() const;
|
||||
private:
|
||||
float fov = 45.0f, aspect_ratio = 1.778f, near_clip = 0.1f, far_clip = 1000.0f;
|
||||
|
||||
glm::mat4 view_matrix;
|
||||
glm::vec3 position = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 focal_point = { 0.0f, 0.0f, 0.0f };
|
||||
|
||||
glm::vec2 initial_mouse_position = { 0.0f, 0.0f };
|
||||
|
||||
float distance = 10.0f;
|
||||
float pitch = 0.0f, yaw = 0.0f;
|
||||
|
||||
float viewport_width = 1280, viewport_height = 720;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // EDITOR_CAMERA_HPP
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef RENDERER2D_HPP
|
||||
#define RENDERER2D_HPP
|
||||
|
||||
#include "open_engine/renderer/editor_camera.hpp"
|
||||
#include "open_engine/renderer/subtexture2d.hpp"
|
||||
#include "open_engine/orthographic_camera.hpp"
|
||||
#include "open_engine/renderer/texture.hpp"
|
||||
@@ -22,8 +23,8 @@ namespace OpenEngine {
|
||||
uint32_t draw_calls = 0;
|
||||
uint32_t quad_count = 0;
|
||||
|
||||
uint32_t GetToralVertexCount() { return quad_count * 4; };
|
||||
uint32_t GetToralIndexCount() { return quad_count * 6; };
|
||||
uint32_t GetTotalVertexCount() { return quad_count * 4; };
|
||||
uint32_t GetTotalIndexCount() { return quad_count * 6; };
|
||||
};
|
||||
|
||||
class Renderer2D
|
||||
@@ -34,6 +35,7 @@ namespace OpenEngine {
|
||||
|
||||
static void BeginScene(const OrthographicCamera& camera);
|
||||
static void BeginScene(const Camera& camera, const glm::mat4& transform);
|
||||
static void BeginScene(const EditorCamera& camera);
|
||||
static void EndScene();
|
||||
static void Flush();
|
||||
|
||||
@@ -50,6 +52,9 @@ namespace OpenEngine {
|
||||
|
||||
private:
|
||||
static void FlushAndReset();
|
||||
|
||||
static void StartBatch();
|
||||
static void NextBatch();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#ifndef SCENE_HPP
|
||||
#define SCENE_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include "open_engine/renderer/editor_camera.hpp"
|
||||
|
||||
#include <entt/entt.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace OpenEngine {
|
||||
|
||||
@@ -17,7 +19,8 @@ namespace OpenEngine {
|
||||
Entity CreateEntity(const std::string& name = std::string());
|
||||
void DeleteEntity(Entity entity);
|
||||
|
||||
void OnUpdate();
|
||||
void OnUpdateRuntime();
|
||||
void OnUpdateEditor(EditorCamera& camera);
|
||||
void OnViewportResize(uint32_t width, uint32_t height);
|
||||
|
||||
entt::registry& GetRegistry() { return registry; };
|
||||
|
||||
Reference in New Issue
Block a user