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())
|
||||
.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;
|
||||
}
|
||||
|
@@ -19,6 +19,40 @@ using namespace Magnum;
|
||||
using Object3D = SceneGraph::Object<SceneGraph::MatrixTransformation3D>;
|
||||
using Scene3D = SceneGraph::Scene<SceneGraph::MatrixTransformation3D>;
|
||||
|
||||
class GridDrawable : public SceneGraph::Drawable3D {
|
||||
public:
|
||||
explicit GridDrawable(Object3D &object, Shaders::Flat3D &shader,
|
||||
GL::Mesh &mesh, SceneGraph::DrawableGroup3D &drawables)
|
||||
: SceneGraph::Drawable3D{object, &drawables},
|
||||
m_shader(shader),
|
||||
m_mesh(mesh) {}
|
||||
|
||||
void draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera);
|
||||
|
||||
private:
|
||||
Shaders::Flat3D &m_shader;
|
||||
GL::Mesh &m_mesh;
|
||||
};
|
||||
|
||||
class SubjectDrawable : public SceneGraph::Drawable3D {
|
||||
public:
|
||||
explicit SubjectDrawable(Object3D &object, Shaders::Phong &shader,
|
||||
GL::Mesh &mesh, SceneGraph::DrawableGroup3D &drawables,
|
||||
int count)
|
||||
: SceneGraph::Drawable3D{object, &drawables},
|
||||
m_shader(shader),
|
||||
m_mesh(mesh),
|
||||
m_count(count) {}
|
||||
|
||||
void draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera);
|
||||
void count(int count);
|
||||
|
||||
private:
|
||||
Shaders::Phong &m_shader;
|
||||
GL::Mesh &m_mesh;
|
||||
int m_count;
|
||||
};
|
||||
|
||||
class MagnumRenderer {
|
||||
public:
|
||||
MagnumRenderer();
|
||||
@@ -39,9 +73,8 @@ private:
|
||||
void lazyInitialize();
|
||||
void prepGLState();
|
||||
|
||||
bool m_init{false};
|
||||
|
||||
float m_count{1};
|
||||
bool m_init;
|
||||
int m_count;
|
||||
|
||||
Platform::GLContext *m_ctx;
|
||||
GL::Framebuffer m_FBO{NoCreate};
|
||||
@@ -53,39 +86,11 @@ private:
|
||||
GL::Mesh m_subject{NoCreate};
|
||||
Shaders::Phong m_subjectShader{NoCreate};
|
||||
Object3D* m_subjectObject{nullptr};
|
||||
SubjectDrawable* m_subjectDrawable{nullptr};
|
||||
|
||||
GL::Mesh m_grid{NoCreate};
|
||||
Shaders::Flat3D m_gridShader{NoCreate};
|
||||
};
|
||||
|
||||
class GridDrawable : public SceneGraph::Drawable3D {
|
||||
public:
|
||||
explicit GridDrawable(Object3D &object, Shaders::Flat3D &shader,
|
||||
GL::Mesh &mesh, SceneGraph::DrawableGroup3D &drawables)
|
||||
: SceneGraph::Drawable3D{object, &drawables},
|
||||
m_shader(shader),
|
||||
m_mesh(mesh) {}
|
||||
|
||||
void draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera);
|
||||
|
||||
private:
|
||||
Shaders::Flat3D &m_shader;
|
||||
GL::Mesh &m_mesh;
|
||||
};
|
||||
|
||||
class SubjectDrawable : public SceneGraph::Drawable3D {
|
||||
public:
|
||||
explicit SubjectDrawable(Object3D &object, Shaders::Phong &shader,
|
||||
GL::Mesh &mesh, SceneGraph::DrawableGroup3D &drawables)
|
||||
: SceneGraph::Drawable3D{object, &drawables},
|
||||
m_shader(shader),
|
||||
m_mesh(mesh) {}
|
||||
|
||||
void draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera);
|
||||
|
||||
private:
|
||||
Shaders::Phong &m_shader;
|
||||
GL::Mesh &m_mesh;
|
||||
Object3D* m_gridObject{nullptr};
|
||||
};
|
||||
|
||||
#endif // MAGNUM_RENDER_H
|
||||
|
Reference in New Issue
Block a user