vktutorial/hk_game_object.hpp

59 lines
1.3 KiB
C++

#pragma once
#include "hk_model.hpp"
// std
#include <memory>
namespace hk
{
struct Transform2dComponent
{
glm::vec2 translation{};
glm::vec2 scale{1.0f, 1.0f};
float rotation;
glm::mat2 mat2()
{
const float cos = glm::cos(rotation);
const float sin = glm::sin(rotation);
glm::mat2 rotationMat{
{cos, sin},
{-sin, cos}};
glm::mat2 scaleMat{
{scale.x, .0f},
{.0f, scale.y}};
return rotationMat * scaleMat;
}
};
class GameObject
{
public:
using id_t = unsigned int;
static GameObject createGameObject()
{
static id_t currentId = 0;
return GameObject{currentId++};
}
GameObject(const GameObject &) = delete;
GameObject &operator=(const GameObject &) = delete;
GameObject(GameObject &&) = default;
GameObject &operator=(GameObject &&) = default;
id_t getId() const { return m_id; }
std::shared_ptr<Model> m_model{};
glm::vec3 m_color{};
Transform2dComponent m_transform2d{};
private:
GameObject(id_t objId) : m_id(objId) {}
id_t m_id;
};
} // namespace hk