41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
|
|
#include "MagnumDrawable.h"
|
||
|
|
|
||
|
|
#include <Magnum/SceneGraph/Camera.h>
|
||
|
|
|
||
|
|
#include "Components.h"
|
||
|
|
|
||
|
|
namespace Rendering::Magnum
|
||
|
|
{
|
||
|
|
void Drawable::draw(const Matrix4& transformationMatrix, SceneGraph::Camera3D& camera)
|
||
|
|
{
|
||
|
|
const auto mesh = _registry.try_get<Components::Mesh>(_entity);
|
||
|
|
if (!mesh) return;
|
||
|
|
|
||
|
|
if (const auto material = _registry.try_get<Components::Material>(_entity))
|
||
|
|
{
|
||
|
|
material->_shader->
|
||
|
|
setDiffuseColor(material->phongConfig->diffuse)
|
||
|
|
.setAmbientColor(material->phongConfig->ambient)
|
||
|
|
.setSpecularColor(material->phongConfig->specular)
|
||
|
|
.setShininess(material->phongConfig->shininess)
|
||
|
|
.setLightPositions({
|
||
|
|
{camera.cameraMatrix().transformPoint({-3.0f, 10.0f, 10.0f}), 0.0f}
|
||
|
|
})
|
||
|
|
.setTransformationMatrix(transformationMatrix)
|
||
|
|
.setNormalMatrix(transformationMatrix.normalMatrix())
|
||
|
|
.setProjectionMatrix(camera.projectionMatrix())
|
||
|
|
.draw(*mesh->mesh);
|
||
|
|
|
||
|
|
if (material->texture)
|
||
|
|
{
|
||
|
|
material->_shader->bindDiffuseTexture(*material->texture);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// TODO: Have a default rendering method
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|