Added Camera Component and layers
This commit is contained in:
parent
7945ff246b
commit
ae7a8b2b29
44
build.log
44
build.log
@ -1,6 +1,42 @@
|
||||
[COMPILE] g++ -std=c++20 -Wall -Isrc/include -Isrc/vendor -Isrc/vendor/imgui -IC:/msys64/mingw64/include -MMD -MP -c src\src\main.cpp -o src\build\src\main.o
|
||||
[COMPILE] g++ -std=c++20 -Wall -Isrc/include -Isrc/vendor -Isrc/vendor/imgui -IC:/msys64/mingw64/include -MMD -MP -c src\src\Engine.cpp -o src\build\src\Engine.osrc\src\Engine.cpp:23:9: warning: "NOMINMAX" redefined
|
||||
23 | #define NOMINMAX
|
||||
| ^~~~~~~~
|
||||
In file included from C:/msys64/mingw64/include/c++/14.2.0/x86_64-w64-mingw32/bits/c++config.h:680,
|
||||
from C:/msys64/mingw64/include/c++/14.2.0/bits/memoryfwd.h:48,
|
||||
from C:/msys64/mingw64/include/c++/14.2.0/memory:63,
|
||||
from src\src\Engine.h:2,
|
||||
from src\src\Engine.cpp:1:
|
||||
C:/msys64/mingw64/include/c++/14.2.0/x86_64-w64-mingw32/bits/os_defines.h:45:9: note: this is the location of the previous definition
|
||||
45 | #define NOMINMAX 1
|
||||
| ^~~~~~~~
|
||||
In file included from C:/msys64/mingw64/include/yaml-cpp/parser.h:13,
|
||||
from C:/msys64/mingw64/include/yaml-cpp/yaml.h:10,
|
||||
from src\src\Entitys/Object.h:6,
|
||||
from src\src\Engine.cpp:2:
|
||||
C:/msys64/mingw64/include/yaml-cpp/dll.h:22:65: note: '#pragma message: Defining YAML_CPP_API for DLL import'
|
||||
22 | # pragma message( "Defining YAML_CPP_API for DLL import" )
|
||||
| ^
|
||||
|
||||
[COMPILE] g++ -std=c++20 -Wall -Isrc/include -Isrc/vendor -Isrc/vendor/imgui -IC:/msys64/mingw64/include -MMD -MP -c src\src\Entitys\Object.cpp -o src\build\src\Entitys\Object.oIn file included from C:/msys64/mingw64/include/yaml-cpp/parser.h:13,
|
||||
from C:/msys64/mingw64/include/yaml-cpp/yaml.h:10,
|
||||
from src\src\Entitys\Object.h:6,
|
||||
from src\src\Entitys\Object.cpp:1:
|
||||
C:/msys64/mingw64/include/yaml-cpp/dll.h:22:65: note: '#pragma message: Defining YAML_CPP_API for DLL import'
|
||||
22 | # pragma message( "Defining YAML_CPP_API for DLL import" )
|
||||
| ^
|
||||
src\src\Entitys\Object.h: In constructor 'Object::Object(const std::string&)':
|
||||
src\src\Entitys\Object.h:48:15: warning: 'Object::localPosition' will be initialized after [-Wreorder]
|
||||
48 | glm::vec2 localPosition;
|
||||
| ^~~~~~~~~~~~~
|
||||
src\src\Entitys\Object.h:41:9: warning: 'int Object::id' [-Wreorder]
|
||||
41 | int id;
|
||||
| ^~
|
||||
src\src\Entitys\Object.cpp:10:1: warning: when initialized here [-Wreorder]
|
||||
10 | Object::Object(const std::string& name)
|
||||
| ^~~~~~
|
||||
|
||||
[LINK] g++ src\build\src\Engine.o src\build\src\main.o src\build\src\Renderer.o src\build\src\Components\SpriteComponent.o src\build\src\Entitys\Object.o src\build\src\utils\FileDialog.o src\build\src\utils\Shader.o src\build\vendor\imgui\imgui.o src\build\vendor\imgui\imgui_demo.o src\build\vendor\imgui\imgui_draw.o src\build\vendor\imgui\imgui_impl_glfw.o src\build\vendor\imgui\imgui_impl_opengl3.o src\build\vendor\imgui\imgui_tables.o src\build\vendor\imgui\imgui_widgets.o -o src\build\app.exe -LC:/msys64/mingw64/lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto
|
||||
|
||||
[TIME] Build duration: 1.23s
|
||||
[ERROR] Runtime crash
|
||||
Command 'src\build\app.exe' returned non-zero exit status 3221226356.
|
||||
[TIME] Build duration: 9.21s
|
||||
[RUN] Executed app.exe successfully.
|
||||
[TIME] Total runtime: 55.09s
|
||||
|
19
src/src/Components/CameraComponent.cpp
Normal file
19
src/src/Components/CameraComponent.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "CameraComponent.h"
|
||||
|
||||
CameraComponent::CameraComponent(Object* owner)
|
||||
: Component(owner) {}
|
||||
|
||||
void CameraComponent::Save(YAML::Emitter& out) {
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "type" << YAML::Value << "CameraComponent";
|
||||
out << YAML::Key << "zoom" << YAML::Value << zoom;
|
||||
out << YAML::Key << "aspectRatio" << YAML::Value << aspectRatio;
|
||||
out << YAML::Key << "fov" << YAML::Value << fov;
|
||||
out << YAML::EndMap;
|
||||
}
|
||||
|
||||
void CameraComponent::Load(const YAML::Node& node) {
|
||||
zoom = node["zoom"] ? node["zoom"].as<float>() : 1.0f;
|
||||
aspectRatio = node["aspectRatio"] ? node["aspectRatio"].as<float>() : 16.0f / 9.0f;
|
||||
fov = node["fov"] ? node["fov"].as<float>() : 45.0f;
|
||||
}
|
24
src/src/Components/CameraComponent.h
Normal file
24
src/src/Components/CameraComponent.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "Component.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
class CameraComponent : public Component {
|
||||
public:
|
||||
float zoom = 1.0f;
|
||||
float aspectRatio = 16.0f / 9.0f;
|
||||
float fov = 45.0f;
|
||||
|
||||
CameraComponent(Object* owner);
|
||||
|
||||
void Save(YAML::Emitter& out) override;
|
||||
void Load(const YAML::Node& node) override;
|
||||
|
||||
float GetZoom() const { return zoom; }
|
||||
float GetAspectRatio() const { return aspectRatio; }
|
||||
float GetFOV() const { return fov; }
|
||||
|
||||
void SetZoom(float z) { zoom = z; }
|
||||
void SetAspectRatio(float a) { aspectRatio = a; }
|
||||
void SetFOV(float f) { fov = f; }
|
||||
};
|
@ -10,6 +10,8 @@
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
@ -20,7 +22,7 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <commdlg.h> // includes GetOpenFileNameA
|
||||
#include <commdlg.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
static std::vector<std::shared_ptr<Object>> objects;
|
||||
@ -151,6 +153,8 @@ void Engine::Run()
|
||||
if (ImGui::DragFloat2("Position", &pos.x))
|
||||
selected->SetLocalPosition(pos);
|
||||
|
||||
ImGui::InputInt("Layer", &selected->layer);
|
||||
|
||||
// Add component
|
||||
if (ImGui::Button("Add SpriteComponent"))
|
||||
{
|
||||
@ -205,14 +209,29 @@ void Engine::Run()
|
||||
Renderer::Resize((int)size.x, (int)size.y);
|
||||
Renderer::Begin();
|
||||
|
||||
for (auto &obj : objects)
|
||||
{
|
||||
if (auto sprite = obj->GetComponent<SpriteComponent>())
|
||||
{
|
||||
std::vector<std::shared_ptr<Object>> toDraw;
|
||||
|
||||
std::function<void(const std::shared_ptr<Object>&)> collect = [&](const std::shared_ptr<Object>& obj) {
|
||||
toDraw.push_back(obj);
|
||||
for (const auto& child : obj->GetChildren())
|
||||
collect(child);
|
||||
};
|
||||
|
||||
for (const auto& obj : objects)
|
||||
if (!obj->GetParent())
|
||||
collect(obj);
|
||||
|
||||
std::sort(toDraw.begin(), toDraw.end(), [](const auto& a, const auto& b) {
|
||||
return a->layer < b->layer;
|
||||
});
|
||||
|
||||
for (const auto& obj : toDraw) {
|
||||
if (auto sprite = obj->GetComponent<SpriteComponent>()) {
|
||||
Renderer::DrawSprite(sprite.get(), obj->GetWorldPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Renderer::End();
|
||||
GLuint texID = Renderer::GetRenderTexture();
|
||||
ImGui::Image((ImTextureID)(uintptr_t)texID, size, ImVec2(0, 1), ImVec2(1, 0));
|
||||
|
@ -8,7 +8,7 @@
|
||||
static int nextID = 0;
|
||||
|
||||
Object::Object(const std::string& name)
|
||||
: name(name), localPosition(0.0f, 0.0f), id(nextID++) {}
|
||||
: name(name), localPosition(0.0f, 0.0f), id(nextID++), layer(1) {}
|
||||
|
||||
Object::~Object() {}
|
||||
|
||||
|
@ -41,6 +41,8 @@ public:
|
||||
int id;
|
||||
bool selected = false;
|
||||
|
||||
int layer;
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
glm::vec2 localPosition;
|
||||
|
Loading…
Reference in New Issue
Block a user