Transform.Scale
This commit is contained in:
@@ -9,9 +9,13 @@ namespace Components
|
|||||||
|
|
||||||
struct Transform : Component
|
struct Transform : Component
|
||||||
{
|
{
|
||||||
|
Transform()
|
||||||
|
: Scale(glm::vec3(1.f)) { }
|
||||||
|
|
||||||
glm::vec3 Position;
|
glm::vec3 Position;
|
||||||
glm::quat Orientation;
|
glm::quat Orientation;
|
||||||
glm::vec3 Velocity;
|
glm::vec3 Velocity;
|
||||||
|
glm::vec3 Scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,10 +87,10 @@ void GameWorld::Initialize()
|
|||||||
m_Player = CreateEntity();
|
m_Player = CreateEntity();
|
||||||
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
transform = AddComponent<Components::Transform>(m_Player, "Transform");
|
||||||
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
transform->Position = glm::vec3(0.f, 4.f, 0.f);
|
||||||
|
transform->Scale = glm::vec3(2.0f);
|
||||||
model = AddComponent<Components::Model>(m_Player, "Model");
|
model = AddComponent<Components::Model>(m_Player, "Model");
|
||||||
model->ModelFile = "ship.obj";
|
model->ModelFile = "ship.obj";
|
||||||
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
auto bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||||
bounds->Origin = glm::vec3(0.f);
|
|
||||||
bounds->VolumeVector = glm::vec3(1.0f, 2.0f, 3.0f);
|
bounds->VolumeVector = glm::vec3(1.0f, 2.0f, 3.0f);
|
||||||
|
|
||||||
ent = CreateEntity();
|
ent = CreateEntity();
|
||||||
|
|||||||
@@ -285,12 +285,11 @@ void Renderer::AddTextToDraw()
|
|||||||
//Add to draw shit vector
|
//Add to draw shit vector
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddModelToDraw(std::shared_ptr<Model> _model, glm::vec3 _position, glm::quat _orientation)
|
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
||||||
{
|
{
|
||||||
glm::mat4 RotationMatrix = glm::toMat4(_orientation);
|
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||||
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), _position) * RotationMatrix ;
|
|
||||||
// You can now use ModelMatrix to build the MVP matrix
|
// You can now use ModelMatrix to build the MVP matrix
|
||||||
ModelsToRender.push_back(new ModelData(_model, ModelMatrix));
|
ModelsToRender.push_back(new ModelData(model, ModelMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddPointLightToDraw(
|
void Renderer::AddPointLightToDraw(
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
void Draw(double dt);
|
void Draw(double dt);
|
||||||
void DrawText();
|
void DrawText();
|
||||||
|
|
||||||
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation);
|
void AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale);
|
||||||
void AddTextToDraw();
|
void AddTextToDraw();
|
||||||
void AddPointLightToDraw(
|
void AddPointLightToDraw(
|
||||||
glm::vec3 _position,
|
glm::vec3 _position,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto model = m_CachedModels[modelComponent->ModelFile];
|
auto model = m_CachedModels[modelComponent->ModelFile];
|
||||||
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation, transformComponent->Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug draw bounds
|
// Debug draw bounds
|
||||||
@@ -33,7 +33,8 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
|||||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||||
if (bounds != nullptr) {
|
if (bounds != nullptr) {
|
||||||
glm::vec3 origin = transformComponent->Position + bounds->Origin;
|
glm::vec3 origin = transformComponent->Position + bounds->Origin;
|
||||||
m_Renderer->AddAABBToDraw(origin, bounds->VolumeVector);
|
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||||
|
m_Renderer->AddAABBToDraw(origin, volumeVector);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user