vktutorial/hk_game_object.hpp

67 lines
1.4 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;
}
};
struct RigidBody2dComponent
{
glm::vec2 velocity;
float mass{1.0f};
};
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{};
RigidBody2dComponent m_rigidBody2d{};
private:
GameObject(id_t objId) : m_id(objId) {}
id_t m_id;
};
} // namespace hk