diff --git a/VulkanTest b/VulkanTest index 7fea3c0..c594100 100755 Binary files a/VulkanTest and b/VulkanTest differ diff --git a/build/first_app.o b/build/first_app.o index 363cf58..70b6289 100644 Binary files a/build/first_app.o and b/build/first_app.o differ diff --git a/cve_game_object.hpp b/cve_game_object.hpp new file mode 100644 index 0000000..fcc4e0c --- /dev/null +++ b/cve_game_object.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "cve_model.hpp" + +#include + +namespace cve { + + struct Transform2dComponent { + glm::vec2 translation{}; // Position offset + glm::mat2 mat2() { return glm::mat2{1.f}; }; + }; + + class CveGameObject { + public: + using id_t = unsigned int; + + static CveGameObject createGameObject() { + static id_t currentId = 0; + return CveGameObject{currentId++}; + } + + CveGameObject(const CveGameObject &) = delete; + CveGameObject &operator=(const CveGameObject &) = delete; + CveGameObject(CveGameObject &&) = default; + CveGameObject &operator=(CveGameObject &&) = default; + + const id_t getId() { return id; } + + std::shared_ptr model{}; + glm::vec3 color; + Transform2dComponent transform2d{}; + + private: + CveGameObject(id_t objID) : id{objID} {} + id_t id; + }; +} \ No newline at end of file diff --git a/first_app.cpp b/first_app.cpp index 885e034..3c7c098 100644 --- a/first_app.cpp +++ b/first_app.cpp @@ -9,6 +9,7 @@ namespace cve { struct SimplePushConstantData{ + glm::mat2 transform{1.f}; // Identity matrix glm::vec2 offset; alignas(16) glm::vec3 color; }; diff --git a/first_app.hpp b/first_app.hpp index 442cd68..d179456 100644 --- a/first_app.hpp +++ b/first_app.hpp @@ -5,6 +5,7 @@ #include "cve_device.hpp" #include "cve_swap_chain.hpp" #include "cve_model.hpp" +#include "cve_game_object.hpp" #include #include diff --git a/shaders/simple_shader.frag b/shaders/simple_shader.frag index 6092dcd..7fea586 100644 --- a/shaders/simple_shader.frag +++ b/shaders/simple_shader.frag @@ -3,6 +3,7 @@ layout(location = 0) out vec4 outColor; layout(push_constant) uniform Push { + mat2 transform; vec2 offset; vec3 color; } push; diff --git a/shaders/simple_shader.frag.spv b/shaders/simple_shader.frag.spv index 6cc4cd4..9463bc6 100644 Binary files a/shaders/simple_shader.frag.spv and b/shaders/simple_shader.frag.spv differ diff --git a/shaders/simple_shader.vert b/shaders/simple_shader.vert index cfa9bc6..7a6b8fa 100644 --- a/shaders/simple_shader.vert +++ b/shaders/simple_shader.vert @@ -4,10 +4,11 @@ layout(location = 0) in vec2 position; layout(location = 1) in vec3 color; layout(push_constant) uniform Push { + mat2 transform; vec2 offset; vec3 color; } push; void main() { - gl_Position = vec4(position + push.offset, 0.0, 1.0); + gl_Position = vec4(push.transform * position + push.offset, 0.0, 1.0); } diff --git a/shaders/simple_shader.vert.spv b/shaders/simple_shader.vert.spv index d1f503f..473cb69 100644 Binary files a/shaders/simple_shader.vert.spv and b/shaders/simple_shader.vert.spv differ