Rot + Scale!
This commit is contained in:
BIN
VulkanTest
BIN
VulkanTest
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,17 @@ namespace cve {
|
|||||||
|
|
||||||
struct Transform2dComponent {
|
struct Transform2dComponent {
|
||||||
glm::vec2 translation{}; // Position offset
|
glm::vec2 translation{}; // Position offset
|
||||||
glm::mat2 mat2() { return glm::mat2{1.f}; };
|
glm::vec2 scale{1.f, 1.f};
|
||||||
|
float rotation;
|
||||||
|
|
||||||
|
glm::mat2 mat2() {
|
||||||
|
const float s = glm::sin(rotation);
|
||||||
|
const float c = glm::cos(rotation);
|
||||||
|
glm::mat2 rotMatrix{{c, s}, {-s, c}};
|
||||||
|
|
||||||
|
glm::mat2 scaleMat{{scale.x, .0f}, {.0f, scale.y}};
|
||||||
|
return rotMatrix*scaleMat;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CveGameObject {
|
class CveGameObject {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#define GLM_FORCE_RADIANS
|
#define GLM_FORCE_RADIANS
|
||||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/constants.hpp>
|
||||||
|
|
||||||
namespace cve {
|
namespace cve {
|
||||||
struct SimplePushConstantData{
|
struct SimplePushConstantData{
|
||||||
@@ -47,6 +48,8 @@ namespace cve {
|
|||||||
triangle.model = cveModel;
|
triangle.model = cveModel;
|
||||||
triangle.color = {0.1f, 0.8f, 0.1f};
|
triangle.color = {0.1f, 0.8f, 0.1f};
|
||||||
triangle.transform2d.translation.x = .2f;
|
triangle.transform2d.translation.x = .2f;
|
||||||
|
triangle.transform2d.scale = {2.f, .5f};
|
||||||
|
triangle.transform2d.rotation = .25f * glm::two_pi<float>();
|
||||||
|
|
||||||
gameObjects.push_back(std::move(triangle));
|
gameObjects.push_back(std::move(triangle));
|
||||||
}
|
}
|
||||||
@@ -179,6 +182,8 @@ namespace cve {
|
|||||||
cvePipeline->bind(commandBuffer);
|
cvePipeline->bind(commandBuffer);
|
||||||
|
|
||||||
for (auto& obj: gameObjects) {
|
for (auto& obj: gameObjects) {
|
||||||
|
obj.transform2d.rotation = glm::mod(obj.transform2d.rotation + 0.001f, glm::two_pi<float>());
|
||||||
|
|
||||||
SimplePushConstantData push{};
|
SimplePushConstantData push{};
|
||||||
push.offset = obj.transform2d.translation;
|
push.offset = obj.transform2d.translation;
|
||||||
push.color = obj.color;
|
push.color = obj.color;
|
||||||
|
|||||||
Reference in New Issue
Block a user