Support count setter
This commit is contained in:
@@ -16,12 +16,14 @@ static const auto HUE_BG = 210.0_degf;
|
||||
static const auto COLOR_BG = Color4::fromHsv({HUE_BG, .3f, .9f}, 1.f);
|
||||
static const auto COLOR_GRID = Color4::fromHsv({HUE_BG, .3f, .7f}, 1.f);
|
||||
|
||||
MagnumRenderer::MagnumRenderer() {}
|
||||
MagnumRenderer::MagnumRenderer() :
|
||||
m_init(false),
|
||||
m_count(1) {}
|
||||
|
||||
MagnumRenderer::~MagnumRenderer() {}
|
||||
|
||||
void MagnumRenderer::t(const float t) {
|
||||
if (m_subjectObject != nullptr) {
|
||||
if (m_subjectObject != nullptr && m_subjectObject->parent()) {
|
||||
m_subjectObject->resetTransformation();
|
||||
m_subjectObject->translate(Vector3{0.f, 1.f, 0.f});
|
||||
m_subjectObject->rotateY(Rad(t*Math::Constants<float>::pi()));
|
||||
@@ -38,7 +40,8 @@ void MagnumRenderer::hue(float hue) {
|
||||
}
|
||||
|
||||
void MagnumRenderer::count(int count) {
|
||||
m_count = count;
|
||||
if (m_subjectDrawable)
|
||||
m_subjectDrawable->count(count);
|
||||
}
|
||||
|
||||
void MagnumRenderer::lazyInitialize() {
|
||||
@@ -56,19 +59,19 @@ void MagnumRenderer::lazyInitialize() {
|
||||
.setLightColor(Color3{1.f})
|
||||
.setLightPosition(Vector3{-100.f, 100.f, 50.f});
|
||||
|
||||
new SubjectDrawable{*m_subjectObject, m_subjectShader, m_subject, m_drawables};
|
||||
m_subjectDrawable = new SubjectDrawable{*m_subjectObject, m_subjectShader, m_subject, m_drawables, m_count};
|
||||
}
|
||||
|
||||
// The Grid
|
||||
{
|
||||
m_grid = MeshTools::compile(Primitives::grid3DWireframe({15, 15}));
|
||||
auto obj = new Object3D{&m_scene};
|
||||
(*obj).rotateX(90.0_degf).scale(Vector3{8.0f});
|
||||
m_gridObject = new Object3D{&m_scene};
|
||||
(*m_gridObject).rotateX(90.0_degf).scale(Vector3{8.0f});
|
||||
|
||||
m_gridShader = Shaders::Flat3D{};
|
||||
m_gridShader.setColor(COLOR_GRID);
|
||||
|
||||
new GridDrawable{*obj, m_gridShader, m_grid, m_drawables};
|
||||
new GridDrawable{*m_gridObject, m_gridShader, m_grid, m_drawables};
|
||||
}
|
||||
|
||||
// The Camera
|
||||
@@ -142,8 +145,20 @@ void GridDrawable::draw(const Matrix4 &transformation,
|
||||
void SubjectDrawable::draw(const Matrix4 &transformation,
|
||||
SceneGraph::Camera3D &camera) {
|
||||
m_shader
|
||||
.setTransformationMatrix(transformation)
|
||||
.setNormalMatrix(transformation.normalMatrix())
|
||||
.setProjectionMatrix(camera.projectionMatrix())
|
||||
.draw(m_mesh);
|
||||
.setProjectionMatrix(camera.projectionMatrix());
|
||||
static const float width = 3.f;
|
||||
float x = -float(m_count)/2.f * width + width/2.f;
|
||||
for (int i = 0; i < m_count; i++) {
|
||||
m_shader
|
||||
.setTransformationMatrix(
|
||||
transformation *
|
||||
Matrix4::translation({x, 0.f, 0.f}))
|
||||
.draw(m_mesh);
|
||||
x += width;
|
||||
}
|
||||
}
|
||||
|
||||
void SubjectDrawable::count(int count) {
|
||||
m_count = count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user