diff --git a/src/examples/cameras.cpp b/src/examples/cameras.cpp index a4b7d9ef..6af21c37 100644 --- a/src/examples/cameras.cpp +++ b/src/examples/cameras.cpp @@ -8,10 +8,8 @@ class MyApp : public robot_dart::gui::magnum::GlfwApplication { public: - explicit MyApp(int argc, char** argv, const dart::simulation::WorldPtr& world, - size_t width, size_t height, const std::string& title = "DART", - bool shadowed = true, bool transparent_shadows = true) - : GlfwApplication(argc, argv, world, width, height, title, shadowed, transparent_shadows) {} + explicit MyApp(int argc, char** argv, const dart::simulation::WorldPtr& world, const robot_dart::gui::magnum::GraphicsConfiguration& configuration = robot_dart::gui::magnum::GraphicsConfiguration()) + : GlfwApplication(argc, argv, world, configuration) {} protected: void keyPressEvent(KeyEvent& event) override @@ -43,7 +41,10 @@ int main() robot_dart::RobotDARTSimu simu(0.001); // Magnum graphics - auto graphics = std::make_shared>(simu.world(), 1024, 768); + robot_dart::gui::magnum::GraphicsConfiguration configuration; + configuration.width = 1024; + configuration.height = 768; + auto graphics = std::make_shared>(simu.world(), configuration); simu.set_graphics(graphics); graphics->look_at({0., 3.5, 2.}, {0., 0., 0.25}); diff --git a/src/examples/magnum_contexts.cpp b/src/examples/magnum_contexts.cpp index 61115f56..29aa14da 100644 --- a/src/examples/magnum_contexts.cpp +++ b/src/examples/magnum_contexts.cpp @@ -52,7 +52,10 @@ int main() std::static_pointer_cast(g_robot->controllers()[0])->set_pd(300., 50.); // Magnum graphics - auto graphics = std::make_shared>(simu.world(), 1024, 768); + robot_dart::gui::magnum::GraphicsConfiguration configuration; + configuration.width = 1024; + configuration.height = 768; + auto graphics = std::make_shared>(simu.world(), configuration); simu.set_graphics(graphics); // Position the camera differently for each thread to visualize the difference graphics->look_at({0.4 * index, 3.5 - index * 0.1, 2.}, {0., 0., 0.25}); diff --git a/src/python/example.py b/src/python/example.py index cbfcb8b8..826c613c 100644 --- a/src/python/example.py +++ b/src/python/example.py @@ -36,11 +36,11 @@ def clone(self): simu = rd.RobotDARTSimu(0.001) # Create graphics -graphics = rd.gui.Graphics(simu.world(), 640, 480, True, False, "DART") +graphics = rd.gui.Graphics(simu.world(), rd.gui.GraphicsConfiguration()) # graphics.clear_lights() # mat = rd.gui.Material(magnum.Color4(0, 0, 0, 1), magnum.Color4(1, 1, 1, 1), magnum.Color4(1, 1, 1, 1), 80.) -# graphics.add_light(rd.gui.createPointLight(magnum.Vector3(-1., 1., 2.), mat, 2., magnum.Vector3(0., 0., 1.))) -# graphics.add_light(rd.gui.createPointLight(magnum.Vector3(1., -1., 2.), mat, 2., magnum.Vector3(0., 0., 1.))) +# graphics.add_light(rd.gui.create_point_light(magnum.Vector3(-1., 1., 2.), mat, 2., magnum.Vector3(0., 0., 1.))) +# graphics.add_light(rd.gui.create_point_light(magnum.Vector3(1., -1., 2.), mat, 2., magnum.Vector3(0., 0., 1.))) simu.set_graphics(graphics) # Add robot and floor to the simulation diff --git a/src/python/example_parallel.py b/src/python/example_parallel.py index 5a8e4ffa..768917ae 100644 --- a/src/python/example_parallel.py +++ b/src/python/example_parallel.py @@ -26,7 +26,7 @@ def test(): simu = rd.RobotDARTSimu(0.001) # set the graphics - graphics = rd.gui.WindowlessGraphics(simu.world(), 640, 480, True, False, "DART") + graphics = rd.gui.WindowlessGraphics(simu.world(), rd.gui.GraphicsConfiguration()) graphics.look_at([0.4 * ii, 3.5 - ii * 0.1, 2.], [0., 0., 0.25], [0., 0., 1.]) simu.set_graphics(graphics) diff --git a/src/python/gui.cpp b/src/python/gui.cpp index 9db2c967..7eda94ee 100644 --- a/src/python/gui.cpp +++ b/src/python/gui.cpp @@ -24,6 +24,7 @@ namespace robot_dart { // Helper definitions and classes using BaseGraphics = gui::magnum::Graphics; using BaseWindowlessGraphics = gui::magnum::Graphics; + using GraphicsConfiguration = gui::magnum::GraphicsConfiguration; class Graphics : public BaseGraphics { public: @@ -35,6 +36,26 @@ namespace robot_dart { using BaseWindowlessGraphics::BaseWindowlessGraphics; }; + py::class_(sm, "GraphicsConfiguration") + .def(py::init(), + py::arg("width") = 640, + py::arg("height") = 480, + py::arg("title") = "DART", + py::arg("shadowed") = true, + py::arg("transparent_shadows") = true, + py::arg("shadow_map_size") = 512, + py::arg("max_lights") = 3) + + .def_readwrite("width", &GraphicsConfiguration::width) + .def_readwrite("height", &GraphicsConfiguration::height) + .def_readwrite("title", &GraphicsConfiguration::title) + + .def_readwrite("shadowed", &GraphicsConfiguration::shadowed) + .def_readwrite("transparent_shadows", &GraphicsConfiguration::transparent_shadows) + .def_readwrite("shadow_map_size", &GraphicsConfiguration::shadow_map_size) + + .def_readwrite("max_lights", &GraphicsConfiguration::max_lights); + py::class_>(sm, "Base"); py::class_>(sm, "BaseGraphics"); py::class_>(sm, "BaseWindowlessGraphics"); @@ -42,7 +63,7 @@ namespace robot_dart { // Graphics class py::class_>(sm, "Graphics") - .def(py::init()) + .def(py::init()) .def("done", &Graphics::done) .def("refresh", &Graphics::refresh) @@ -61,7 +82,8 @@ namespace robot_dart { .def("recording", &Graphics::recording) .def("recording_depth", &Graphics::recording_depth) - .def("is_shadowed", &Graphics::is_shadowed) + .def("shadowed", &Graphics::shadowed) + .def("transparent_shadows", &Graphics::transparent_shadows) .def("enable_shadows", &Graphics::enable_shadows) // Magnum::Image2D* magnum_image() @@ -84,7 +106,7 @@ namespace robot_dart { // WindowlessGraphics class py::class_>(sm, "WindowlessGraphics") - .def(py::init()) + .def(py::init()) .def("done", &WindowlessGraphics::done) .def("refresh", &WindowlessGraphics::refresh) @@ -103,7 +125,8 @@ namespace robot_dart { .def("recording", &WindowlessGraphics::recording) .def("recording_depth", &WindowlessGraphics::recording_depth) - .def("is_shadowed", &WindowlessGraphics::is_shadowed) + .def("shadowed", &WindowlessGraphics::shadowed) + .def("transparent_shadows", &WindowlessGraphics::transparent_shadows) .def("enable_shadows", &WindowlessGraphics::enable_shadows) // Magnum::Image2D* magnum_image() @@ -190,9 +213,9 @@ namespace robot_dart { .def(py::init()); // TO-DO: Add more functions - sm.def("createPointLight", &gui::magnum::gs::createPointLight); - sm.def("createSpotLight", &gui::magnum::gs::createSpotLight); - sm.def("createDirectionalLight", &gui::magnum::gs::createDirectionalLight); + sm.def("create_point_light", &gui::magnum::gs::create_point_light); + sm.def("create_spot_light", &gui::magnum::gs::create_spot_light); + sm.def("create_directional_light", &gui::magnum::gs::create_directional_light); } #endif } // namespace python diff --git a/src/robot_dart/gui/base.hpp b/src/robot_dart/gui/base.hpp index 931adb62..b410c742 100644 --- a/src/robot_dart/gui/base.hpp +++ b/src/robot_dart/gui/base.hpp @@ -15,10 +15,7 @@ namespace robot_dart { virtual ~Base() {} - virtual bool done() const - { - return false; - } + virtual bool done() const { return false; } virtual void refresh() {} diff --git a/src/robot_dart/gui/magnum/base_application.cpp b/src/robot_dart/gui/magnum/base_application.cpp index 41ed3e84..f1222142 100644 --- a/src/robot_dart/gui/magnum/base_application.cpp +++ b/src/robot_dart/gui/magnum/base_application.cpp @@ -15,12 +15,6 @@ #include #include -#include -#include -#include -#include -#include - namespace robot_dart { namespace gui { namespace magnum { @@ -70,330 +64,10 @@ namespace robot_dart { } } - // DrawableObject - DrawableObject::DrawableObject( - const std::vector>& meshes, - const std::vector& materials, - std::reference_wrapper color, - std::reference_wrapper texture, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group) - : Object3D{parent}, - Magnum::SceneGraph::Drawable3D{*this, group}, - _meshes{meshes}, - _color_shader{color}, - _texture_shader{texture}, - _materials(materials) - { - assert(_materials.size() >= meshes.size()); - _isSoftBody.resize(_meshes.size(), false); - } - - DrawableObject& DrawableObject::setMeshes(const std::vector>& meshes) - { - _meshes = meshes; - return *this; - } - - DrawableObject& DrawableObject::setMaterials(const std::vector& materials) - { - _materials = materials; - return *this; - } - - DrawableObject& DrawableObject::setSoftBodies(const std::vector& softBody) - { - _isSoftBody = softBody; - return *this; - } - - DrawableObject& DrawableObject::setScalings(const std::vector& scalings) - { - _scalings = scalings; - - _hasNegativeScaling.resize(_scalings.size()); - for (size_t i = 0; i < scalings.size(); i++) { - _hasNegativeScaling[i] = false; - for (size_t j = 0; j < 3; j++) - if (_scalings[i][j] < 0.f) { - _hasNegativeScaling[i] = true; - break; - } - } - - return *this; - } - - DrawableObject& DrawableObject::setTransparent(bool transparent) - { - _isTransparent = transparent; - return *this; - } - - DrawableObject& DrawableObject::setColorShader(std::reference_wrapper shader) - { - _color_shader = shader; - return *this; - } - - DrawableObject& DrawableObject::setTextureShader(std::reference_wrapper shader) - { - _texture_shader = shader; - return *this; - } - - void DrawableObject::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) - { - for (size_t i = 0; i < _meshes.size(); i++) { - Magnum::GL::Mesh& mesh = _meshes[i]; - Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); - bool isColor = !_materials[i].hasDiffuseTexture(); - if (_isSoftBody[i]) - Magnum::GL::Renderer::disable(Magnum::GL::Renderer::Feature::FaceCulling); - else if (_hasNegativeScaling[i]) - Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Front); - if (isColor) { - _color_shader.get() - .setMaterial(_materials[i]) - .setTransformationMatrix(absoluteTransformationMatrix() * scalingMatrix) - .setNormalMatrix((transformationMatrix * scalingMatrix).rotationScaling()) - .setCameraMatrix(camera.cameraMatrix()) - .setProjectionMatrix(camera.projectionMatrix()) - .draw(mesh); - } - else { - _texture_shader.get() - .setMaterial(_materials[i]) - .setTransformationMatrix(absoluteTransformationMatrix() * scalingMatrix) - .setNormalMatrix((transformationMatrix * scalingMatrix).rotationScaling()) - .setCameraMatrix(camera.cameraMatrix()) - .setProjectionMatrix(camera.projectionMatrix()) - .draw(mesh); - } - - if (_isSoftBody[i]) - Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::FaceCulling); - else if (_hasNegativeScaling[i]) - Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Back); - } - } - - // ShadowedObject - ShadowedObject::ShadowedObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group) - : Object3D{parent}, - Magnum::SceneGraph::Drawable3D{*this, group}, - _meshes{meshes}, - _shader{shader}, - _texture_shader(texture_shader) {} - - ShadowedObject& ShadowedObject::setMeshes(const std::vector>& meshes) - { - _meshes = meshes; - return *this; - } - - ShadowedObject& ShadowedObject::setMaterials(const std::vector& materials) - { - _materials = materials; - return *this; - } - - ShadowedObject& ShadowedObject::setScalings(const std::vector& scalings) - { - _scalings = scalings; - return *this; - } - - void ShadowedObject::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) - { - for (size_t i = 0; i < _meshes.size(); i++) { - Magnum::GL::Mesh& mesh = _meshes[i]; - Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); - bool isColor = !_materials[i].hasDiffuseTexture(); - if (isColor) { - (_shader.get()) - .setTransformationMatrix(transformationMatrix * scalingMatrix) - .setProjectionMatrix(camera.projectionMatrix()) - .setMaterial(_materials[i]) - .draw(mesh); - } - else { - (_texture_shader.get()) - .setTransformationMatrix(transformationMatrix * scalingMatrix) - .setProjectionMatrix(camera.projectionMatrix()) - .setMaterial(_materials[i]) - .draw(mesh); - } - } - } - - // ShadowedColorObject - ShadowedColorObject::ShadowedColorObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group) - : Object3D{parent}, - Magnum::SceneGraph::Drawable3D{*this, group}, - _meshes{meshes}, - _shader{shader}, - _texture_shader(texture_shader) {} - - ShadowedColorObject& ShadowedColorObject::setMeshes(const std::vector>& meshes) - { - _meshes = meshes; - return *this; - } - - ShadowedColorObject& ShadowedColorObject::setMaterials(const std::vector& materials) - { - _materials = materials; - return *this; - } - - ShadowedColorObject& ShadowedColorObject::setScalings(const std::vector& scalings) - { - _scalings = scalings; - return *this; - } - - void ShadowedColorObject::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) - { - for (size_t i = 0; i < _meshes.size(); i++) { - Magnum::GL::Mesh& mesh = _meshes[i]; - Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); - bool isColor = !_materials[i].hasDiffuseTexture(); - if (isColor) { - (_shader.get()) - .setTransformationMatrix(transformationMatrix * scalingMatrix) - .setProjectionMatrix(camera.projectionMatrix()) - .setMaterial(_materials[i]) - .draw(mesh); - } - else { - (_texture_shader.get()) - .setTransformationMatrix(transformationMatrix * scalingMatrix) - .setProjectionMatrix(camera.projectionMatrix()) - .setMaterial(_materials[i]) - .draw(mesh); - } - } - } - - // CubeMapShadowedObject - CubeMapShadowedObject::CubeMapShadowedObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group) - : Object3D{parent}, - Magnum::SceneGraph::Drawable3D{*this, group}, - _meshes{meshes}, - _shader{shader}, - _texture_shader(texture_shader) {} - - CubeMapShadowedObject& CubeMapShadowedObject::setMeshes(const std::vector>& meshes) - { - _meshes = meshes; - return *this; - } - - CubeMapShadowedObject& CubeMapShadowedObject::setMaterials(const std::vector& materials) - { - _materials = materials; - return *this; - } - - CubeMapShadowedObject& CubeMapShadowedObject::setScalings(const std::vector& scalings) - { - _scalings = scalings; - return *this; - } - - void CubeMapShadowedObject::draw(const Magnum::Matrix4&, Magnum::SceneGraph::Camera3D&) - { - for (size_t i = 0; i < _meshes.size(); i++) { - Magnum::GL::Mesh& mesh = _meshes[i]; - Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); - bool isColor = !_materials[i].hasDiffuseTexture(); - if (isColor) { - (_shader.get()) - .setTransformationMatrix(absoluteTransformation() * scalingMatrix) - .setMaterial(_materials[i]) - .draw(mesh); - } - else { - (_texture_shader.get()) - .setTransformationMatrix(absoluteTransformation() * scalingMatrix) - .setMaterial(_materials[i]) - .draw(mesh); - } - } - } - - // CubeMapShadowedColorObject - CubeMapShadowedColorObject::CubeMapShadowedColorObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group) - : Object3D{parent}, - Magnum::SceneGraph::Drawable3D{*this, group}, - _meshes{meshes}, - _shader{shader}, - _texture_shader(texture_shader) {} - - CubeMapShadowedColorObject& CubeMapShadowedColorObject::setMeshes(const std::vector>& meshes) - { - _meshes = meshes; - return *this; - } - - CubeMapShadowedColorObject& CubeMapShadowedColorObject::setMaterials(const std::vector& materials) - { - _materials = materials; - return *this; - } - - CubeMapShadowedColorObject& CubeMapShadowedColorObject::setScalings(const std::vector& scalings) - { - _scalings = scalings; - return *this; - } - - void CubeMapShadowedColorObject::draw(const Magnum::Matrix4&, Magnum::SceneGraph::Camera3D&) - { - for (size_t i = 0; i < _meshes.size(); i++) { - Magnum::GL::Mesh& mesh = _meshes[i]; - Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); - bool isColor = !_materials[i].hasDiffuseTexture(); - if (isColor) { - (_shader.get()) - .setTransformationMatrix(absoluteTransformation() * scalingMatrix) - .setMaterial(_materials[i]) - .draw(mesh); - } - else { - (_texture_shader.get()) - .setTransformationMatrix(absoluteTransformation() * scalingMatrix) - .setMaterial(_materials[i]) - .draw(mesh); - } - } - } - // BaseApplication - BaseApplication::BaseApplication(bool isShadowed, bool drawTransparentShadows) + BaseApplication::BaseApplication(const GraphicsConfiguration& configuration) : _max_lights(configuration.max_lights), _shadow_map_size(configuration.shadow_map_size) { - enableShadows(isShadowed, drawTransparentShadows); + enable_shadows(configuration.shadowed, configuration.transparent_shadows); } void BaseApplication::init(const dart::simulation::WorldPtr& world, size_t width, size_t height) @@ -403,16 +77,16 @@ namespace robot_dart { new gs::Camera(_scene, static_cast(width), static_cast(height))); /* Shadow camera */ - _shadowCameraObject = new Object3D{&_scene}; - _shadowCamera.reset(new Camera3D{*_shadowCameraObject}); + _shadow_camera_object = new Object3D{&_scene}; + _shadow_camera.reset(new Camera3D{*_shadow_camera_object}); /* Create our DARTIntegration object/world */ auto dartObj = new Object3D{&_scene}; - _dartWorld.reset(new Magnum::DartIntegration::World(_importer_manager, *dartObj, *world)); /* Plugin manager is now thread-safe */ + _dart_world.reset(new Magnum::DartIntegration::World(_importer_manager, *dartObj, *world)); /* Plugin manager is now thread-safe */ /* Phong shaders */ - _color_shader.reset(new gs::PhongMultiLight{{}, _maxLights}); - _texture_shader.reset(new gs::PhongMultiLight{{gs::PhongMultiLight::Flag::DiffuseTexture}, _maxLights}); + _color_shader.reset(new gs::PhongMultiLight{{}, _max_lights}); + _texture_shader.reset(new gs::PhongMultiLight{{gs::PhongMultiLight::Flag::DiffuseTexture}, _max_lights}); /* Shadow shaders */ _shadow_shader.reset(new gs::ShadowMap()); @@ -428,16 +102,16 @@ namespace robot_dart { /* Add default lights (2 directional lights) */ gs::Material mat; - mat.diffuseColor() = {1.f, 1.f, 1.f, 1.f}; - mat.specularColor() = {1.f, 1.f, 1.f, 1.f}; - // gs::Light light = gs::createPointLight({0.f, 0.f, 2.f}, mat, 2.f, {0.f, 0.f, 1.f}); - // gs::Light light = gs::createSpotLight( + mat.diffuse_color() = {1.f, 1.f, 1.f, 1.f}; + mat.specular_color() = {1.f, 1.f, 1.f, 1.f}; + // gs::Light light = gs::create_point_light({0.f, 0.f, 2.f}, mat, 2.f, {0.f, 0.f, 1.f}); + // gs::Light light = gs::create_spot_light( // {0.f, 0.f, 3.f}, mat, {0.f, 0.f, -1.f}, 1.f, Magnum::Math::Constants::piHalf() / 5.f, 2.f, {0.f, 0.f, 1.f}); Magnum::Vector3 dir = {-0.5f, -0.5f, -0.5f}; - gs::Light light = gs::createDirectionalLight(dir, mat); + gs::Light light = gs::create_directional_light(dir, mat); _lights.push_back(light); dir = {0.5f, 0.5f, -0.5f}; - light = gs::createDirectionalLight(dir, mat); + light = gs::create_directional_light(dir, mat); _lights.push_back(light); // Magnum::Vector3 lpos = {0.f, 0.5f, 1.f}; // Magnum::Vector3 ldir = {0.f, 0.f, -1.f}; @@ -445,40 +119,39 @@ namespace robot_dart { // Magnum::Float lspot = M_PI / 3.; // Magnum::Float lint = 1.f; // Magnum::Vector3 latt = {0.f, 0.f, 1.f}; - // light = gs::createSpotLight(lpos, mat, ldir, lexp, lspot, lint, latt); + // light = gs::create_spot_light(lpos, mat, ldir, lexp, lspot, lint, latt); // // _lights.push_back(light); // lpos = {0.5f, -0.5f, 0.6f}; - // light = gs::createPointLight(lpos, mat, lint, latt); + // light = gs::create_point_light(lpos, mat, lint, latt); // // _lights.push_back(light); // lpos = {0.5f, 0.5f, 0.6f}; - // light = gs::createPointLight(lpos, mat, lint, latt); + // light = gs::create_point_light(lpos, mat, lint, latt); // // _lights.push_back(light); // lpos = {0.5f, 1.5f, 2.f}; // latt = {1.f, 0.2f, 0.f}; - // light = gs::createPointLight(lpos, mat, lint, latt); + // light = gs::create_point_light(lpos, mat, lint, latt); // _lights.push_back(light); // lpos = {-2.f, -1.f, 2.f}; - // light = gs::createPointLight(lpos, mat, lint, latt); + // light = gs::create_point_light(lpos, mat, lint, latt); // _lights.push_back(light); } - void BaseApplication::clearLights() + void BaseApplication::clear_lights() { _lights.clear(); /* Reset lights in shaders */ gs::Light light; - for (int i = 0; i < _color_shader->maxLights(); i++) - _color_shader->setLight(i, light); - for (int i = 0; i < _texture_shader->maxLights(); i++) - _texture_shader->setLight(i, light); + for (int i = 0; i < _color_shader->max_lights(); i++) + _color_shader->set_light(i, light); + for (int i = 0; i < _texture_shader->max_lights(); i++) + _texture_shader->set_light(i, light); } - void BaseApplication::addLight(const gs::Light& light) + void BaseApplication::add_light(const gs::Light& light) { - if (static_cast(_lights.size()) < _maxLights) - _lights.push_back(light); - // TO-DO: Output warning + ROBOT_DART_ASSERT(static_cast(_lights.size()) < _max_lights, "You cannot add more lights!", ); + _lights.push_back(light); } gs::Light& BaseApplication::light(size_t i) @@ -492,7 +165,7 @@ namespace robot_dart { return _lights; } - size_t BaseApplication::numLights() const + size_t BaseApplication::num_lights() const { return _lights.size(); } @@ -502,7 +175,7 @@ namespace robot_dart { return _done; } - void BaseApplication::lookAt(const Eigen::Vector3d& camera_pos, + void BaseApplication::look_at(const Eigen::Vector3d& camera_pos, const Eigen::Vector3d& look_at, const Eigen::Vector3d& up) { @@ -518,50 +191,50 @@ namespace robot_dart { float uy = static_cast(up[1]); float uz = static_cast(up[2]); - _camera->lookAt(Magnum::Vector3{cx, cy, cz}, + _camera->look_at(Magnum::Vector3{cx, cy, cz}, Magnum::Vector3{lx, ly, lz}, Magnum::Vector3{ux, uy, uz}); } - void BaseApplication::updateLights(const gs::Camera& camera) + void BaseApplication::update_lights(const gs::Camera& camera) { /* Update lights transformations */ - camera.transformLights(_lights); + camera.transform_lights(_lights); /* Set the shader information */ for (size_t i = 0; i < _lights.size(); i++) { - _color_shader->setLight(i, _lights[i]); - _texture_shader->setLight(i, _lights[i]); + _color_shader->set_light(i, _lights[i]); + _texture_shader->set_light(i, _lights[i]); } - if (_shadowTexture) { - _color_shader->bindShadowTexture(*_shadowTexture); - _texture_shader->bindShadowTexture(*_shadowTexture); + if (_shadow_texture) { + _color_shader->bind_shadow_texture(*_shadow_texture); + _texture_shader->bind_shadow_texture(*_shadow_texture); } - if (_shadowColorTexture) { - _color_shader->bindShadowColorTexture(*_shadowColorTexture); - _texture_shader->bindShadowColorTexture(*_shadowColorTexture); + if (_shadow_color_texture) { + _color_shader->bind_shadow_color_texture(*_shadow_color_texture); + _texture_shader->bind_shadow_color_texture(*_shadow_color_texture); } - if (_shadowCubeMap) { - _color_shader->bindCubeMapTexture(*_shadowCubeMap); - _texture_shader->bindCubeMapTexture(*_shadowCubeMap); + if (_shadow_cube_map) { + _color_shader->bind_cube_map_texture(*_shadow_cube_map); + _texture_shader->bind_cube_map_texture(*_shadow_cube_map); } - if (_shadowColorCubeMap) { - _color_shader->bindCubeMapColorTexture(*_shadowColorCubeMap); - _texture_shader->bindCubeMapColorTexture(*_shadowColorCubeMap); + if (_shadow_color_cube_map) { + _color_shader->bind_cube_map_color_texture(*_shadow_color_cube_map); + _texture_shader->bind_cube_map_color_texture(*_shadow_color_cube_map); } } - void BaseApplication::updateGraphics() + void BaseApplication::update_graphics() { /* Refresh the graphical models */ - _dartWorld->refresh(); + _dart_world->refresh(); /* For each update object */ - for (Magnum::DartIntegration::Object& object : _dartWorld->updatedShapeObjects()) { + for (Magnum::DartIntegration::Object& object : _dart_world->updatedShapeObjects()) { /* Get material information */ std::vector materials; std::vector> meshes; @@ -575,15 +248,15 @@ namespace robot_dart { gs::Material mat; if (object.drawData().materials[i].flags() & Magnum::Trade::PhongMaterialData::Flag::DiffuseTexture) { - mat.setDiffuseTexture(&(*object.drawData().textures[object.drawData().materials[i].diffuseTexture()])); + mat.set_diffuse_texture(&(*object.drawData().textures[object.drawData().materials[i].diffuseTexture()])); isColor = false; } - mat.ambientColor() = object.drawData().materials[i].ambientColor(); + mat.ambient_color() = object.drawData().materials[i].ambientColor(); if (isColor) - mat.diffuseColor() = object.drawData().materials[i].diffuseColor(); - if (!isColor || mat.diffuseColor().a() != 1.f) + mat.diffuse_color() = object.drawData().materials[i].diffuseColor(); + if (!isColor || mat.diffuse_color().a() != 1.f) transparent = true; - mat.specularColor() = object.drawData().materials[i].specularColor(); + mat.specular_color() = object.drawData().materials[i].specularColor(); mat.shininess() = object.drawData().materials[i].shininess(); scalings.push_back(object.drawData().scaling); @@ -600,25 +273,25 @@ namespace robot_dart { } /* Check if we already have it */ - auto it = _drawableObjects.insert(std::make_pair(&object, nullptr)); + auto it = _drawable_objects.insert(std::make_pair(&object, nullptr)); if (it.second) { /* If not, create a new object and add it to our drawables list */ auto drawableObject = new DrawableObject(meshes, materials, *_color_shader, *_texture_shader, static_cast(&(object.object())), &_drawables); - drawableObject->setSoftBodies(isSoftBody); - drawableObject->setScalings(scalings); - drawableObject->setTransparent(transparent); + drawableObject->set_soft_bodies(isSoftBody); + drawableObject->set_scalings(scalings); + drawableObject->set_transparent(transparent); auto shadowedObject = new ShadowedObject(meshes, *_shadow_shader, *_shadow_texture_shader, static_cast(&(object.object())), &_shadowed_drawables); - shadowedObject->setScalings(scalings); - shadowedObject->setMaterials(materials); + shadowedObject->set_scalings(scalings); + shadowedObject->set_materials(materials); auto cubeMapObject = new CubeMapShadowedObject(meshes, *_cubemap_shader, *_cubemap_texture_shader, static_cast(&(object.object())), &_cubemap_drawables); - cubeMapObject->setScalings(scalings); - cubeMapObject->setMaterials(materials); + cubeMapObject->set_scalings(scalings); + cubeMapObject->set_materials(materials); auto shadowedColorObject = new ShadowedColorObject(meshes, *_shadow_color_shader, *_shadow_texture_color_shader, static_cast(&(object.object())), &_shadowed_color_drawables); - shadowedColorObject->setScalings(scalings); - shadowedColorObject->setMaterials(materials); + shadowedColorObject->set_scalings(scalings); + shadowedColorObject->set_materials(materials); auto cubeMapColorObject = new CubeMapShadowedColorObject(meshes, *_cubemap_color_shader, *_cubemap_texture_color_shader, static_cast(&(object.object())), &_cubemap_color_drawables); - cubeMapColorObject->setScalings(scalings); - cubeMapColorObject->setMaterials(materials); + cubeMapColorObject->set_scalings(scalings); + cubeMapColorObject->set_materials(materials); auto obj = new ObjectStruct{}; obj->drawable = drawableObject; @@ -633,15 +306,15 @@ namespace robot_dart { /* Otherwise, update the mesh and the material data */ auto obj = it.first->second; - if (_drawTransparentShadows) { + if (_transparent_shadows) { /* Check if it was transparent before */ auto& mats = obj->drawable->materials(); bool any = false; for (size_t j = 0; j < mats.size(); j++) { // Assume textures are transparent objects so that everything gets drawn better // TO-DO: Check if this is okay to do? - bool isTextured = mats[j].hasDiffuseTexture(); - if (isTextured || mats[j].diffuseColor().a() != 1.f) { + bool isTextured = mats[j].has_diffuse_texture(); + if (isTextured || mats[j].diffuse_color().a() != 1.f) { any = true; break; } @@ -654,142 +327,141 @@ namespace robot_dart { _transparentSize--; } - // TO-DO: Do I need to re-set the shaders?! - obj->drawable->setMeshes(meshes).setMaterials(materials).setSoftBodies(isSoftBody).setScalings(scalings).setTransparent(transparent).setColorShader(*_color_shader).setTextureShader(*_texture_shader); - obj->shadowed->setMeshes(meshes).setMaterials(materials).setScalings(scalings); - obj->cubemapped->setMeshes(meshes).setMaterials(materials).setScalings(scalings); - obj->shadowed_color->setMeshes(meshes).setMaterials(materials).setScalings(scalings); - obj->cubemapped_color->setMeshes(meshes).setMaterials(materials).setScalings(scalings); + obj->drawable->set_meshes(meshes).set_materials(materials).set_soft_bodies(isSoftBody).set_scalings(scalings).set_transparent(transparent).set_color_shader(*_color_shader).set_texture_shader(*_texture_shader); + obj->shadowed->set_meshes(meshes).set_materials(materials).set_scalings(scalings); + obj->cubemapped->set_meshes(meshes).set_materials(materials).set_scalings(scalings); + obj->shadowed_color->set_meshes(meshes).set_materials(materials).set_scalings(scalings); + obj->cubemapped_color->set_meshes(meshes).set_materials(materials).set_scalings(scalings); } } - _dartWorld->clearUpdatedShapeObjects(); + _dart_world->clearUpdatedShapeObjects(); - if (_isShadowed) - prepareShadows(); + if (_shadowed) + _prepare_shadows(); - _color_shader->setIsShadowed(_isShadowed); - _texture_shader->setIsShadowed(_isShadowed); - _color_shader->setTransparentShadows(_drawTransparentShadows && _transparentSize > 0); - _texture_shader->setTransparentShadows(_drawTransparentShadows && _transparentSize > 0); + _color_shader->set_is_shadowed(_shadowed); + _texture_shader->set_is_shadowed(_shadowed); + _color_shader->set_transparent_shadows(_transparent_shadows && _transparentSize > 0); + _texture_shader->set_transparent_shadows(_transparent_shadows && _transparentSize > 0); - if (_isShadowed) - renderShadows(); + if (_shadowed) + render_shadows(); } - void BaseApplication::renderShadows() + void BaseApplication::render_shadows() { /* For each light */ for (size_t i = 0; i < _lights.size(); i++) { - bool isPointLight = (_lights[i].position().w() > 0.f) && (_lights[i].spotCutOff() >= M_PI / 2.0); + bool isPointLight = (_lights[i].position().w() > 0.f) && (_lights[i].spot_cut_off() >= M_PI / 2.0); bool cullFront = false; Magnum::Matrix4 cameraMatrix; - Magnum::Float farPlane = 20.f, nearPlane = 0.001f; - Magnum::Float proj_size = (farPlane - nearPlane) / 2.f; + Magnum::Float far_plane = 20.f, near_plane = 0.001f; + Magnum::Float proj_size = (far_plane - near_plane) / 2.f; if (!isPointLight) { /* Directional lights */ if (_lights[i].position().w() == 0.f) { - cameraMatrix = Magnum::Matrix4::lookAt(-_lights[i].position().xyz().normalized() * proj_size, {}, Magnum::Vector3::yAxis()); //_camera->cameraObject().transformation()[2].xyz()); //.invertedRigid(); + cameraMatrix = Magnum::Matrix4::lookAt(-_lights[i].position().xyz().normalized() * proj_size, {}, Magnum::Vector3::yAxis()); //_camera->camera_object().transformation()[2].xyz()); //.invertedRigid(); - (*_shadowCamera) + (*_shadow_camera) .setAspectRatioPolicy(Magnum::SceneGraph::AspectRatioPolicy::Extend) - .setProjectionMatrix(Magnum::Matrix4::orthographicProjection({proj_size, proj_size}, nearPlane, farPlane)) - .setViewport({_shadowMapSize, _shadowMapSize}); + .setProjectionMatrix(Magnum::Matrix4::orthographicProjection({proj_size, proj_size}, near_plane, far_plane)) + .setViewport({_shadow_map_size, _shadow_map_size}); cullFront = true; // if false, peter panning will be quite a bit, but has better acne } /* Spotlights */ - else if (_lights[i].spotCutOff() < M_PI / 2.0) { + else if (_lights[i].spot_cut_off() < M_PI / 2.0) { Magnum::Vector3 position = _lights[i].position().xyz(); - cameraMatrix = Magnum::Matrix4::lookAt(position, position + _lights[i].spotDirection().normalized(), Magnum::Vector3::yAxis()); + cameraMatrix = Magnum::Matrix4::lookAt(position, position + _lights[i].spot_direction().normalized(), Magnum::Vector3::yAxis()); - (*_shadowCamera) + (*_shadow_camera) .setAspectRatioPolicy(Magnum::SceneGraph::AspectRatioPolicy::Extend) - .setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(Magnum::Rad(_lights[i].spotCutOff() * 2.f), 1.f, nearPlane, farPlane)) - .setViewport({_shadowMapSize, _shadowMapSize}); + .setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(Magnum::Rad(_lights[i].spot_cut_off() * 2.f), 1.f, near_plane, far_plane)) + .setViewport({_shadow_map_size, _shadow_map_size}); } } /* Point lights */ else { - (*_shadowCamera) + (*_shadow_camera) .setAspectRatioPolicy(Magnum::SceneGraph::AspectRatioPolicy::Extend) - .setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(Magnum::Rad(Magnum::Math::Constants::piHalf()), 1.f, nearPlane, farPlane)) - .setViewport({_shadowMapSize, _shadowMapSize}); + .setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(Magnum::Rad(Magnum::Math::Constants::piHalf()), 1.f, near_plane, far_plane)) + .setViewport({_shadow_map_size, _shadow_map_size}); Magnum::Vector3 lightPos = _lights[i].position().xyz(); Magnum::Matrix4 matrices[6]; - matrices[0] = _shadowCamera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::xAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); - matrices[1] = _shadowCamera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos - Magnum::Vector3::xAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); - matrices[2] = _shadowCamera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::yAxis(), Magnum::Vector3::zAxis()).invertedRigid(); - matrices[3] = _shadowCamera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos - Magnum::Vector3::yAxis(), -Magnum::Vector3::zAxis()).invertedRigid(); - matrices[4] = _shadowCamera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::zAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); - matrices[5] = _shadowCamera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos - Magnum::Vector3::zAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); - - _cubemap_shader->setShadowMatrices(matrices); - _cubemap_shader->setLightPosition(lightPos); - _cubemap_shader->setFarPlane(farPlane); - _cubemap_shader->setLightIndex(i); - - _cubemap_texture_shader->setShadowMatrices(matrices); - _cubemap_texture_shader->setLightPosition(lightPos); - _cubemap_texture_shader->setFarPlane(farPlane); - _cubemap_texture_shader->setLightIndex(i); - - if (_drawTransparentShadows) { - _cubemap_color_shader->setShadowMatrices(matrices); - _cubemap_color_shader->setLightPosition(lightPos); - _cubemap_color_shader->setFarPlane(farPlane); - _cubemap_color_shader->setLightIndex(i); - - _cubemap_texture_color_shader->setShadowMatrices(matrices); - _cubemap_texture_color_shader->setLightPosition(lightPos); - _cubemap_texture_color_shader->setFarPlane(farPlane); - _cubemap_texture_color_shader->setLightIndex(i); - - if (_shadowCubeMap) { - _cubemap_color_shader->bindCubeMapTexture(*_shadowCubeMap); - _cubemap_texture_color_shader->bindCubeMapTexture(*_shadowCubeMap); + matrices[0] = _shadow_camera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::xAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); + matrices[1] = _shadow_camera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos - Magnum::Vector3::xAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); + matrices[2] = _shadow_camera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::yAxis(), Magnum::Vector3::zAxis()).invertedRigid(); + matrices[3] = _shadow_camera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos - Magnum::Vector3::yAxis(), -Magnum::Vector3::zAxis()).invertedRigid(); + matrices[4] = _shadow_camera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::zAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); + matrices[5] = _shadow_camera->projectionMatrix() * Magnum::Matrix4::lookAt(lightPos, lightPos - Magnum::Vector3::zAxis(), -Magnum::Vector3::yAxis()).invertedRigid(); + + _cubemap_shader->set_shadow_matrices(matrices); + _cubemap_shader->set_light_position(lightPos); + _cubemap_shader->set_far_plane(far_plane); + _cubemap_shader->set_light_index(i); + + _cubemap_texture_shader->set_shadow_matrices(matrices); + _cubemap_texture_shader->set_light_position(lightPos); + _cubemap_texture_shader->set_far_plane(far_plane); + _cubemap_texture_shader->set_light_index(i); + + if (_transparent_shadows) { + _cubemap_color_shader->set_shadow_matrices(matrices); + _cubemap_color_shader->set_light_position(lightPos); + _cubemap_color_shader->set_far_plane(far_plane); + _cubemap_color_shader->set_light_index(i); + + _cubemap_texture_color_shader->set_shadow_matrices(matrices); + _cubemap_texture_color_shader->set_light_position(lightPos); + _cubemap_texture_color_shader->set_far_plane(far_plane); + _cubemap_texture_color_shader->set_light_index(i); + + if (_shadow_cube_map) { + _cubemap_color_shader->bind_cube_map_texture(*_shadow_cube_map); + _cubemap_texture_color_shader->bind_cube_map_texture(*_shadow_cube_map); } } - _color_shader->setFarPlane(farPlane); - _texture_shader->setFarPlane(farPlane); + _color_shader->set_far_plane(far_plane); + _texture_shader->set_far_plane(far_plane); // cameraMatrix = Magnum::Matrix4::lookAt(lightPos, lightPos + Magnum::Vector3::xAxis(), -Magnum::Vector3::yAxis()); // No effect } - _shadowCameraObject->setTransformation(cameraMatrix); + _shadow_camera_object->setTransformation(cameraMatrix); Magnum::Matrix4 bias{{0.5f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.5f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.5f, 0.0f}, {0.5f, 0.5f, 0.5f, 1.0f}}; - _lights[i].setShadowMatrix(bias * _shadowCamera->projectionMatrix() * cameraMatrix.invertedRigid()); + _lights[i].set_shadow_matrix(bias * _shadow_camera->projectionMatrix() * cameraMatrix.invertedRigid()); Magnum::GL::Renderer::setDepthMask(true); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::DepthTest); if (cullFront) Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Front); - _shadowData[i].shadowFramebuffer.bind(); + _shadow_data[i].shadow_framebuffer.bind(); if (isPointLight) { /* Clear layer-by-layer of the cube-map texture array */ for (size_t k = 0; k < 6; k++) { - _shadowData[i].shadowFramebuffer.attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowCubeMap, 0, i * 6 + k); - _shadowData[i].shadowFramebuffer.clear(Magnum::GL::FramebufferClear::Depth); + _shadow_data[i].shadow_framebuffer.attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_cube_map, 0, i * 6 + k); + _shadow_data[i].shadow_framebuffer.clear(Magnum::GL::FramebufferClear::Depth); } /* Attach again the full texture */ - _shadowData[i].shadowFramebuffer.attachLayeredTexture(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowCubeMap, 0); + _shadow_data[i].shadow_framebuffer.attachLayeredTexture(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_cube_map, 0); } else - _shadowData[i].shadowFramebuffer.clear(Magnum::GL::FramebufferClear::Depth); + _shadow_data[i].shadow_framebuffer.clear(Magnum::GL::FramebufferClear::Depth); if (!isPointLight) - _shadowCamera->draw(_shadowed_drawables); + _shadow_camera->draw(_shadowed_drawables); else - _shadowCamera->draw(_cubemap_drawables); + _shadow_camera->draw(_cubemap_drawables); if (cullFront) Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Back); /* Transparent color shadow: main ideas taken from https://wickedengine.net/2018/01/18/easy-transparent-shadow-maps/ */ - if (_drawTransparentShadows && _transparentSize > 0) { + if (_transparent_shadows && _transparentSize > 0) { Magnum::GL::Renderer::setDepthMask(false); Magnum::GL::Renderer::setColorMask(true, true, true, true); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::DepthTest); @@ -800,27 +472,27 @@ namespace robot_dart { if (cullFront) Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Front); - _shadowData[i].shadowColorFramebuffer.bind(); + _shadow_data[i].shadow_color_framebuffer.bind(); if (isPointLight) { /* Clear layer-by-layer of the cube-map texture array */ for (size_t k = 0; k < 6; k++) { - _shadowData[i].shadowColorFramebuffer.attachTextureLayer(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadowColorCubeMap, 0, i * 6 + k); - _shadowData[i].shadowColorFramebuffer.clear(Magnum::GL::FramebufferClear::Color); + _shadow_data[i].shadow_color_framebuffer.attachTextureLayer(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadow_color_cube_map, 0, i * 6 + k); + _shadow_data[i].shadow_color_framebuffer.clear(Magnum::GL::FramebufferClear::Color); } /* Attach again the full texture */ - _shadowData[i].shadowColorFramebuffer.attachLayeredTexture(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadowColorCubeMap, 0); - // _shadowData[i].shadowColorFramebuffer.attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowCubeMap, 0, i * 6); + _shadow_data[i].shadow_color_framebuffer.attachLayeredTexture(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadow_color_cube_map, 0); + // _shadow_data[i].shadow_color_framebuffer.attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_cube_map, 0, i * 6); } else - _shadowData[i].shadowColorFramebuffer.clear(Magnum::GL::FramebufferClear::Color); + _shadow_data[i].shadow_color_framebuffer.clear(Magnum::GL::FramebufferClear::Color); /* Draw only transparent objects for transparent shadow color */ std::vector, Magnum::Matrix4>> drawableTransformations; if (!isPointLight) - drawableTransformations = _shadowCamera->drawableTransformations(_shadowed_color_drawables); + drawableTransformations = _shadow_camera->drawableTransformations(_shadowed_color_drawables); else - drawableTransformations = _shadowCamera->drawableTransformations(_cubemap_color_drawables); + drawableTransformations = _shadow_camera->drawableTransformations(_cubemap_color_drawables); std::vector, Magnum::Matrix4>> opaque, transparent; for (size_t i = 0; i < drawableTransformations.size(); i++) { @@ -830,8 +502,8 @@ namespace robot_dart { for (size_t j = 0; j < mats.size(); j++) { // Assume textures are transparent objects so that everything gets drawn better // TO-DO: Check if this is okay to do? - bool isTextured = mats[j].hasDiffuseTexture(); - if (isTextured || mats[j].diffuseColor().a() != 1.f) { + bool isTextured = mats[j].has_diffuse_texture(); + if (isTextured || mats[j].diffuse_color().a() != 1.f) { any = true; break; } @@ -843,7 +515,7 @@ namespace robot_dart { } if (transparent.size() > 0) - _shadowCamera->draw(transparent); + _shadow_camera->draw(transparent); if (cullFront) Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Back); @@ -854,15 +526,15 @@ namespace robot_dart { } } - bool BaseApplication::attachCamera(gs::Camera& camera, const std::string& name) + bool BaseApplication::attach_camera(gs::Camera& camera, const std::string& name) { - for (Magnum::DartIntegration::Object& object : _dartWorld->objects()) { + for (Magnum::DartIntegration::Object& object : _dart_world->objects()) { if (object.bodyNode() && object.bodyNode()->getName() == name) { - camera.cameraObject().setParent(static_cast(&object.object())); + camera.camera_object().setParent(static_cast(&object.object())); return true; } if (object.shapeNode() && object.shapeNode()->getName() == name) { - camera.cameraObject().setParent(static_cast(&object.object())); + camera.camera_object().setParent(static_cast(&object.object())); return true; } } @@ -870,18 +542,18 @@ namespace robot_dart { return false; } - void BaseApplication::enableShadows(bool enable, bool drawTransparentShadows) + void BaseApplication::enable_shadows(bool enable, bool drawTransparentShadows) { - _isShadowed = enable; - _drawTransparentShadows = drawTransparentShadows; + _shadowed = enable; + _transparent_shadows = drawTransparentShadows; #ifdef MAGNUM_MAC_OSX - ROBOT_DART_WARNING(_isShadowed, "Shadows are not working properly on Mac! Disable them if you experience unexpected behavior.."); + ROBOT_DART_WARNING(_shadowed, "Shadows are not working properly on Mac! Disable them if you experience unexpected behavior.."); #endif } - GrayscaleImage BaseApplication::depthImage() + GrayscaleImage BaseApplication::depth_image() { - auto& depth_image = _camera->depthImage(); + auto& depth_image = _camera->depth_image(); if (!depth_image) return GrayscaleImage(); auto pixels = depth_image->pixels(); @@ -898,8 +570,8 @@ namespace robot_dart { Magnum::Float depth = pixels[height - 1 - h][w]; /* Linearize depth for visualization */ - Magnum::Float zNear = _camera->nearPlane(); - Magnum::Float zFar = _camera->farPlane(); + Magnum::Float zNear = _camera->near_plane(); + Magnum::Float zFar = _camera->far_plane(); Magnum::Float val = (2.f * zNear) / (zFar + zNear - depth * (zFar - zNear)); img[w][h] = val * 255.f; } @@ -908,9 +580,9 @@ namespace robot_dart { return img; } - GrayscaleImage BaseApplication::rawDepthImage() + GrayscaleImage BaseApplication::raw_depth_image() { - auto& depth_image = _camera->depthImage(); + auto& depth_image = _camera->depth_image(); if (!depth_image) return GrayscaleImage(); auto pixels = depth_image->pixels(); @@ -932,7 +604,7 @@ namespace robot_dart { return img; } - void BaseApplication::GLCleanUp() + void BaseApplication::_gl_clean_up() { /* Clean up GL because of destructor order */ _color_shader.reset(); @@ -945,29 +617,29 @@ namespace robot_dart { _cubemap_texture_shader.reset(); _cubemap_color_shader.reset(); _cubemap_texture_color_shader.reset(); - _shadowTexture.reset(); - _shadowColorTexture.reset(); - _shadowCubeMap.reset(); - _shadowColorCubeMap.reset(); + _shadow_texture.reset(); + _shadow_color_texture.reset(); + _shadow_cube_map.reset(); + _shadow_color_cube_map.reset(); _camera.reset(); - _shadowCamera.reset(); + _shadow_camera.reset(); - _dartWorld.reset(); - for (auto& it : _drawableObjects) + _dart_world.reset(); + for (auto& it : _drawable_objects) delete it.second; - _drawableObjects.clear(); - _dartObjs.clear(); + _drawable_objects.clear(); + _dart_objects.clear(); _lights.clear(); - _shadowData.clear(); + _shadow_data.clear(); } - void BaseApplication::prepareShadows() + void BaseApplication::_prepare_shadows() { /* Shadow Textures */ - if (!_shadowTexture) { - _shadowTexture.reset(new Magnum::GL::Texture2DArray{}); - _shadowTexture->setStorage(1, Magnum::GL::TextureFormat::DepthComponent24, {_shadowMapSize, _shadowMapSize, _maxLights}) + if (!_shadow_texture) { + _shadow_texture.reset(new Magnum::GL::Texture2DArray{}); + _shadow_texture->setStorage(1, Magnum::GL::TextureFormat::DepthComponent24, {_shadow_map_size, _shadow_map_size, _max_lights}) .setCompareFunction(Magnum::GL::SamplerCompareFunction::LessOrEqual) .setCompareMode(Magnum::GL::SamplerCompareMode::CompareRefToTexture) .setMinificationFilter(Magnum::GL::SamplerFilter::Linear, Magnum::GL::SamplerMipmap::Base) @@ -975,9 +647,9 @@ namespace robot_dart { // .setWrapping(Magnum::GL::SamplerWrapping::ClampToEdge); } - if (_drawTransparentShadows && !_shadowColorTexture) { - _shadowColorTexture.reset(new Magnum::GL::Texture2DArray{}); - _shadowColorTexture->setStorage(1, Magnum::GL::TextureFormat::RGBA32F, {_shadowMapSize, _shadowMapSize, _maxLights}) + if (_transparent_shadows && !_shadow_color_texture) { + _shadow_color_texture.reset(new Magnum::GL::Texture2DArray{}); + _shadow_color_texture->setStorage(1, Magnum::GL::TextureFormat::RGBA32F, {_shadow_map_size, _shadow_map_size, _max_lights}) .setCompareFunction(Magnum::GL::SamplerCompareFunction::LessOrEqual) .setCompareMode(Magnum::GL::SamplerCompareMode::CompareRefToTexture) .setMinificationFilter(Magnum::GL::SamplerFilter::Linear, Magnum::GL::SamplerMipmap::Base) @@ -985,9 +657,9 @@ namespace robot_dart { .setDepthStencilMode(Magnum::GL::SamplerDepthStencilMode::DepthComponent); } - if (!_shadowCubeMap) { - _shadowCubeMap.reset(new Magnum::GL::CubeMapTextureArray{}); - _shadowCubeMap->setStorage(1, Magnum::GL::TextureFormat::DepthComponent24, {_shadowMapSize, _shadowMapSize, _maxLights * 6}) + if (!_shadow_cube_map) { + _shadow_cube_map.reset(new Magnum::GL::CubeMapTextureArray{}); + _shadow_cube_map->setStorage(1, Magnum::GL::TextureFormat::DepthComponent24, {_shadow_map_size, _shadow_map_size, _max_lights * 6}) .setCompareFunction(Magnum::GL::SamplerCompareFunction::LessOrEqual) .setCompareMode(Magnum::GL::SamplerCompareMode::CompareRefToTexture) .setMinificationFilter(Magnum::GL::SamplerFilter::Linear, Magnum::GL::SamplerMipmap::Base) @@ -996,9 +668,9 @@ namespace robot_dart { .setDepthStencilMode(Magnum::GL::SamplerDepthStencilMode::DepthComponent); } - if (_drawTransparentShadows && !_shadowColorCubeMap) { - _shadowColorCubeMap.reset(new Magnum::GL::CubeMapTextureArray{}); - _shadowColorCubeMap->setStorage(1, Magnum::GL::TextureFormat::RGBA32F, {_shadowMapSize, _shadowMapSize, _maxLights * 6}) + if (_transparent_shadows && !_shadow_color_cube_map) { + _shadow_color_cube_map.reset(new Magnum::GL::CubeMapTextureArray{}); + _shadow_color_cube_map->setStorage(1, Magnum::GL::TextureFormat::RGBA32F, {_shadow_map_size, _shadow_map_size, _max_lights * 6}) .setCompareFunction(Magnum::GL::SamplerCompareFunction::LessOrEqual) .setCompareMode(Magnum::GL::SamplerCompareMode::CompareRefToTexture) .setMinificationFilter(Magnum::GL::SamplerFilter::Linear, Magnum::GL::SamplerMipmap::Base) @@ -1010,48 +682,48 @@ namespace robot_dart { /* For each light */ for (size_t i = 0; i < _lights.size(); i++) { /* There's no shadow texture/framebuffer for this light */ - if (_shadowData.size() <= i) { - bool isPointLight = (_lights[i].position().w() > 0.f) && (_lights[i].spotCutOff() >= M_PI / 2.0); + if (_shadow_data.size() <= i) { + bool isPointLight = (_lights[i].position().w() > 0.f) && (_lights[i].spot_cut_off() >= M_PI / 2.0); - _shadowData.push_back({}); + _shadow_data.push_back({}); - _shadowData[i].shadowFramebuffer = Magnum::GL::Framebuffer({{}, {_shadowMapSize, _shadowMapSize}}); - if (_drawTransparentShadows) - _shadowData[i].shadowColorFramebuffer = Magnum::GL::Framebuffer({{}, {_shadowMapSize, _shadowMapSize}}); + _shadow_data[i].shadow_framebuffer = Magnum::GL::Framebuffer({{}, {_shadow_map_size, _shadow_map_size}}); + if (_transparent_shadows) + _shadow_data[i].shadow_color_framebuffer = Magnum::GL::Framebuffer({{}, {_shadow_map_size, _shadow_map_size}}); if (!isPointLight) { - (_shadowData[i].shadowFramebuffer) - .attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowTexture, 0, i) + (_shadow_data[i].shadow_framebuffer) + .attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_texture, 0, i) .mapForDraw(Magnum::GL::Framebuffer::DrawAttachment::None) .bind(); - if (_drawTransparentShadows) - (_shadowData[i].shadowColorFramebuffer) - .attachTextureLayer(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadowColorTexture, 0, i) - .attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowTexture, 0, i) + if (_transparent_shadows) + (_shadow_data[i].shadow_color_framebuffer) + .attachTextureLayer(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadow_color_texture, 0, i) + .attachTextureLayer(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_texture, 0, i) .bind(); } else { - (_shadowData[i].shadowFramebuffer) + (_shadow_data[i].shadow_framebuffer) .mapForDraw(Magnum::GL::Framebuffer::DrawAttachment::None) - .attachLayeredTexture(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowCubeMap, 0) + .attachLayeredTexture(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_cube_map, 0) .bind(); - if (_drawTransparentShadows) - (_shadowData[i].shadowColorFramebuffer) - .attachLayeredTexture(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadowColorCubeMap, 0) - // .attachLayeredTexture(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadowCubeMap, 0) + if (_transparent_shadows) + (_shadow_data[i].shadow_color_framebuffer) + .attachLayeredTexture(Magnum::GL::Framebuffer::ColorAttachment(0), *_shadow_color_cube_map, 0) + // .attachLayeredTexture(Magnum::GL::Framebuffer::BufferAttachment::Depth, *_shadow_cube_map, 0) .bind(); } /* Check if the creation of the framebuffer was successful */ - if (!(_shadowData[i].shadowFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw) == Magnum::GL::Framebuffer::Status::Complete) - || (_drawTransparentShadows && !(_shadowData[i].shadowColorFramebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw) == Magnum::GL::Framebuffer::Status::Complete))) { - _isShadowed = false; + if (!(_shadow_data[i].shadow_framebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw) == Magnum::GL::Framebuffer::Status::Complete) + || (_transparent_shadows && !(_shadow_data[i].shadow_color_framebuffer.checkStatus(Magnum::GL::FramebufferTarget::Draw) == Magnum::GL::Framebuffer::Status::Complete))) { + _shadowed = false; break; } } } - ROBOT_DART_WARNING(!_isShadowed, "Something bad happened when configuring shadows! Disabling them!"); + ROBOT_DART_WARNING(!_shadowed, "Something bad happened when configuring shadows! Disabling them!"); } } // namespace magnum } // namespace gui diff --git a/src/robot_dart/gui/magnum/base_application.hpp b/src/robot_dart/gui/magnum/base_application.hpp index 367c5b24..8041fc00 100644 --- a/src/robot_dart/gui/magnum/base_application.hpp +++ b/src/robot_dart/gui/magnum/base_application.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #else #include #endif -#include #include @@ -81,154 +81,33 @@ namespace robot_dart { size_t _max_contexts = 4; }; - class DrawableObject : public Object3D, Magnum::SceneGraph::Drawable3D { - public: - explicit DrawableObject( - const std::vector>& meshes, - const std::vector& materials, - std::reference_wrapper color, - std::reference_wrapper texture, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group); - - DrawableObject& setMeshes(const std::vector>& meshes); - DrawableObject& setMaterials(const std::vector& materials); - DrawableObject& setSoftBodies(const std::vector& softBody); - DrawableObject& setScalings(const std::vector& scalings); - DrawableObject& setTransparent(bool transparent = true); - - DrawableObject& setColorShader(std::reference_wrapper shader); - DrawableObject& setTextureShader(std::reference_wrapper shader); - - const std::vector& materials() const { return _materials; } - bool isTransparent() const { return _isTransparent; } - - private: - void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; - - std::vector> _meshes; - std::reference_wrapper _color_shader; - std::reference_wrapper _texture_shader; - std::vector _materials; - std::vector _scalings; - std::vector _hasNegativeScaling; - std::vector _isSoftBody; - bool _isTransparent; - }; - - class ShadowedObject : public Object3D, Magnum::SceneGraph::Drawable3D { - public: - explicit ShadowedObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group); - - ShadowedObject& setMeshes(const std::vector>& meshes); - ShadowedObject& setMaterials(const std::vector& materials); - ShadowedObject& setScalings(const std::vector& scalings); - - private: - void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; + struct GraphicsConfiguration { + // General + size_t width = 640; + size_t height = 480; + std::string title = "DART"; - std::vector> _meshes; - std::reference_wrapper _shader, _texture_shader; - std::vector _materials; - std::vector _scalings; - }; - - class ShadowedColorObject : public Object3D, Magnum::SceneGraph::Drawable3D { - public: - explicit ShadowedColorObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group); - - ShadowedColorObject& setMeshes(const std::vector>& meshes); - ShadowedColorObject& setMaterials(const std::vector& materials); - ShadowedColorObject& setScalings(const std::vector& scalings); - - private: - void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; - - std::vector> _meshes; - std::reference_wrapper _shader, _texture_shader; - std::vector _materials; - std::vector _scalings; - }; - - class CubeMapShadowedObject : public Object3D, Magnum::SceneGraph::Drawable3D { - public: - explicit CubeMapShadowedObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group); - - CubeMapShadowedObject& setMeshes(const std::vector>& meshes); - CubeMapShadowedObject& setMaterials(const std::vector& materials); - CubeMapShadowedObject& setScalings(const std::vector& scalings); - - private: - void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; - - std::vector> _meshes; - std::reference_wrapper _shader, _texture_shader; - std::vector _materials; - std::vector _scalings; - }; - - class CubeMapShadowedColorObject : public Object3D, Magnum::SceneGraph::Drawable3D { - public: - explicit CubeMapShadowedColorObject( - const std::vector>& meshes, - std::reference_wrapper shader, - std::reference_wrapper texture_shader, - Object3D* parent, - Magnum::SceneGraph::DrawableGroup3D* group); - - CubeMapShadowedColorObject& setMeshes(const std::vector>& meshes); - CubeMapShadowedColorObject& setMaterials(const std::vector& materials); - CubeMapShadowedColorObject& setScalings(const std::vector& scalings); - - private: - void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; - - std::vector> _meshes; - std::reference_wrapper _shader, _texture_shader; - std::vector _materials; - std::vector _scalings; - }; - - struct ShadowData { - Magnum::GL::Framebuffer shadowFramebuffer{Magnum::NoCreate}; - Magnum::GL::Framebuffer shadowColorFramebuffer{Magnum::NoCreate}; - }; + // Shadows + bool shadowed = true; + bool transparent_shadows = true; + size_t shadow_map_size = 512; - struct ObjectStruct { - DrawableObject* drawable; - ShadowedObject* shadowed; - ShadowedColorObject* shadowed_color; - CubeMapShadowedObject* cubemapped; - CubeMapShadowedColorObject* cubemapped_color; + // Lights + size_t max_lights = 3; }; class BaseApplication { public: - BaseApplication(bool isShadowed = true, bool drawTransparentShadows = true); + BaseApplication(const GraphicsConfiguration& configuration = GraphicsConfiguration()); virtual ~BaseApplication() {} void init(const dart::simulation::WorldPtr& world, size_t width, size_t height); - void clearLights(); - void addLight(const gs::Light& light); + void clear_lights(); + void add_light(const gs::Light& light); gs::Light& light(size_t i); std::vector& lights(); - size_t numLights() const; + size_t num_lights() const; Magnum::SceneGraph::DrawableGroup3D& drawables() { return _drawables; } Scene3D& scene() { return _scene; } @@ -236,32 +115,32 @@ namespace robot_dart { bool done() const; - void lookAt(const Eigen::Vector3d& camera_pos, + void look_at(const Eigen::Vector3d& camera_pos, const Eigen::Vector3d& look_at, const Eigen::Vector3d& up); virtual void render() {} - void updateLights(const gs::Camera& camera); - void updateGraphics(); - void renderShadows(); - bool attachCamera(gs::Camera& camera, const std::string& name); + void update_lights(const gs::Camera& camera); + void update_graphics(); + void render_shadows(); + bool attach_camera(gs::Camera& camera, const std::string& name); void record(bool recording, bool depthRecording = false) { _camera->record(recording, depthRecording); } - bool isRecording() { return _camera->isRecording(); } - bool isDepthRecording() { return _camera->isDepthRecording(); } + bool recording() { return _camera->recording(); } + bool recording_depth() { return _camera->recording_depth(); } - bool isShadowed() const { return _isShadowed; } - bool transparentShadows() const { return _drawTransparentShadows; } - void enableShadows(bool enable = true, bool drawTransparentShadows = false); + bool shadowed() const { return _shadowed; } + bool transparent_shadows() const { return _transparent_shadows; } + void enable_shadows(bool enable = true, bool drawTransparentShadows = false); Corrade::Containers::Optional& image() { return _camera->image(); } // This is for visualization purposes - GrayscaleImage depthImage(); + GrayscaleImage depth_image(); // Image filled with depth buffer values - GrayscaleImage rawDepthImage(); + GrayscaleImage raw_depth_image(); protected: /* Magnum */ @@ -274,38 +153,39 @@ namespace robot_dart { bool _done = false; /* DART */ - std::unique_ptr _dartWorld; - std::unordered_map _drawableObjects; - std::vector _dartObjs; + std::unique_ptr _dart_world; + std::unordered_map _drawable_objects; + std::vector _dart_objects; std::vector _lights; /* Shadows */ - bool _isShadowed = true, _drawTransparentShadows = false; + bool _shadowed = true, _transparent_shadows = false; int _transparentSize = 0; std::unique_ptr _shadow_shader, _shadow_texture_shader; std::unique_ptr _shadow_color_shader, _shadow_texture_color_shader; std::unique_ptr _cubemap_shader, _cubemap_texture_shader; std::unique_ptr _cubemap_color_shader, _cubemap_texture_color_shader; - std::vector _shadowData; - std::unique_ptr _shadowTexture, _shadowColorTexture; - std::unique_ptr _shadowCubeMap, _shadowColorCubeMap; - int _shadowMapSize = 512; - int _maxLights = 5; - std::unique_ptr _shadowCamera; - Object3D* _shadowCameraObject; + std::vector _shadow_data; + std::unique_ptr _shadow_texture, _shadow_color_texture; + std::unique_ptr _shadow_cube_map, _shadow_color_cube_map; + int _max_lights = 5; + int _shadow_map_size = 512; + std::unique_ptr _shadow_camera; + Object3D* _shadow_camera_object; Corrade::PluginManager::Manager _importer_manager; - void GLCleanUp(); - void prepareShadows(); + void _gl_clean_up(); + void _prepare_shadows(); }; template - inline BaseApplication* make_application(const dart::simulation::WorldPtr& world, size_t width, size_t height, const std::string& title = "DART", bool isShadowed = true, bool drawTransparentShadows = true) + inline BaseApplication* make_application(const dart::simulation::WorldPtr& world, const GraphicsConfiguration& configuration = GraphicsConfiguration()) { int argc = 0; char** argv = NULL; - return new T(argc, argv, world, width, height, title, isShadowed, drawTransparentShadows); + return new T(argc, argv, world, configuration); + // configuration.width, configuration.height, configuration.shadowed, configuration.transparent_shadows, configuration.max_lights, configuration.shadow_map_size); } } // namespace magnum } // namespace gui diff --git a/src/robot_dart/gui/magnum/camera_osr.cpp b/src/robot_dart/gui/magnum/camera_osr.cpp index 1fd584b2..b507fae0 100644 --- a/src/robot_dart/gui/magnum/camera_osr.cpp +++ b/src/robot_dart/gui/magnum/camera_osr.cpp @@ -84,7 +84,7 @@ namespace robot_dart { float uy = static_cast(up[1]); float uz = static_cast(up[2]); - _camera->lookAt(Magnum::Vector3{cx, cy, cz}, + _camera->look_at(Magnum::Vector3{cx, cy, cz}, Magnum::Vector3{lx, ly, lz}, Magnum::Vector3{ux, uy, uz}); } @@ -92,9 +92,9 @@ namespace robot_dart { void CameraOSR::render() { /* Update graphic meshes/materials and render */ - _magnum_app->updateGraphics(); + _magnum_app->update_graphics(); /* Update lights transformations */ - _magnum_app->updateLights(*_camera); + _magnum_app->update_lights(*_camera); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::DepthTest); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::FaceCulling); @@ -116,7 +116,7 @@ namespace robot_dart { GrayscaleImage CameraOSR::depth_image() { - auto& depth_image = _camera->depthImage(); + auto& depth_image = _camera->depth_image(); if (!depth_image) return GrayscaleImage(); auto pixels = depth_image->pixels(); @@ -133,8 +133,8 @@ namespace robot_dart { Magnum::Float depth = pixels[height - 1 - h][w]; /* Linearize depth for visualization */ - Magnum::Float zNear = _camera->nearPlane(); - Magnum::Float zFar = _camera->farPlane(); + Magnum::Float zNear = _camera->near_plane(); + Magnum::Float zFar = _camera->far_plane(); Magnum::Float val = (2.f * zNear) / (zFar + zNear - depth * (zFar - zNear)); img[w][h] = val * 255.f; } @@ -145,7 +145,7 @@ namespace robot_dart { GrayscaleImage CameraOSR::raw_depth_image() { - auto& depth_image = _camera->depthImage(); + auto& depth_image = _camera->depth_image(); if (!depth_image) return GrayscaleImage(); auto pixels = depth_image->pixels(); @@ -169,7 +169,7 @@ namespace robot_dart { // std::vector CameraOSR::point_cloud() // { - // Magnum::Image2D depth_image = _camera->depthImage(); + // Magnum::Image2D depth_image = _camera->depth_image(); // auto pixels = depth_image.pixels(); // auto sz = pixels.size(); @@ -203,7 +203,7 @@ namespace robot_dart { _attached = false; _attached_tf = tf; - _attached = _magnum_app->attachCamera(*_camera, name); + _attached = _magnum_app->attach_camera(*_camera, name); if (_attached) { _attaching = false; @@ -225,8 +225,8 @@ namespace robot_dart { Magnum::Rad theta(angle); /* Pass it to Magnum */ - _camera->cameraObject().setTransformation({}); - _camera->cameraObject().rotate(theta, u).translate(t); + _camera->camera_object().setTransformation({}); + _camera->camera_object().rotate(theta, u).translate(t); } } } // namespace magnum diff --git a/src/robot_dart/gui/magnum/camera_osr.hpp b/src/robot_dart/gui/magnum/camera_osr.hpp index e02416fe..e4fc62d7 100644 --- a/src/robot_dart/gui/magnum/camera_osr.hpp +++ b/src/robot_dart/gui/magnum/camera_osr.hpp @@ -27,8 +27,8 @@ namespace robot_dart { void render(); void set_recording(bool recording, bool recording_depth = false) { _camera->record(recording, recording_depth); } - bool recording() { return _camera->isRecording(); } - bool recording_depth() { return _camera->isDepthRecording(); } + bool recording() { return _camera->recording(); } + bool recording_depth() { return _camera->recording_depth(); } Magnum::Image2D* magnum_image() { @@ -47,8 +47,8 @@ namespace robot_dart { Magnum::Image2D* magnum_depth_image() { - if (_camera->depthImage()) - return &(*_camera->depthImage()); + if (_camera->depth_image()) + return &(*_camera->depth_image()); return nullptr; } @@ -64,15 +64,15 @@ namespace robot_dart { virtual void attach_to(const std::string& name, const Eigen::Isometry3d& tf); - void set_speed(const Magnum::Vector2& speed) { _camera->setSpeed(speed); } - void set_near_plane(double near_plane) { _camera->setNearPlane(near_plane); } - void set_far_plane(double far_plane) { _camera->setFarPlane(far_plane); } - void set_fov(double fov) { _camera->setFOV(fov); } - void set_camera_params(double near_plane, double far_plane, double fov, size_t width, size_t height) { _camera->setCameraParameters(near_plane, far_plane, fov, width, height); } + void set_speed(const Magnum::Vector2& speed) { _camera->set_speed(speed); } + void set_near_plane(double near_plane) { _camera->set_near_plane(near_plane); } + void set_far_plane(double far_plane) { _camera->set_far_plane(far_plane); } + void set_fov(double fov) { _camera->set_fov(fov); } + void set_camera_params(double near_plane, double far_plane, double fov, size_t width, size_t height) { _camera->set_camera_params(near_plane, far_plane, fov, width, height); } Magnum::Vector2 speed() const { return _camera->speed(); } - double near_plane() const { return _camera->nearPlane(); } - double far_plane() const { return _camera->farPlane(); } + double near_plane() const { return _camera->near_plane(); } + double far_plane() const { return _camera->far_plane(); } double fov() const { return _camera->fov(); } protected: diff --git a/src/robot_dart/gui/magnum/drawables.cpp b/src/robot_dart/gui/magnum/drawables.cpp new file mode 100644 index 00000000..c2c34f01 --- /dev/null +++ b/src/robot_dart/gui/magnum/drawables.cpp @@ -0,0 +1,335 @@ +#include +#include + +#include +#include +#include +#include + +#include +#include + +namespace robot_dart { + namespace gui { + namespace magnum { + // DrawableObject + DrawableObject::DrawableObject( + const std::vector>& meshes, + const std::vector& materials, + gs::PhongMultiLight& color, + gs::PhongMultiLight& texture, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group) + : Object3D{parent}, + Magnum::SceneGraph::Drawable3D{*this, group}, + _meshes{meshes}, + _color_shader{color}, + _texture_shader{texture}, + _materials(materials) + { + _is_soft_body.resize(_meshes.size(), false); + } + + DrawableObject& DrawableObject::set_meshes(const std::vector>& meshes) + { + _meshes = meshes; + return *this; + } + + DrawableObject& DrawableObject::set_materials(const std::vector& materials) + { + _materials = materials; + return *this; + } + + DrawableObject& DrawableObject::set_soft_bodies(const std::vector& softBody) + { + _is_soft_body = softBody; + return *this; + } + + DrawableObject& DrawableObject::set_scalings(const std::vector& scalings) + { + _scalings = scalings; + + _has_negative_scaling.resize(_scalings.size()); + for (size_t i = 0; i < scalings.size(); i++) { + _has_negative_scaling[i] = false; + for (size_t j = 0; j < 3; j++) + if (_scalings[i][j] < 0.f) { + _has_negative_scaling[i] = true; + break; + } + } + + return *this; + } + + DrawableObject& DrawableObject::set_transparent(bool transparent) + { + _isTransparent = transparent; + return *this; + } + + DrawableObject& DrawableObject::set_color_shader(std::reference_wrapper shader) + { + _color_shader = shader; + return *this; + } + + DrawableObject& DrawableObject::set_texture_shader(std::reference_wrapper shader) + { + _texture_shader = shader; + return *this; + } + + void DrawableObject::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) + { + for (size_t i = 0; i < _meshes.size(); i++) { + Magnum::GL::Mesh& mesh = _meshes[i]; + Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); + bool isColor = !_materials[i].has_diffuse_texture(); + if (_is_soft_body[i]) + Magnum::GL::Renderer::disable(Magnum::GL::Renderer::Feature::FaceCulling); + else if (_has_negative_scaling[i]) + Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Front); + if (isColor) { + _color_shader.get() + .set_material(_materials[i]) + .set_transformation_matrix(absoluteTransformationMatrix() * scalingMatrix) + .set_normal_matrix((transformationMatrix * scalingMatrix).rotationScaling()) + .set_camera_matrix(camera.cameraMatrix()) + .set_projection_matrix(camera.projectionMatrix()) + .draw(mesh); + } + else { + _texture_shader.get() + .set_material(_materials[i]) + .set_transformation_matrix(absoluteTransformationMatrix() * scalingMatrix) + .set_normal_matrix((transformationMatrix * scalingMatrix).rotationScaling()) + .set_camera_matrix(camera.cameraMatrix()) + .set_projection_matrix(camera.projectionMatrix()) + .draw(mesh); + } + + if (_is_soft_body[i]) + Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::FaceCulling); + else if (_has_negative_scaling[i]) + Magnum::GL::Renderer::setFaceCullingMode(Magnum::GL::Renderer::PolygonFacing::Back); + } + } + + // ShadowedObject + ShadowedObject::ShadowedObject( + const std::vector>& meshes, + gs::ShadowMap& shader, + gs::ShadowMap& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group) + : Object3D{parent}, + Magnum::SceneGraph::Drawable3D{*this, group}, + _meshes{meshes}, + _shader{shader}, + _texture_shader(texture_shader) {} + + ShadowedObject& ShadowedObject::set_meshes(const std::vector>& meshes) + { + _meshes = meshes; + return *this; + } + + ShadowedObject& ShadowedObject::set_materials(const std::vector& materials) + { + _materials = materials; + return *this; + } + + ShadowedObject& ShadowedObject::set_scalings(const std::vector& scalings) + { + _scalings = scalings; + return *this; + } + + void ShadowedObject::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) + { + for (size_t i = 0; i < _meshes.size(); i++) { + Magnum::GL::Mesh& mesh = _meshes[i]; + Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); + bool isColor = !_materials[i].has_diffuse_texture(); + if (isColor) { + (_shader.get()) + .set_transformation_matrix(transformationMatrix * scalingMatrix) + .set_projection_matrix(camera.projectionMatrix()) + .set_material(_materials[i]) + .draw(mesh); + } + else { + (_texture_shader.get()) + .set_transformation_matrix(transformationMatrix * scalingMatrix) + .set_projection_matrix(camera.projectionMatrix()) + .set_material(_materials[i]) + .draw(mesh); + } + } + } + + // ShadowedColorObject + ShadowedColorObject::ShadowedColorObject( + const std::vector>& meshes, + gs::ShadowMapColor& shader, + gs::ShadowMapColor& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group) + : Object3D{parent}, + Magnum::SceneGraph::Drawable3D{*this, group}, + _meshes{meshes}, + _shader{shader}, + _texture_shader(texture_shader) {} + + ShadowedColorObject& ShadowedColorObject::set_meshes(const std::vector>& meshes) + { + _meshes = meshes; + return *this; + } + + ShadowedColorObject& ShadowedColorObject::set_materials(const std::vector& materials) + { + _materials = materials; + return *this; + } + + ShadowedColorObject& ShadowedColorObject::set_scalings(const std::vector& scalings) + { + _scalings = scalings; + return *this; + } + + void ShadowedColorObject::draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) + { + for (size_t i = 0; i < _meshes.size(); i++) { + Magnum::GL::Mesh& mesh = _meshes[i]; + Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); + bool isColor = !_materials[i].has_diffuse_texture(); + if (isColor) { + (_shader.get()) + .set_transformation_matrix(transformationMatrix * scalingMatrix) + .set_projection_matrix(camera.projectionMatrix()) + .set_material(_materials[i]) + .draw(mesh); + } + else { + (_texture_shader.get()) + .set_transformation_matrix(transformationMatrix * scalingMatrix) + .set_projection_matrix(camera.projectionMatrix()) + .set_material(_materials[i]) + .draw(mesh); + } + } + } + + // CubeMapShadowedObject + CubeMapShadowedObject::CubeMapShadowedObject( + const std::vector>& meshes, + gs::CubeMap& shader, + gs::CubeMap& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group) + : Object3D{parent}, + Magnum::SceneGraph::Drawable3D{*this, group}, + _meshes{meshes}, + _shader{shader}, + _texture_shader(texture_shader) {} + + CubeMapShadowedObject& CubeMapShadowedObject::set_meshes(const std::vector>& meshes) + { + _meshes = meshes; + return *this; + } + + CubeMapShadowedObject& CubeMapShadowedObject::set_materials(const std::vector& materials) + { + _materials = materials; + return *this; + } + + CubeMapShadowedObject& CubeMapShadowedObject::set_scalings(const std::vector& scalings) + { + _scalings = scalings; + return *this; + } + + void CubeMapShadowedObject::draw(const Magnum::Matrix4&, Magnum::SceneGraph::Camera3D&) + { + for (size_t i = 0; i < _meshes.size(); i++) { + Magnum::GL::Mesh& mesh = _meshes[i]; + Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); + bool isColor = !_materials[i].has_diffuse_texture(); + if (isColor) { + (_shader.get()) + .set_transformation_matrix(absoluteTransformation() * scalingMatrix) + .set_material(_materials[i]) + .draw(mesh); + } + else { + (_texture_shader.get()) + .set_transformation_matrix(absoluteTransformation() * scalingMatrix) + .set_material(_materials[i]) + .draw(mesh); + } + } + } + + // CubeMapShadowedColorObject + CubeMapShadowedColorObject::CubeMapShadowedColorObject( + const std::vector>& meshes, + gs::CubeMapColor& shader, + gs::CubeMapColor& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group) + : Object3D{parent}, + Magnum::SceneGraph::Drawable3D{*this, group}, + _meshes{meshes}, + _shader{shader}, + _texture_shader(texture_shader) {} + + CubeMapShadowedColorObject& CubeMapShadowedColorObject::set_meshes(const std::vector>& meshes) + { + _meshes = meshes; + return *this; + } + + CubeMapShadowedColorObject& CubeMapShadowedColorObject::set_materials(const std::vector& materials) + { + _materials = materials; + return *this; + } + + CubeMapShadowedColorObject& CubeMapShadowedColorObject::set_scalings(const std::vector& scalings) + { + _scalings = scalings; + return *this; + } + + void CubeMapShadowedColorObject::draw(const Magnum::Matrix4&, Magnum::SceneGraph::Camera3D&) + { + for (size_t i = 0; i < _meshes.size(); i++) { + Magnum::GL::Mesh& mesh = _meshes[i]; + Magnum::Matrix4 scalingMatrix = Magnum::Matrix4::scaling(_scalings[i]); + bool isColor = !_materials[i].has_diffuse_texture(); + if (isColor) { + (_shader.get()) + .set_transformation_matrix(absoluteTransformation() * scalingMatrix) + .set_material(_materials[i]) + .draw(mesh); + } + else { + (_texture_shader.get()) + .set_transformation_matrix(absoluteTransformation() * scalingMatrix) + .set_material(_materials[i]) + .draw(mesh); + } + } + } + } // namespace magnum + } // namespace gui +} // namespace robot_dart \ No newline at end of file diff --git a/src/robot_dart/gui/magnum/drawables.hpp b/src/robot_dart/gui/magnum/drawables.hpp new file mode 100644 index 00000000..6fe4013d --- /dev/null +++ b/src/robot_dart/gui/magnum/drawables.hpp @@ -0,0 +1,157 @@ +#ifndef ROBOT_DART_GUI_MAGNUM_DRAWABLES_HPP +#define ROBOT_DART_GUI_MAGNUM_DRAWABLES_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +namespace robot_dart { + namespace gui { + namespace magnum { + class DrawableObject : public Object3D, Magnum::SceneGraph::Drawable3D { + public: + explicit DrawableObject( + const std::vector>& meshes, + const std::vector& materials, + gs::PhongMultiLight& color, + gs::PhongMultiLight& texture, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group); + + DrawableObject& set_meshes(const std::vector>& meshes); + DrawableObject& set_materials(const std::vector& materials); + DrawableObject& set_soft_bodies(const std::vector& softBody); + DrawableObject& set_scalings(const std::vector& scalings); + DrawableObject& set_transparent(bool transparent = true); + + DrawableObject& set_color_shader(std::reference_wrapper shader); + DrawableObject& set_texture_shader(std::reference_wrapper shader); + + const std::vector& materials() const { return _materials; } + bool transparent() const { return _isTransparent; } + + private: + void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; + + std::vector> _meshes; + std::reference_wrapper _color_shader; + std::reference_wrapper _texture_shader; + std::vector _materials; + std::vector _scalings; + std::vector _has_negative_scaling; + std::vector _is_soft_body; + bool _isTransparent; + }; + + class ShadowedObject : public Object3D, Magnum::SceneGraph::Drawable3D { + public: + explicit ShadowedObject( + const std::vector>& meshes, + gs::ShadowMap& shader, + gs::ShadowMap& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group); + + ShadowedObject& set_meshes(const std::vector>& meshes); + ShadowedObject& set_materials(const std::vector& materials); + ShadowedObject& set_scalings(const std::vector& scalings); + + private: + void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; + + std::vector> _meshes; + std::reference_wrapper _shader, _texture_shader; + std::vector _materials; + std::vector _scalings; + }; + + class ShadowedColorObject : public Object3D, Magnum::SceneGraph::Drawable3D { + public: + explicit ShadowedColorObject( + const std::vector>& meshes, + gs::ShadowMapColor& shader, + gs::ShadowMapColor& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group); + + ShadowedColorObject& set_meshes(const std::vector>& meshes); + ShadowedColorObject& set_materials(const std::vector& materials); + ShadowedColorObject& set_scalings(const std::vector& scalings); + + private: + void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; + + std::vector> _meshes; + std::reference_wrapper _shader, _texture_shader; + std::vector _materials; + std::vector _scalings; + }; + + class CubeMapShadowedObject : public Object3D, Magnum::SceneGraph::Drawable3D { + public: + explicit CubeMapShadowedObject( + const std::vector>& meshes, + gs::CubeMap& shader, + gs::CubeMap& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group); + + CubeMapShadowedObject& set_meshes(const std::vector>& meshes); + CubeMapShadowedObject& set_materials(const std::vector& materials); + CubeMapShadowedObject& set_scalings(const std::vector& scalings); + + private: + void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; + + std::vector> _meshes; + std::reference_wrapper _shader, _texture_shader; + std::vector _materials; + std::vector _scalings; + }; + + class CubeMapShadowedColorObject : public Object3D, Magnum::SceneGraph::Drawable3D { + public: + explicit CubeMapShadowedColorObject( + const std::vector>& meshes, + gs::CubeMapColor& shader, + gs::CubeMapColor& texture_shader, + Object3D* parent, + Magnum::SceneGraph::DrawableGroup3D* group); + + CubeMapShadowedColorObject& set_meshes(const std::vector>& meshes); + CubeMapShadowedColorObject& set_materials(const std::vector& materials); + CubeMapShadowedColorObject& set_scalings(const std::vector& scalings); + + private: + void draw(const Magnum::Matrix4& transformationMatrix, Magnum::SceneGraph::Camera3D& camera) override; + + std::vector> _meshes; + std::reference_wrapper _shader, _texture_shader; + std::vector _materials; + std::vector _scalings; + }; + + struct ShadowData { + Magnum::GL::Framebuffer shadow_framebuffer{Magnum::NoCreate}; + Magnum::GL::Framebuffer shadow_color_framebuffer{Magnum::NoCreate}; + }; + + struct ObjectStruct { + DrawableObject* drawable; + ShadowedObject* shadowed; + ShadowedColorObject* shadowed_color; + CubeMapShadowedObject* cubemapped; + CubeMapShadowedColorObject* cubemapped_color; + }; + } // namespace magnum + } // namespace gui +} // namespace robot_dart +#endif diff --git a/src/robot_dart/gui/magnum/glfw_application.cpp b/src/robot_dart/gui/magnum/glfw_application.cpp index 2db93497..24384cf3 100644 --- a/src/robot_dart/gui/magnum/glfw_application.cpp +++ b/src/robot_dart/gui/magnum/glfw_application.cpp @@ -10,14 +10,17 @@ namespace robot_dart { namespace gui { namespace magnum { - GlfwApplication::GlfwApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, size_t width, size_t height, const std::string& title, bool isShadowed, bool drawTransparentShadows) - : BaseApplication(isShadowed, drawTransparentShadows), Magnum::Platform::Application({argc, argv}, Magnum::NoCreate), _speedMove(0.f), _speedStrafe(0.f) + GlfwApplication::GlfwApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, const GraphicsConfiguration& configuration) + : BaseApplication(configuration), + Magnum::Platform::Application({argc, argv}, Magnum::NoCreate), + _speed_move(0.f), + _speed_strafe(0.f) { /* Try 16x MSAA */ Configuration conf; GLConfiguration glConf; - conf.setTitle(title); - conf.setSize({static_cast(width), static_cast(height)}); + conf.setTitle(configuration.title); + conf.setSize({static_cast(configuration.width), static_cast(configuration.height)}); conf.setWindowFlags(Configuration::WindowFlag::Resizable); glConf.setSampleCount(8); if (!tryCreate(conf, glConf)) @@ -35,7 +38,7 @@ namespace robot_dart { GlfwApplication::~GlfwApplication() { - GLCleanUp(); + _gl_clean_up(); } void GlfwApplication::render() @@ -47,15 +50,15 @@ namespace robot_dart { { Magnum::GL::defaultFramebuffer.setViewport({{}, size}); - _camera->setViewport(size); + _camera->set_viewport(size); } void GlfwApplication::drawEvent() { /* Update graphic meshes/materials and render */ - updateGraphics(); + update_graphics(); /* Update lights transformations */ - updateLights(*_camera); + update_lights(*_camera); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::DepthTest); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::FaceCulling); @@ -70,8 +73,8 @@ namespace robot_dart { Magnum::GL::defaultFramebuffer.clear( Magnum::GL::FramebufferClear::Color | Magnum::GL::FramebufferClear::Depth); - _camera->forward(_speedMove); - _camera->strafe(_speedStrafe); + _camera->forward(_speed_move); + _camera->strafe(_speed_strafe); /* Draw with main camera */ _camera->draw(_drawables, Magnum::GL::defaultFramebuffer, Magnum::PixelFormat::RGB8Unorm); @@ -83,8 +86,8 @@ namespace robot_dart { void GlfwApplication::keyReleaseEvent(KeyEvent& event) { - _speedMove = 0.f; - _speedStrafe = 0.f; + _speed_move = 0.f; + _speed_strafe = 0.f; event.setAccepted(); } @@ -92,16 +95,16 @@ namespace robot_dart { void GlfwApplication::keyPressEvent(KeyEvent& event) { if (event.key() == KeyEvent::Key::W) { - _speedMove = _speed; + _speed_move = _speed; } else if (event.key() == KeyEvent::Key::S) { - _speedMove = -_speed; + _speed_move = -_speed; } else if (event.key() == KeyEvent::Key::A) { - _speedStrafe = -_speed; + _speed_strafe = -_speed; } else if (event.key() == KeyEvent::Key::D) { - _speedStrafe = _speed; + _speed_strafe = _speed; } else if (event.key() == KeyEvent::Key::Q || event.key() == KeyEvent::Key::Esc) { exit(); diff --git a/src/robot_dart/gui/magnum/glfw_application.hpp b/src/robot_dart/gui/magnum/glfw_application.hpp index efb2bd21..7314d2cf 100644 --- a/src/robot_dart/gui/magnum/glfw_application.hpp +++ b/src/robot_dart/gui/magnum/glfw_application.hpp @@ -16,14 +16,14 @@ namespace robot_dart { namespace magnum { class GlfwApplication : public BaseApplication, public Magnum::Platform::Application { public: - explicit GlfwApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, size_t width, size_t height, const std::string& title = "DART", bool isShadowed = true, bool drawTransparentShadows = true); + explicit GlfwApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, const GraphicsConfiguration& configuration = GraphicsConfiguration()); ~GlfwApplication(); void render() override; protected: - Magnum::Float _speedMove, _speedStrafe; + Magnum::Float _speed_move, _speed_strafe; static constexpr Magnum::Float _speed = 0.05f; diff --git a/src/robot_dart/gui/magnum/graphics.hpp b/src/robot_dart/gui/magnum/graphics.hpp index 420ae645..37b5cd4b 100644 --- a/src/robot_dart/gui/magnum/graphics.hpp +++ b/src/robot_dart/gui/magnum/graphics.hpp @@ -19,12 +19,12 @@ namespace robot_dart { template class Graphics : public Base { public: - Graphics(const dart::simulation::WorldPtr& world, unsigned int width = 640, unsigned int height = 480, bool shadowed = true, bool transparent_shadows = true, const std::string& title = "DART") - : _world(world), _width(width), _height(height), _frame_counter(0), _enabled(true) + Graphics(const dart::simulation::WorldPtr& world, const GraphicsConfiguration& configuration = GraphicsConfiguration()) + : _world(world), _width(configuration.width), _height(configuration.height), _frame_counter(0), _enabled(true) { Corrade::Utility::Debug magnum_silence_output{nullptr}; robot_dart_initialize_magnum_resources(); - _magnum_app.reset(make_application(world, width, height, title, shadowed, transparent_shadows)); + _magnum_app.reset(make_application(world, configuration)); set_render_period(world->getTimeStep()); } @@ -63,17 +63,17 @@ namespace robot_dart { const Eigen::Vector3d& look_at = Eigen::Vector3d(0, 0, 0), const Eigen::Vector3d& up = Eigen::Vector3d(0, 0, 1)) { - _magnum_app->lookAt(camera_pos, look_at, up); + _magnum_app->look_at(camera_pos, look_at, up); } void clear_lights() { - _magnum_app->clearLights(); + _magnum_app->clear_lights(); } void add_light(const magnum::gs::Light& light) { - _magnum_app->addLight(light); + _magnum_app->add_light(light); } std::vector& lights() @@ -83,7 +83,7 @@ namespace robot_dart { size_t num_lights() const { - return _magnum_app->numLights(); + return _magnum_app->num_lights(); } magnum::gs::Light& light(size_t i) @@ -92,11 +92,12 @@ namespace robot_dart { } void set_recording(bool recording, bool recording_depth = false) { _magnum_app->record(recording, recording_depth); } - bool recording() { return _magnum_app->isRecording(); } - bool recording_depth() { return _magnum_app->isDepthRecording(); } + bool recording() { return _magnum_app->recording(); } + bool recording_depth() { return _magnum_app->recording_depth(); } - bool is_shadowed() const { return _magnum_app->isShadowed(); } - void enable_shadows(bool enable = true) { _magnum_app->enableShadows(enable); } + bool shadowed() const { return _magnum_app->shadowed(); } + bool transparent_shadows() const { return _magnum_app->transparent_shadows(); } + void enable_shadows(bool enable = true, bool transparent = true) { _magnum_app->enable_shadows(enable, transparent); } Magnum::Image2D* magnum_image() { @@ -113,18 +114,18 @@ namespace robot_dart { return Image(); } - GrayscaleImage depth_image() override { return _magnum_app->depthImage(); } - GrayscaleImage raw_depth_image() override { return _magnum_app->rawDepthImage(); } + GrayscaleImage depth_image() override { return _magnum_app->depth_image(); } + GrayscaleImage raw_depth_image() override { return _magnum_app->raw_depth_image(); } - void set_speed(const Magnum::Vector2& speed) { _magnum_app->camera().setSpeed(speed); } - void set_near_plane(double near_plane) { _magnum_app->camera().setNearPlane(near_plane); } - void set_far_plane(double far_plane) { _magnum_app->camera().setFarPlane(far_plane); } - void set_fov(double fov) { _magnum_app->camera().setFOV(fov); } - void set_camera_params(double near_plane, double far_plane, double fov, size_t width, size_t height) { _magnum_app->camera().setCameraParameters(near_plane, far_plane, fov, width, height); } + void set_speed(const Magnum::Vector2& speed) { _magnum_app->camera().set_speed(speed); } + void set_near_plane(double near_plane) { _magnum_app->camera().set_near_plane(near_plane); } + void set_far_plane(double far_plane) { _magnum_app->camera().set_far_plane(far_plane); } + void set_fov(double fov) { _magnum_app->camera().set_fov(fov); } + void set_camera_params(double near_plane, double far_plane, double fov, size_t width, size_t height) { _magnum_app->camera().set_camera_params(near_plane, far_plane, fov, width, height); } Magnum::Vector2 speed() const { return _magnum_app->camera().speed(); } - double near_plane() const { return _magnum_app->camera().nearPlane(); } - double far_plane() const { return _magnum_app->camera().farPlane(); } + double near_plane() const { return _magnum_app->camera().near_plane(); } + double far_plane() const { return _magnum_app->camera().far_plane(); } double fov() const { return _magnum_app->camera().fov(); } BaseApplication* magnum_app() { return &*_magnum_app; } diff --git a/src/robot_dart/gui/magnum/gs/camera.cpp b/src/robot_dart/gui/magnum/gs/camera.cpp index a442e137..d7c43105 100644 --- a/src/robot_dart/gui/magnum/gs/camera.cpp +++ b/src/robot_dart/gui/magnum/gs/camera.cpp @@ -15,11 +15,11 @@ namespace robot_dart { namespace gs { Camera::Camera(Object3D& object, Magnum::Int width, Magnum::Int height) : Object3D{&object} { - _yawObject = new Object3D{this}; - _pitchObject = new Object3D{_yawObject}; + _yaw_object = new Object3D{this}; + _pitch_object = new Object3D{_yaw_object}; - _yawObject->setTransformation(Magnum::Matrix4{}); - _pitchObject->setTransformation(Magnum::Matrix4{}); + _yaw_object->setTransformation(Magnum::Matrix4{}); + _pitch_object->setTransformation(Magnum::Matrix4{}); Magnum::Vector3 center{0., 0., 0.}; Magnum::Vector3 camera{0., 2., 1.}; @@ -27,17 +27,17 @@ namespace robot_dart { _up = Magnum::Vector3::zAxis(); _right = Magnum::Math::cross(_front, _up).normalized(); - _cameraObject = new Object3D{_pitchObject}; - _cameraObject->setTransformation(Magnum::Matrix4::lookAt(camera, center, _up)); + _camera_object = new Object3D{_pitch_object}; + _camera_object->setTransformation(Magnum::Matrix4::lookAt(camera, center, _up)); _fov = Magnum::Deg(60.0f); - _aspectRatio = width / static_cast(height); - _nearPlane = 0.01f; - _farPlane = 200.f; + _aspect_ratio = width / static_cast(height); + _near_plane = 0.01f; + _far_plane = 200.f; - _camera = new Camera3D{*_cameraObject}; + _camera = new Camera3D{*_camera_object}; _camera->setAspectRatioPolicy(Magnum::SceneGraph::AspectRatioPolicy::Extend) - .setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspectRatio, _nearPlane, _farPlane)) + .setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspect_ratio, _near_plane, _far_plane)) .setViewport({width, height}); } @@ -46,15 +46,15 @@ namespace robot_dart { return *_camera; } - Object3D& Camera::cameraObject() const + Object3D& Camera::camera_object() const { - return *_cameraObject; + return *_camera_object; } - Camera& Camera::setViewport(const Magnum::Vector2i& size) + Camera& Camera::set_viewport(const Magnum::Vector2i& size) { - _aspectRatio = size[0] / static_cast(size[1]); - _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspectRatio, _nearPlane, _farPlane)) + _aspect_ratio = size[0] / static_cast(size[1]); + _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspect_ratio, _near_plane, _far_plane)) .setViewport(size); return *this; @@ -64,85 +64,85 @@ namespace robot_dart { { Magnum::Vector2 s = Magnum::Vector2{shift} * _speed; - _yawObject->rotate(Magnum::Rad(s.x()), _up); - _pitchObject->rotate(Magnum::Rad(s.y()), _right); + _yaw_object->rotate(Magnum::Rad(s.x()), _up); + _pitch_object->rotate(Magnum::Rad(s.y()), _right); return *this; } Camera& Camera::forward(Magnum::Float speed) { - _cameraObject->translate(speed * _front); + _camera_object->translate(speed * _front); return *this; } Camera& Camera::strafe(Magnum::Float speed) { - _cameraObject->translate(speed * _right); + _camera_object->translate(speed * _right); return *this; } - Camera& Camera::setSpeed(const Magnum::Vector2& speed) + Camera& Camera::set_speed(const Magnum::Vector2& speed) { _speed = speed; return *this; } - Camera& Camera::setNearPlane(Magnum::Float nearPlane) + Camera& Camera::set_near_plane(Magnum::Float near_plane) { - _nearPlane = nearPlane; - _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspectRatio, _nearPlane, _farPlane)); + _near_plane = near_plane; + _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspect_ratio, _near_plane, _far_plane)); return *this; } - Camera& Camera::setFarPlane(Magnum::Float farPlane) + Camera& Camera::set_far_plane(Magnum::Float far_plane) { - _farPlane = farPlane; - _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspectRatio, _nearPlane, _farPlane)); + _far_plane = far_plane; + _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspect_ratio, _near_plane, _far_plane)); return *this; } - Camera& Camera::setFOV(Magnum::Float fov) + Camera& Camera::set_fov(Magnum::Float fov) { // Maximum FOV is around 170 degrees _fov = Magnum::Rad(std::max(0.f, std::min(3.f, fov))); - _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspectRatio, _nearPlane, _farPlane)); + _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspect_ratio, _near_plane, _far_plane)); return *this; } - Camera& Camera::setCameraParameters(Magnum::Float nearPlane, Magnum::Float farPlane, Magnum::Float fov, Magnum::Int width, Magnum::Int height) + Camera& Camera::set_camera_params(Magnum::Float near_plane, Magnum::Float far_plane, Magnum::Float fov, Magnum::Int width, Magnum::Int height) { - _nearPlane = nearPlane; - _farPlane = farPlane; + _near_plane = near_plane; + _far_plane = far_plane; // Maximum FOV is around 170 degrees _fov = Magnum::Rad(std::max(0.f, std::min(3.f, fov))); - _aspectRatio = width / static_cast(height); + _aspect_ratio = width / static_cast(height); - _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspectRatio, _nearPlane, _farPlane)) + _camera->setProjectionMatrix(Magnum::Matrix4::perspectiveProjection(_fov, _aspect_ratio, _near_plane, _far_plane)) .setViewport({width, height}); return *this; } - Camera& Camera::lookAt(const Magnum::Vector3& camera, const Magnum::Vector3& center, const Magnum::Vector3& up) + Camera& Camera::look_at(const Magnum::Vector3& camera, const Magnum::Vector3& center, const Magnum::Vector3& up) { _front = (center - camera).normalized(); _up = up; _right = Magnum::Math::cross(_front, _up).normalized(); - _cameraObject->setTransformation(Magnum::Matrix4::lookAt(camera, center, up)); - _yawObject->setTransformation(Magnum::Matrix4{}); - _pitchObject->setTransformation(Magnum::Matrix4{}); + _camera_object->setTransformation(Magnum::Matrix4::lookAt(camera, center, up)); + _yaw_object->setTransformation(Magnum::Matrix4{}); + _pitch_object->setTransformation(Magnum::Matrix4{}); return *this; } - void Camera::transformLights(std::vector& lights) const + void Camera::transform_lights(std::vector& lights) const { /* Update lights transformations */ for (size_t i = 0; i < lights.size(); i++) { @@ -154,9 +154,9 @@ namespace robot_dart { /* Other light types, need full transformation */ else pos = _camera->cameraMatrix().transformPoint(old_pos.xyz()); - lights[i].setTransformedPosition(Magnum::Vector4{pos, old_pos.w()}); + lights[i].set_transformed_position(Magnum::Vector4{pos, old_pos.w()}); /* Transform spotlight direction */ - lights[i].setTransformedSpotDirection(_camera->cameraMatrix().transformVector(lights[i].spotDirection())); + lights[i].set_transformed_spot_direction(_camera->cameraMatrix().transformVector(lights[i].spot_direction())); } } @@ -169,7 +169,7 @@ namespace robot_dart { std::vector, Magnum::Matrix4>> opaque, transparent; for (size_t i = 0; i < drawableTransformations.size(); i++) { auto& obj = static_cast(drawableTransformations[i].first.get().object()); - if (obj.isTransparent()) + if (obj.transparent()) transparent.emplace_back(drawableTransformations[i]); else opaque.emplace_back(drawableTransformations[i]); diff --git a/src/robot_dart/gui/magnum/gs/camera.hpp b/src/robot_dart/gui/magnum/gs/camera.hpp index fdf5057c..e4cd120b 100644 --- a/src/robot_dart/gui/magnum/gs/camera.hpp +++ b/src/robot_dart/gui/magnum/gs/camera.hpp @@ -17,30 +17,30 @@ namespace robot_dart { explicit Camera(Object3D& object, Magnum::Int width, Magnum::Int height); Camera3D& camera() const; - Object3D& cameraObject() const; + Object3D& camera_object() const; - Camera& setViewport(const Magnum::Vector2i& size); + Camera& set_viewport(const Magnum::Vector2i& size); Camera& move(const Magnum::Vector2i& shift); Camera& forward(Magnum::Float speed); Camera& strafe(Magnum::Float speed); - Camera& setSpeed(const Magnum::Vector2& speed); - Camera& setNearPlane(Magnum::Float nearPlane); - Camera& setFarPlane(Magnum::Float farPlane); - Camera& setFOV(Magnum::Float fov); - Camera& setCameraParameters(Magnum::Float nearPlane, Magnum::Float farPlane, Magnum::Float fov, Magnum::Int width, Magnum::Int height); + Camera& set_speed(const Magnum::Vector2& speed); + Camera& set_near_plane(Magnum::Float near_plane); + Camera& set_far_plane(Magnum::Float far_plane); + Camera& set_fov(Magnum::Float fov); + Camera& set_camera_params(Magnum::Float near_plane, Magnum::Float far_plane, Magnum::Float fov, Magnum::Int width, Magnum::Int height); Magnum::Vector2 speed() const { return _speed; } - Magnum::Float nearPlane() const { return _nearPlane; } - Magnum::Float farPlane() const { return _farPlane; } + Magnum::Float near_plane() const { return _near_plane; } + Magnum::Float far_plane() const { return _far_plane; } Magnum::Float fov() const { return static_cast(_fov); } Magnum::Int width() const { return _camera->viewport()[0]; } Magnum::Int height() const { return _camera->viewport()[1]; } - Camera& lookAt(const Magnum::Vector3& camera, const Magnum::Vector3& center, const Magnum::Vector3& up = Magnum::Vector3::zAxis()); + Camera& look_at(const Magnum::Vector3& camera, const Magnum::Vector3& center, const Magnum::Vector3& up = Magnum::Vector3::zAxis()); - void transformLights(std::vector& lights) const; + void transform_lights(std::vector& lights) const; void record(bool recording, bool depthRecording = false) { @@ -48,24 +48,24 @@ namespace robot_dart { _recording_depth = depthRecording; } - bool isRecording() { return _recording; } - bool isDepthRecording() { return _recording_depth; } + bool recording() { return _recording; } + bool recording_depth() { return _recording_depth; } Corrade::Containers::Optional& image() { return _image; } - Corrade::Containers::Optional& depthImage() { return _depth_image; } + Corrade::Containers::Optional& depth_image() { return _depth_image; } void draw(Magnum::SceneGraph::DrawableGroup3D& drawables, Magnum::GL::AbstractFramebuffer& framebuffer, Magnum::PixelFormat format); private: - Object3D* _yawObject; - Object3D* _pitchObject; - Object3D* _cameraObject; + Object3D* _yaw_object; + Object3D* _pitch_object; + Object3D* _camera_object; Camera3D* _camera; Magnum::Vector2 _speed{-0.01f, 0.01f}; Magnum::Vector3 _up, _front, _right; - Magnum::Float _aspectRatio, _nearPlane, _farPlane; + Magnum::Float _aspect_ratio, _near_plane, _far_plane; Magnum::Rad _fov; bool _recording = false, _recording_depth = false; diff --git a/src/robot_dart/gui/magnum/gs/cube_map.cpp b/src/robot_dart/gui/magnum/gs/cube_map.cpp index 1bdfeaff..ff6565df 100644 --- a/src/robot_dart/gui/magnum/gs/cube_map.cpp +++ b/src/robot_dart/gui/magnum/gs/cube_map.cpp @@ -20,8 +20,11 @@ namespace robot_dart { Magnum::GL::Shader frag = Magnum::Shaders::Implementation::createCompatibilityShader( rs_shaders, version, Magnum::GL::Shader::Type::Fragment); + std::string defines = "#define POSITION_ATTRIBUTE_LOCATION " + std::to_string(Position::Location) + "\n"; + defines += "#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION " + std::to_string(TextureCoordinates::Location) + "\n"; + vert.addSource(flags ? "#define TEXTURED\n" : "") - .addSource(rs_shaders.get("generic.glsl")) + .addSource(defines) .addSource(rs_shaders.get("CubeMap.vert")); geom.addSource(flags ? "#define TEXTURED\n" : "") .addSource(rs_shaders.get("CubeMap.geom")); @@ -41,12 +44,12 @@ namespace robot_dart { CORRADE_INTERNAL_ASSERT_OUTPUT(link()); if (!Magnum::GL::Context::current().isExtensionSupported(version)) { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); - _shadowMatricesUniform = uniformLocation("shadowMatrices[0]"); - _lightPositionUniform = uniformLocation("lightPosition"); - _farPlaneUniform = uniformLocation("farPlane"); - _lightIndexUniform = uniformLocation("lightIndex"); - _diffuseColorUniform = uniformLocation("diffuseColor"); + _transformation_matrix_uniform = uniformLocation("transformationMatrix"); + _shadow_matrices_uniform = uniformLocation("shadowMatrices[0]"); + _light_position_uniform = uniformLocation("lightPosition"); + _far_plane_uniform = uniformLocation("farPlane"); + _light_index_uniform = uniformLocation("lightIndex"); + _diffuse_color_uniform = uniformLocation("diffuseColor"); } } @@ -54,45 +57,45 @@ namespace robot_dart { CubeMap::Flags CubeMap::flags() const { return _flags; } - CubeMap& CubeMap::setTransformationMatrix(const Magnum::Matrix4& matrix) + CubeMap& CubeMap::set_transformation_matrix(const Magnum::Matrix4& matrix) { - setUniform(_transformationMatrixUniform, matrix); + setUniform(_transformation_matrix_uniform, matrix); return *this; } - CubeMap& CubeMap::setShadowMatrices(Magnum::Matrix4 matrices[6]) + CubeMap& CubeMap::set_shadow_matrices(Magnum::Matrix4 matrices[6]) { for (size_t i = 0; i < 6; i++) - setUniform(_shadowMatricesUniform + i, matrices[i]); + setUniform(_shadow_matrices_uniform + i, matrices[i]); return *this; } - CubeMap& CubeMap::setLightPosition(const Magnum::Vector3& position) + CubeMap& CubeMap::set_light_position(const Magnum::Vector3& position) { - setUniform(_lightPositionUniform, position); + setUniform(_light_position_uniform, position); return *this; } - CubeMap& CubeMap::setFarPlane(Magnum::Float farPlane) + CubeMap& CubeMap::set_far_plane(Magnum::Float far_plane) { - setUniform(_farPlaneUniform, farPlane); + setUniform(_far_plane_uniform, far_plane); return *this; } - CubeMap& CubeMap::setLightIndex(Magnum::Int index) + CubeMap& CubeMap::set_light_index(Magnum::Int index) { - setUniform(_lightIndexUniform, index); + setUniform(_light_index_uniform, index); return *this; } - CubeMap& CubeMap::setMaterial(Material& material) + CubeMap& CubeMap::set_material(Material& material) { - if (material.hasDiffuseTexture() && (_flags & Flag::DiffuseTexture)) { - (*material.diffuseTexture()).bind(DiffuseTextureLayer); - setUniform(_diffuseColorUniform, Magnum::Color4{1.0f}); + if (material.has_diffuse_texture() && (_flags & Flag::DiffuseTexture)) { + (*material.diffuse_texture()).bind(DiffuseTextureLayer); + setUniform(_diffuse_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_diffuseColorUniform, material.diffuseColor()); + setUniform(_diffuse_color_uniform, material.diffuse_color()); return *this; } diff --git a/src/robot_dart/gui/magnum/gs/cube_map.hpp b/src/robot_dart/gui/magnum/gs/cube_map.hpp index 4424b8dd..af8102cd 100644 --- a/src/robot_dart/gui/magnum/gs/cube_map.hpp +++ b/src/robot_dart/gui/magnum/gs/cube_map.hpp @@ -32,21 +32,21 @@ namespace robot_dart { Flags flags() const; - CubeMap& setTransformationMatrix(const Magnum::Matrix4& matrix); - CubeMap& setShadowMatrices(Magnum::Matrix4 matrices[6]); - CubeMap& setLightPosition(const Magnum::Vector3& position); - CubeMap& setFarPlane(Magnum::Float farPlane); - CubeMap& setLightIndex(Magnum::Int index); - CubeMap& setMaterial(Material& material); + CubeMap& set_transformation_matrix(const Magnum::Matrix4& matrix); + CubeMap& set_shadow_matrices(Magnum::Matrix4 matrices[6]); + CubeMap& set_light_position(const Magnum::Vector3& position); + CubeMap& set_far_plane(Magnum::Float far_plane); + CubeMap& set_light_index(Magnum::Int index); + CubeMap& set_material(Material& material); private: Flags _flags; - Magnum::Int _transformationMatrixUniform{0}, - _shadowMatricesUniform{5}, - _lightPositionUniform{1}, - _farPlaneUniform{2}, - _lightIndexUniform{3}, - _diffuseColorUniform{4}; + Magnum::Int _transformation_matrix_uniform{0}, + _shadow_matrices_uniform{5}, + _light_position_uniform{1}, + _far_plane_uniform{2}, + _light_index_uniform{3}, + _diffuse_color_uniform{4}; }; CORRADE_ENUMSET_OPERATORS(CubeMap::Flags) diff --git a/src/robot_dart/gui/magnum/gs/cube_map_color.cpp b/src/robot_dart/gui/magnum/gs/cube_map_color.cpp index d7526617..5c3deba5 100644 --- a/src/robot_dart/gui/magnum/gs/cube_map_color.cpp +++ b/src/robot_dart/gui/magnum/gs/cube_map_color.cpp @@ -21,8 +21,11 @@ namespace robot_dart { Magnum::GL::Shader frag = Magnum::Shaders::Implementation::createCompatibilityShader( rs_shaders, version, Magnum::GL::Shader::Type::Fragment); + std::string defines = "#define POSITION_ATTRIBUTE_LOCATION " + std::to_string(Position::Location) + "\n"; + defines += "#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION " + std::to_string(TextureCoordinates::Location) + "\n"; + vert.addSource(flags ? "#define TEXTURED\n" : "") - .addSource(rs_shaders.get("generic.glsl")) + .addSource(defines) .addSource(rs_shaders.get("CubeMap.vert")); geom.addSource(flags ? "#define TEXTURED\n" : "") .addSource(rs_shaders.get("CubeMap.geom")); @@ -42,17 +45,17 @@ namespace robot_dart { CORRADE_INTERNAL_ASSERT_OUTPUT(link()); if (!Magnum::GL::Context::current().isExtensionSupported(version)) { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); - _shadowMatricesUniform = uniformLocation("shadowMatrices[0]"); - _lightPositionUniform = uniformLocation("lightPosition"); - _farPlaneUniform = uniformLocation("farPlane"); - _lightIndexUniform = uniformLocation("lightIndex"); - _diffuseColorUniform = uniformLocation("diffuseColor"); + _transformation_matrix_uniform = uniformLocation("transformationMatrix"); + _shadow_matrices_uniform = uniformLocation("shadowMatrices[0]"); + _light_position_uniform = uniformLocation("lightPosition"); + _far_plane_uniform = uniformLocation("farPlane"); + _light_index_uniform = uniformLocation("lightIndex"); + _diffuse_color_uniform = uniformLocation("diffuseColor"); } if (!Magnum::GL::Context::current() .isExtensionSupported(version)) { - setUniform(uniformLocation("cubeMapTextures"), _cubeMapTexturesLocation); + setUniform(uniformLocation("cubeMapTextures"), _cube_map_textures_location); if (flags) { if (flags & Flag::DiffuseTexture) setUniform(uniformLocation("diffuseTexture"), DiffuseTextureLayer); @@ -64,52 +67,52 @@ namespace robot_dart { CubeMapColor::Flags CubeMapColor::flags() const { return _flags; } - CubeMapColor& CubeMapColor::setTransformationMatrix(const Magnum::Matrix4& matrix) + CubeMapColor& CubeMapColor::set_transformation_matrix(const Magnum::Matrix4& matrix) { - setUniform(_transformationMatrixUniform, matrix); + setUniform(_transformation_matrix_uniform, matrix); return *this; } - CubeMapColor& CubeMapColor::setShadowMatrices(Magnum::Matrix4 matrices[6]) + CubeMapColor& CubeMapColor::set_shadow_matrices(Magnum::Matrix4 matrices[6]) { for (size_t i = 0; i < 6; i++) - setUniform(_shadowMatricesUniform + i, matrices[i]); + setUniform(_shadow_matrices_uniform + i, matrices[i]); return *this; } - CubeMapColor& CubeMapColor::setLightPosition(const Magnum::Vector3& position) + CubeMapColor& CubeMapColor::set_light_position(const Magnum::Vector3& position) { - setUniform(_lightPositionUniform, position); + setUniform(_light_position_uniform, position); return *this; } - CubeMapColor& CubeMapColor::setFarPlane(Magnum::Float farPlane) + CubeMapColor& CubeMapColor::set_far_plane(Magnum::Float far_plane) { - setUniform(_farPlaneUniform, farPlane); + setUniform(_far_plane_uniform, far_plane); return *this; } - CubeMapColor& CubeMapColor::setLightIndex(Magnum::Int index) + CubeMapColor& CubeMapColor::set_light_index(Magnum::Int index) { - setUniform(_lightIndexUniform, index); + setUniform(_light_index_uniform, index); return *this; } - CubeMapColor& CubeMapColor::setMaterial(Material& material) + CubeMapColor& CubeMapColor::set_material(Material& material) { - if (material.hasDiffuseTexture() && (_flags & Flag::DiffuseTexture)) { - (*material.diffuseTexture()).bind(DiffuseTextureLayer); - setUniform(_diffuseColorUniform, Magnum::Color4{1.0f}); + if (material.has_diffuse_texture() && (_flags & Flag::DiffuseTexture)) { + (*material.diffuse_texture()).bind(DiffuseTextureLayer); + setUniform(_diffuse_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_diffuseColorUniform, material.diffuseColor()); + setUniform(_diffuse_color_uniform, material.diffuse_color()); return *this; } - CubeMapColor& CubeMapColor::bindCubeMapTexture(Magnum::GL::CubeMapTextureArray& texture) + CubeMapColor& CubeMapColor::bind_cube_map_texture(Magnum::GL::CubeMapTextureArray& texture) { - texture.bind(_cubeMapTexturesLocation); + texture.bind(_cube_map_textures_location); return *this; } } // namespace gs diff --git a/src/robot_dart/gui/magnum/gs/cube_map_color.hpp b/src/robot_dart/gui/magnum/gs/cube_map_color.hpp index e4082ef7..bb8c8188 100644 --- a/src/robot_dart/gui/magnum/gs/cube_map_color.hpp +++ b/src/robot_dart/gui/magnum/gs/cube_map_color.hpp @@ -32,24 +32,24 @@ namespace robot_dart { Flags flags() const; - CubeMapColor& setTransformationMatrix(const Magnum::Matrix4& matrix); - CubeMapColor& setShadowMatrices(Magnum::Matrix4 matrices[6]); - CubeMapColor& setLightPosition(const Magnum::Vector3& position); - CubeMapColor& setFarPlane(Magnum::Float farPlane); - CubeMapColor& setLightIndex(Magnum::Int index); - CubeMapColor& setMaterial(Material& material); + CubeMapColor& set_transformation_matrix(const Magnum::Matrix4& matrix); + CubeMapColor& set_shadow_matrices(Magnum::Matrix4 matrices[6]); + CubeMapColor& set_light_position(const Magnum::Vector3& position); + CubeMapColor& set_far_plane(Magnum::Float far_plane); + CubeMapColor& set_light_index(Magnum::Int index); + CubeMapColor& set_material(Material& material); - CubeMapColor& bindCubeMapTexture(Magnum::GL::CubeMapTextureArray& texture); + CubeMapColor& bind_cube_map_texture(Magnum::GL::CubeMapTextureArray& texture); private: Flags _flags; - Magnum::Int _transformationMatrixUniform{0}, - _shadowMatricesUniform{5}, - _lightPositionUniform{1}, - _farPlaneUniform{2}, - _lightIndexUniform{3}, - _diffuseColorUniform{4}, - _cubeMapTexturesLocation{2}; + Magnum::Int _transformation_matrix_uniform{0}, + _shadow_matrices_uniform{5}, + _light_position_uniform{1}, + _far_plane_uniform{2}, + _light_index_uniform{3}, + _diffuse_color_uniform{4}, + _cube_map_textures_location{2}; }; CORRADE_ENUMSET_OPERATORS(CubeMapColor::Flags) diff --git a/src/robot_dart/gui/magnum/gs/light.cpp b/src/robot_dart/gui/magnum/gs/light.cpp index 5f7617bf..17a673ff 100644 --- a/src/robot_dart/gui/magnum/gs/light.cpp +++ b/src/robot_dart/gui/magnum/gs/light.cpp @@ -7,101 +7,101 @@ namespace robot_dart { namespace magnum { namespace gs { Light::Light() : _position(Magnum::Vector4{0.f, 0.f, 0.f, 1.f}), - _transformedPosition(_position), + _transformed_position(_position), _material(Material()), - _spotDirection(Magnum::Vector3{1.f, 0.f, 0.f}), - _spotExponent(1.f), - _spotCutOff(Magnum::Math::Constants::pi()), + _spot_direction(Magnum::Vector3{1.f, 0.f, 0.f}), + _spot_exponent(1.f), + _spot_cut_off(Magnum::Math::Constants::pi()), _attenuation(Magnum::Vector4{0.f, 0.f, 1.f, 1.f}) {} - Light::Light(const Magnum::Vector4& position, const Material& material, const Magnum::Vector3& spotDirection, - Magnum::Float spotExponent, Magnum::Float spotCutOff, const Magnum::Vector4& attenuation) : _position(position), - _transformedPosition(_position), + Light::Light(const Magnum::Vector4& position, const Material& material, const Magnum::Vector3& spot_direction, + Magnum::Float spot_exponent, Magnum::Float spot_cut_off, const Magnum::Vector4& attenuation) : _position(position), + _transformed_position(_position), _material(material), - _spotDirection(spotDirection), - _spotExponent(spotExponent), - _spotCutOff(spotCutOff), + _spot_direction(spot_direction), + _spot_exponent(spot_exponent), + _spot_cut_off(spot_cut_off), _attenuation(attenuation) {} // Magnum::Vector4& Light::position(); Magnum::Vector4 Light::position() const { return _position; } - Magnum::Vector4& Light::transformedPosition() { return _transformedPosition; } - Magnum::Vector4 Light::transformedPosition() const { return _transformedPosition; } + Magnum::Vector4& Light::transformed_position() { return _transformed_position; } + Magnum::Vector4 Light::transformed_position() const { return _transformed_position; } Material& Light::material() { return _material; } Material Light::material() const { return _material; } - // Magnum::Vector3& Light::spotDirection() { return _spotDirection; } - Magnum::Vector3 Light::spotDirection() const { return _spotDirection; } + // Magnum::Vector3& Light::spot_direction() { return _spot_direction; } + Magnum::Vector3 Light::spot_direction() const { return _spot_direction; } - Magnum::Vector3& Light::transformedSpotDirection() { return _transformedSpotDirection; } - Magnum::Vector3 Light::transformedSpotDirection() const { return _transformedSpotDirection; } + Magnum::Vector3& Light::transformed_spot_direction() { return _transformed_spot_direction; } + Magnum::Vector3 Light::transformed_spot_direction() const { return _transformed_spot_direction; } - Magnum::Float& Light::spotExponent() { return _spotExponent; } - Magnum::Float Light::spotExponent() const { return _spotExponent; } + Magnum::Float& Light::spot_exponent() { return _spot_exponent; } + Magnum::Float Light::spot_exponent() const { return _spot_exponent; } - Magnum::Float& Light::spotCutOff() { return _spotCutOff; } - Magnum::Float Light::spotCutOff() const { return _spotCutOff; } + Magnum::Float& Light::spot_cut_off() { return _spot_cut_off; } + Magnum::Float Light::spot_cut_off() const { return _spot_cut_off; } Magnum::Vector4& Light::attenuation() { return _attenuation; } Magnum::Vector4 Light::attenuation() const { return _attenuation; } - Magnum::Matrix4 Light::shadowMatrix() const { return _shadowTransform; } + Magnum::Matrix4 Light::shadow_matrix() const { return _shadow_transform; } - Light& Light::setPosition(const Magnum::Vector4& position) + Light& Light::set_position(const Magnum::Vector4& position) { _position = position; - _transformedPosition = position; + _transformed_position = position; return *this; } - Light& Light::setTransformedPosition(const Magnum::Vector4& transformedPosition) + Light& Light::set_transformed_position(const Magnum::Vector4& transformed_position) { - _transformedPosition = transformedPosition; + _transformed_position = transformed_position; return *this; } - Light& Light::setMaterial(const Material& material) + Light& Light::set_material(const Material& material) { _material = material; return *this; } - Light& Light::setSpotDirection(const Magnum::Vector3& spotDirection) + Light& Light::set_spot_direction(const Magnum::Vector3& spot_direction) { - _spotDirection = spotDirection; - _transformedSpotDirection = _spotDirection; + _spot_direction = spot_direction; + _transformed_spot_direction = _spot_direction; return *this; } - Light& Light::setTransformedSpotDirection(const Magnum::Vector3& transformedSpotDirection) + Light& Light::set_transformed_spot_direction(const Magnum::Vector3& transformed_spot_direction) { - _transformedSpotDirection = transformedSpotDirection; + _transformed_spot_direction = transformed_spot_direction; return *this; } - Light& Light::setSpotExponent(Magnum::Float spotExponent) + Light& Light::set_spot_exponent(Magnum::Float spot_exponent) { - _spotExponent = spotExponent; + _spot_exponent = spot_exponent; return *this; } - Light& Light::setSpotCutOff(Magnum::Float spotCutOff) + Light& Light::set_spot_cut_off(Magnum::Float spot_cut_off) { - _spotCutOff = spotCutOff; + _spot_cut_off = spot_cut_off; return *this; } - Light& Light::setAttenuation(const Magnum::Vector4& attenuation) + Light& Light::set_attenuation(const Magnum::Vector4& attenuation) { _attenuation = attenuation; return *this; } - Light& Light::setShadowMatrix(const Magnum::Matrix4& shadowTransform) + Light& Light::set_shadow_matrix(const Magnum::Matrix4& shadowTransform) { - _shadowTransform = shadowTransform; + _shadow_transform = shadowTransform; return *this; } } // namespace gs diff --git a/src/robot_dart/gui/magnum/gs/light.hpp b/src/robot_dart/gui/magnum/gs/light.hpp index b315feac..06c92444 100644 --- a/src/robot_dart/gui/magnum/gs/light.hpp +++ b/src/robot_dart/gui/magnum/gs/light.hpp @@ -13,59 +13,59 @@ namespace robot_dart { public: Light(); - Light(const Magnum::Vector4& position, const Material& material, const Magnum::Vector3& spotDirection, - Magnum::Float spotExponent, Magnum::Float spotCutOff, const Magnum::Vector4& attenuation); + Light(const Magnum::Vector4& position, const Material& material, const Magnum::Vector3& spot_direction, + Magnum::Float spot_exponent, Magnum::Float spot_cut_off, const Magnum::Vector4& attenuation); // Magnum::Vector4& position(); Magnum::Vector4 position() const; - Magnum::Vector4& transformedPosition(); - Magnum::Vector4 transformedPosition() const; + Magnum::Vector4& transformed_position(); + Magnum::Vector4 transformed_position() const; Material& material(); Material material() const; - // Magnum::Vector3& spotDirection(); - Magnum::Vector3 spotDirection() const; + // Magnum::Vector3& spot_direction(); + Magnum::Vector3 spot_direction() const; - Magnum::Vector3& transformedSpotDirection(); - Magnum::Vector3 transformedSpotDirection() const; + Magnum::Vector3& transformed_spot_direction(); + Magnum::Vector3 transformed_spot_direction() const; - Magnum::Float& spotExponent(); - Magnum::Float spotExponent() const; + Magnum::Float& spot_exponent(); + Magnum::Float spot_exponent() const; - Magnum::Float& spotCutOff(); - Magnum::Float spotCutOff() const; + Magnum::Float& spot_cut_off(); + Magnum::Float spot_cut_off() const; Magnum::Vector4& attenuation(); Magnum::Vector4 attenuation() const; - Magnum::Matrix4 shadowMatrix() const; + Magnum::Matrix4 shadow_matrix() const; - Light& setPosition(const Magnum::Vector4& position); - Light& setTransformedPosition(const Magnum::Vector4& transformedPosition); + Light& set_position(const Magnum::Vector4& position); + Light& set_transformed_position(const Magnum::Vector4& transformed_position); - Light& setMaterial(const Material& material); + Light& set_material(const Material& material); - Light& setSpotDirection(const Magnum::Vector3& spotDirection); - Light& setTransformedSpotDirection(const Magnum::Vector3& transformedSpotDirection); - Light& setSpotExponent(Magnum::Float spotExponent); - Light& setSpotCutOff(Magnum::Float spotCutOff); + Light& set_spot_direction(const Magnum::Vector3& spot_direction); + Light& set_transformed_spot_direction(const Magnum::Vector3& transformed_spot_direction); + Light& set_spot_exponent(Magnum::Float spot_exponent); + Light& set_spot_cut_off(Magnum::Float spot_cut_off); - Light& setAttenuation(const Magnum::Vector4& attenuation); + Light& set_attenuation(const Magnum::Vector4& attenuation); - Light& setShadowMatrix(const Magnum::Matrix4& shadowTransform); + Light& set_shadow_matrix(const Magnum::Matrix4& shadowTransform); protected: // Position for point-lights and spot-lights // Direction for directional lights (if position.w == 0) Magnum::Vector4 _position; // TO-DO: Handle dirtiness of transformed position - Magnum::Vector4 _transformedPosition; + Magnum::Vector4 _transformed_position; Material _material; - Magnum::Vector3 _spotDirection; + Magnum::Vector3 _spot_direction; // TO-DO: Handle dirtiness of transformed spot direction - Magnum::Vector3 _transformedSpotDirection; - Magnum::Float _spotExponent, _spotCutOff; + Magnum::Vector3 _transformed_spot_direction; + Magnum::Float _spot_exponent, _spot_cut_off; // Attenuation is: intensity/(constant + d * (linear + quadratic * d) // where d is the distance from the light position to the vertex position. @@ -74,35 +74,35 @@ namespace robot_dart { Magnum::Vector4 _attenuation; // Shadow-Matrix - Magnum::Matrix4 _shadowTransform{}; + Magnum::Matrix4 _shadow_transform{}; }; // Helpers for creating lights - inline Light createPointLight(const Magnum::Vector3& position, const Material& material, + inline Light create_point_light(const Magnum::Vector3& position, const Material& material, Magnum::Float intensity, const Magnum::Vector3& attenuationTerms) { Light light; - light.setMaterial(material); - light.setPosition(Magnum::Vector4{position, 1.f}) - .setAttenuation(Magnum::Vector4{attenuationTerms, intensity}); + light.set_material(material); + light.set_position(Magnum::Vector4{position, 1.f}) + .set_attenuation(Magnum::Vector4{attenuationTerms, intensity}); return light; } - inline Light createSpotLight(const Magnum::Vector3& position, const Material& material, - const Magnum::Vector3& spotDirection, Magnum::Float spotExponent, Magnum::Float spotCutOff, + inline Light create_spot_light(const Magnum::Vector3& position, const Material& material, + const Magnum::Vector3& spot_direction, Magnum::Float spot_exponent, Magnum::Float spot_cut_off, Magnum::Float intensity, const Magnum::Vector3& attenuationTerms) { - return Light(Magnum::Vector4{position, 1.f}, material, spotDirection, spotExponent, spotCutOff, + return Light(Magnum::Vector4{position, 1.f}, material, spot_direction, spot_exponent, spot_cut_off, Magnum::Vector4{attenuationTerms, intensity}); } - inline Light createDirectionalLight( + inline Light create_directional_light( const Magnum::Vector3& direction, const Material& material) { Light light; - light.setMaterial(material); - light.setPosition(Magnum::Vector4{direction, 0.f}); + light.set_material(material); + light.set_position(Magnum::Vector4{direction, 0.f}); return light; } diff --git a/src/robot_dart/gui/magnum/gs/material.cpp b/src/robot_dart/gui/magnum/gs/material.cpp index c7410d26..73e0c8cd 100644 --- a/src/robot_dart/gui/magnum/gs/material.cpp +++ b/src/robot_dart/gui/magnum/gs/material.cpp @@ -17,75 +17,75 @@ namespace robot_dart { _specular(specular), _shininess(shininess) {} - Material::Material(Magnum::GL::Texture2D* ambientTexture, - Magnum::GL::Texture2D* diffuseTexture, - Magnum::GL::Texture2D* specularTexture, Magnum::Float shininess) : _ambient(Magnum::Color4{0.f, 0.f, 0.f, 1.f}), + Material::Material(Magnum::GL::Texture2D* ambient_texture, + Magnum::GL::Texture2D* diffuse_texture, + Magnum::GL::Texture2D* specular_texture, Magnum::Float shininess) : _ambient(Magnum::Color4{0.f, 0.f, 0.f, 1.f}), _diffuse(Magnum::Color4{0.f, 0.f, 0.f, 1.f}), _specular(Magnum::Color4{0.f, 0.f, 0.f, 1.f}), _shininess(shininess), - _ambientTexture(ambientTexture), - _diffuseTexture(diffuseTexture), - _specularTexture(specularTexture) {} + _ambient_texture(ambient_texture), + _diffuse_texture(diffuse_texture), + _specular_texture(specular_texture) {} - Magnum::Color4& Material::ambientColor() { return _ambient; } - Magnum::Color4 Material::ambientColor() const { return _ambient; } + Magnum::Color4& Material::ambient_color() { return _ambient; } + Magnum::Color4 Material::ambient_color() const { return _ambient; } - Magnum::Color4& Material::diffuseColor() { return _diffuse; } - Magnum::Color4 Material::diffuseColor() const { return _diffuse; } + Magnum::Color4& Material::diffuse_color() { return _diffuse; } + Magnum::Color4 Material::diffuse_color() const { return _diffuse; } - Magnum::Color4& Material::specularColor() { return _specular; } - Magnum::Color4 Material::specularColor() const { return _specular; } + Magnum::Color4& Material::specular_color() { return _specular; } + Magnum::Color4 Material::specular_color() const { return _specular; } Magnum::Float& Material::shininess() { return _shininess; } Magnum::Float Material::shininess() const { return _shininess; } - Magnum::GL::Texture2D* Material::ambientTexture() { return _ambientTexture; } - Magnum::GL::Texture2D* Material::diffuseTexture() { return _diffuseTexture; } - Magnum::GL::Texture2D* Material::specularTexture() { return _specularTexture; } + Magnum::GL::Texture2D* Material::ambient_texture() { return _ambient_texture; } + Magnum::GL::Texture2D* Material::diffuse_texture() { return _diffuse_texture; } + Magnum::GL::Texture2D* Material::specular_texture() { return _specular_texture; } - bool Material::hasAmbientTexture() const { return _ambientTexture != NULL; } - bool Material::hasDiffuseTexture() const { return _diffuseTexture != NULL; } - bool Material::hasSpecularTexture() const { return _specularTexture != NULL; } + bool Material::has_ambient_texture() const { return _ambient_texture != NULL; } + bool Material::has_diffuse_texture() const { return _diffuse_texture != NULL; } + bool Material::has_specular_texture() const { return _specular_texture != NULL; } - Material& Material::setAmbientColor(const Magnum::Color4& ambient) + Material& Material::set_ambient_color(const Magnum::Color4& ambient) { _ambient = ambient; return *this; } - Material& Material::setDiffuseColor(const Magnum::Color4& diffuse) + Material& Material::set_diffuse_color(const Magnum::Color4& diffuse) { _diffuse = diffuse; return *this; } - Material& Material::setSpecularColor(const Magnum::Color4& specular) + Material& Material::set_specular_color(const Magnum::Color4& specular) { _specular = specular; return *this; } - Material& Material::setShininess(Magnum::Float shininess) + Material& Material::set_shininess(Magnum::Float shininess) { _shininess = shininess; return *this; } - Material& Material::setAmbientTexture(Magnum::GL::Texture2D* ambientTexture) + Material& Material::set_ambient_texture(Magnum::GL::Texture2D* ambient_texture) { - _ambientTexture = ambientTexture; + _ambient_texture = ambient_texture; return *this; } - Material& Material::setDiffuseTexture(Magnum::GL::Texture2D* diffuseTexture) + Material& Material::set_diffuse_texture(Magnum::GL::Texture2D* diffuse_texture) { - _diffuseTexture = diffuseTexture; + _diffuse_texture = diffuse_texture; return *this; } - Material& Material::setSpecularTexture(Magnum::GL::Texture2D* specularTexture) + Material& Material::set_specular_texture(Magnum::GL::Texture2D* specular_texture) { - _specularTexture = specularTexture; + _specular_texture = specular_texture; return *this; } } // namespace gs diff --git a/src/robot_dart/gui/magnum/gs/material.hpp b/src/robot_dart/gui/magnum/gs/material.hpp index 4a42e556..5ea19617 100644 --- a/src/robot_dart/gui/magnum/gs/material.hpp +++ b/src/robot_dart/gui/magnum/gs/material.hpp @@ -18,45 +18,45 @@ namespace robot_dart { Material(const Magnum::Color4& ambient, const Magnum::Color4& diffuse, const Magnum::Color4& specular, Magnum::Float shininess); - Material(Magnum::GL::Texture2D* ambientTexture, - Magnum::GL::Texture2D* diffuseTexture, - Magnum::GL::Texture2D* specularTexture, Magnum::Float shininess); + Material(Magnum::GL::Texture2D* ambient_texture, + Magnum::GL::Texture2D* diffuse_texture, + Magnum::GL::Texture2D* specular_texture, Magnum::Float shininess); - Magnum::Color4& ambientColor(); - Magnum::Color4 ambientColor() const; + Magnum::Color4& ambient_color(); + Magnum::Color4 ambient_color() const; - Magnum::Color4& diffuseColor(); - Magnum::Color4 diffuseColor() const; + Magnum::Color4& diffuse_color(); + Magnum::Color4 diffuse_color() const; - Magnum::Color4& specularColor(); - Magnum::Color4 specularColor() const; + Magnum::Color4& specular_color(); + Magnum::Color4 specular_color() const; Magnum::Float& shininess(); Magnum::Float shininess() const; - Magnum::GL::Texture2D* ambientTexture(); - Magnum::GL::Texture2D* diffuseTexture(); - Magnum::GL::Texture2D* specularTexture(); + Magnum::GL::Texture2D* ambient_texture(); + Magnum::GL::Texture2D* diffuse_texture(); + Magnum::GL::Texture2D* specular_texture(); - bool hasAmbientTexture() const; - bool hasDiffuseTexture() const; - bool hasSpecularTexture() const; + bool has_ambient_texture() const; + bool has_diffuse_texture() const; + bool has_specular_texture() const; - Material& setAmbientColor(const Magnum::Color4& ambient); - Material& setDiffuseColor(const Magnum::Color4& diffuse); - Material& setSpecularColor(const Magnum::Color4& specular); - Material& setShininess(Magnum::Float shininess); + Material& set_ambient_color(const Magnum::Color4& ambient); + Material& set_diffuse_color(const Magnum::Color4& diffuse); + Material& set_specular_color(const Magnum::Color4& specular); + Material& set_shininess(Magnum::Float shininess); - Material& setAmbientTexture(Magnum::GL::Texture2D* ambientTexture); - Material& setDiffuseTexture(Magnum::GL::Texture2D* diffuseTexture); - Material& setSpecularTexture(Magnum::GL::Texture2D* specularTexture); + Material& set_ambient_texture(Magnum::GL::Texture2D* ambient_texture); + Material& set_diffuse_texture(Magnum::GL::Texture2D* diffuse_texture); + Material& set_specular_texture(Magnum::GL::Texture2D* specular_texture); protected: Magnum::Color4 _ambient, _diffuse, _specular; Magnum::Float _shininess; - Magnum::GL::Texture2D* _ambientTexture = NULL; - Magnum::GL::Texture2D* _diffuseTexture = NULL; - Magnum::GL::Texture2D* _specularTexture = NULL; + Magnum::GL::Texture2D* _ambient_texture = NULL; + Magnum::GL::Texture2D* _diffuse_texture = NULL; + Magnum::GL::Texture2D* _specular_texture = NULL; }; } // namespace gs } // namespace magnum diff --git a/src/robot_dart/gui/magnum/gs/phong_multi_light.cpp b/src/robot_dart/gui/magnum/gs/phong_multi_light.cpp index 942f6d34..c076b37c 100644 --- a/src/robot_dart/gui/magnum/gs/phong_multi_light.cpp +++ b/src/robot_dart/gui/magnum/gs/phong_multi_light.cpp @@ -1,8 +1,6 @@ #include "phong_multi_light.hpp" #include "create_compatibility_shader.hpp" -#include "../resources/generic.glsl" - #include #include #include @@ -11,12 +9,8 @@ namespace robot_dart { namespace gui { namespace magnum { namespace gs { - PhongMultiLight::PhongMultiLight(PhongMultiLight::Flags flags, Magnum::Int maxLights) : _flags(flags), _maxLights(maxLights) + PhongMultiLight::PhongMultiLight(PhongMultiLight::Flags flags, Magnum::Int max_lights) : _flags(flags), _max_lights(max_lights) { - static_assert(Position::Location == POSITION_ATTRIBUTE_LOCATION, "Shader Position Attribute Location Error!"); - static_assert(Normal::Location == NORMAL_ATTRIBUTE_LOCATION, "Shader Normal Attribute Location Error!"); - static_assert(TextureCoordinates::Location == TEXTURECOORDINATES_ATTRIBUTE_LOCATION, "Shader TextureCoordinates Attribute Location Error!"); - Corrade::Utility::Resource rs_shaders("RobotDARTShaders"); const Magnum::GL::Version version = Magnum::GL::Version::GL320; @@ -26,11 +20,13 @@ namespace robot_dart { Magnum::GL::Shader frag = Magnum::Shaders::Implementation::createCompatibilityShader( rs_shaders, version, Magnum::GL::Shader::Type::Fragment); - std::string defines = "#define LIGHT_COUNT " + std::to_string(_maxLights) + "\n"; + std::string defines = "#define LIGHT_COUNT " + std::to_string(_max_lights) + "\n"; + defines += "#define POSITION_ATTRIBUTE_LOCATION " + std::to_string(Position::Location) + "\n"; + defines += "#define NORMAL_ATTRIBUTE_LOCATION " + std::to_string(Normal::Location) + "\n"; + defines += "#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION " + std::to_string(TextureCoordinates::Location) + "\n"; vert.addSource(flags ? "#define TEXTURED\n" : "") .addSource(defines) - .addSource(rs_shaders.get("generic.glsl")) .addSource(rs_shaders.get("PhongMultiLight.vert")); frag.addSource(flags & Flag::AmbientTexture ? "#define AMBIENT_TEXTURE\n" : "") .addSource(flags & Flag::DiffuseTexture ? "#define DIFFUSE_TEXTURE\n" : "") @@ -52,30 +48,30 @@ namespace robot_dart { CORRADE_INTERNAL_ASSERT_OUTPUT(link()); /* Get light matrices uniform */ - _lightsMatricesUniform = uniformLocation("lightMatrices[0]"); + _lights_matrices_uniform = uniformLocation("lightMatrices[0]"); if (!Magnum::GL::Context::current().isExtensionSupported(version)) { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); - _projectionMatrixUniform = uniformLocation("projectionMatrix"); - _cameraMatrixUniform = uniformLocation("cameraMatrix"); - _normalMatrixUniform = uniformLocation("normalMatrix"); - _lightsUniform = uniformLocation("lights[0].position"); - _lightsMatricesUniform = uniformLocation("lightMatrices[0]"); - _ambientColorUniform = uniformLocation("ambientColor"); - _diffuseColorUniform = uniformLocation("diffuseColor"); - _specularColorUniform = uniformLocation("specularColor"); - _shininessUniform = uniformLocation("shininess"); - _farPlaneUniform = uniformLocation("farPlane"); - _isShadowedUniform = uniformLocation("isShadowed"); - _drawTransparentShadowsUniform = uniformLocation("drawTransparentShadows"); + _transformation_matrix_uniform = uniformLocation("transformationMatrix"); + _projection_matrix_uniform = uniformLocation("projectionMatrix"); + _camera_matrix_uniform = uniformLocation("cameraMatrix"); + _normal_matrix_uniform = uniformLocation("normalMatrix"); + _lights_uniform = uniformLocation("lights[0].position"); + _lights_matrices_uniform = uniformLocation("lightMatrices[0]"); + _ambient_color_uniform = uniformLocation("ambientColor"); + _diffuse_color_uniform = uniformLocation("diffuseColor"); + _specular_color_uniform = uniformLocation("specularColor"); + _shininess_uniform = uniformLocation("shininess"); + _far_plane_uniform = uniformLocation("farPlane"); + _is_shadowed_uniform = uniformLocation("isShadowed"); + _transparent_shadows_uniform = uniformLocation("drawTransparentShadows"); } if (!Magnum::GL::Context::current() .isExtensionSupported(version)) { - setUniform(uniformLocation("shadowTextures"), _shadowTexturesLocation); - setUniform(uniformLocation("cubeMapTextures"), _cubeMapTexturesLocation); - setUniform(uniformLocation("shadowColorTextures"), _shadowColorTexturesLocation); - setUniform(uniformLocation("cubeMapColorTextures"), _cubeMapColorTexturesLocation); + setUniform(uniformLocation("shadowTextures"), _shadow_textures_location); + setUniform(uniformLocation("cubeMapTextures"), _cube_map_textures_location); + setUniform(uniformLocation("shadowColorTextures"), _shadow_color_textures_location); + setUniform(uniformLocation("cubeMapColorTextures"), _cube_map_color_textures_location); if (flags) { if (flags & Flag::AmbientTexture) setUniform(uniformLocation("ambientTexture"), AmbientTextureLayer); @@ -91,157 +87,157 @@ namespace robot_dart { /* Default to fully opaque white so we can see the textures */ if (flags & Flag::AmbientTexture) - material.setAmbientColor(Magnum::Color4{1.0f}); + material.set_ambient_color(Magnum::Color4{1.0f}); else - material.setAmbientColor(Magnum::Color4{0.0f, 1.0f}); + material.set_ambient_color(Magnum::Color4{0.0f, 1.0f}); if (flags & Flag::DiffuseTexture) - material.setDiffuseColor(Magnum::Color4{1.0f}); + material.set_diffuse_color(Magnum::Color4{1.0f}); - material.setSpecularColor(Magnum::Color4{1.0f}); - material.setShininess(80.0f); + material.set_specular_color(Magnum::Color4{1.0f}); + material.set_shininess(80.0f); - setMaterial(material); + set_material(material); /* Lights defaults need to be set by code */ /* All lights are disabled i.e., color equal to black */ Light light; - for (Magnum::Int i = 0; i < _maxLights; i++) - setLight(i, light); + for (Magnum::Int i = 0; i < _max_lights; i++) + set_light(i, light); } PhongMultiLight::PhongMultiLight(Magnum::NoCreateT) noexcept : Magnum::GL::AbstractShaderProgram{Magnum::NoCreate} {} PhongMultiLight::Flags PhongMultiLight::flags() const { return _flags; } - PhongMultiLight& PhongMultiLight::setMaterial(Material& material) + PhongMultiLight& PhongMultiLight::set_material(Material& material) { // TO-DO: Check if we should do this or let the user define the proper // material - if (material.hasAmbientTexture() && (_flags & Flag::AmbientTexture)) { - (*material.ambientTexture()).bind(AmbientTextureLayer); - setUniform(_ambientColorUniform, Magnum::Color4{1.0f}); + if (material.has_ambient_texture() && (_flags & Flag::AmbientTexture)) { + (*material.ambient_texture()).bind(AmbientTextureLayer); + setUniform(_ambient_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_ambientColorUniform, material.ambientColor()); + setUniform(_ambient_color_uniform, material.ambient_color()); - if (material.hasDiffuseTexture() && (_flags & Flag::DiffuseTexture)) { - (*material.diffuseTexture()).bind(DiffuseTextureLayer); - setUniform(_diffuseColorUniform, Magnum::Color4{1.0f}); + if (material.has_diffuse_texture() && (_flags & Flag::DiffuseTexture)) { + (*material.diffuse_texture()).bind(DiffuseTextureLayer); + setUniform(_diffuse_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_diffuseColorUniform, material.diffuseColor()); + setUniform(_diffuse_color_uniform, material.diffuse_color()); - if (material.hasSpecularTexture() && (_flags & Flag::SpecularTexture)) { - (*material.specularTexture()).bind(SpecularTextureLayer); - setUniform(_specularColorUniform, Magnum::Color4{1.0f}); + if (material.has_specular_texture() && (_flags & Flag::SpecularTexture)) { + (*material.specular_texture()).bind(SpecularTextureLayer); + setUniform(_specular_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_specularColorUniform, material.specularColor()); + setUniform(_specular_color_uniform, material.specular_color()); - setUniform(_shininessUniform, material.shininess()); + setUniform(_shininess_uniform, material.shininess()); return *this; } - PhongMultiLight& PhongMultiLight::setLight(Magnum::Int i, const Light& light) + PhongMultiLight& PhongMultiLight::set_light(Magnum::Int i, const Light& light) { - CORRADE_INTERNAL_ASSERT(i >= 0 && i < _maxLights); + CORRADE_INTERNAL_ASSERT(i >= 0 && i < _max_lights); Magnum::Vector4 attenuation = light.attenuation(); // light position - setUniform(_lightsUniform + i * _lightLocSize, light.transformedPosition()); + setUniform(_lights_uniform + i * _light_loc_size, light.transformed_position()); // light material - setUniform(_lightsUniform + i * _lightLocSize + 1, light.material().ambientColor()); - setUniform(_lightsUniform + i * _lightLocSize + 2, light.material().diffuseColor()); - setUniform(_lightsUniform + i * _lightLocSize + 3, light.material().specularColor()); + setUniform(_lights_uniform + i * _light_loc_size + 1, light.material().ambient_color()); + setUniform(_lights_uniform + i * _light_loc_size + 2, light.material().diffuse_color()); + setUniform(_lights_uniform + i * _light_loc_size + 3, light.material().specular_color()); // spotlight properties - setUniform(_lightsUniform + i * _lightLocSize + 4, light.transformedSpotDirection()); - setUniform(_lightsUniform + i * _lightLocSize + 5, light.spotExponent()); - setUniform(_lightsUniform + i * _lightLocSize + 6, light.spotCutOff()); + setUniform(_lights_uniform + i * _light_loc_size + 4, light.transformed_spot_direction()); + setUniform(_lights_uniform + i * _light_loc_size + 5, light.spot_exponent()); + setUniform(_lights_uniform + i * _light_loc_size + 6, light.spot_cut_off()); // intesity - setUniform(_lightsUniform + i * _lightLocSize + 7, attenuation[3]); + setUniform(_lights_uniform + i * _light_loc_size + 7, attenuation[3]); // constant attenuation term - setUniform(_lightsUniform + i * _lightLocSize + 8, attenuation[0]); + setUniform(_lights_uniform + i * _light_loc_size + 8, attenuation[0]); // linear attenuation term - setUniform(_lightsUniform + i * _lightLocSize + 9, attenuation[1]); + setUniform(_lights_uniform + i * _light_loc_size + 9, attenuation[1]); // quadratic attenuation term - setUniform(_lightsUniform + i * _lightLocSize + 10, attenuation[2]); + setUniform(_lights_uniform + i * _light_loc_size + 10, attenuation[2]); // world position - setUniform(_lightsUniform + i * _lightLocSize + 11, light.position()); + setUniform(_lights_uniform + i * _light_loc_size + 11, light.position()); - setUniform(_lightsMatricesUniform + i, light.shadowMatrix()); + setUniform(_lights_matrices_uniform + i, light.shadow_matrix()); return *this; } - PhongMultiLight& PhongMultiLight::setTransformationMatrix(const Magnum::Matrix4& matrix) + PhongMultiLight& PhongMultiLight::set_transformation_matrix(const Magnum::Matrix4& matrix) { - setUniform(_transformationMatrixUniform, matrix); + setUniform(_transformation_matrix_uniform, matrix); return *this; } - PhongMultiLight& PhongMultiLight::setCameraMatrix(const Magnum::Matrix4& matrix) + PhongMultiLight& PhongMultiLight::set_camera_matrix(const Magnum::Matrix4& matrix) { - setUniform(_cameraMatrixUniform, matrix); + setUniform(_camera_matrix_uniform, matrix); return *this; } - PhongMultiLight& PhongMultiLight::setNormalMatrix(const Magnum::Matrix3x3& matrix) + PhongMultiLight& PhongMultiLight::set_normal_matrix(const Magnum::Matrix3x3& matrix) { - setUniform(_normalMatrixUniform, matrix); + setUniform(_normal_matrix_uniform, matrix); return *this; } - PhongMultiLight& PhongMultiLight::setProjectionMatrix(const Magnum::Matrix4& matrix) + PhongMultiLight& PhongMultiLight::set_projection_matrix(const Magnum::Matrix4& matrix) { - setUniform(_projectionMatrixUniform, matrix); + setUniform(_projection_matrix_uniform, matrix); return *this; } - PhongMultiLight& PhongMultiLight::setFarPlane(Magnum::Float farPlane) + PhongMultiLight& PhongMultiLight::set_far_plane(Magnum::Float far_plane) { - setUniform(_farPlaneUniform, farPlane); + setUniform(_far_plane_uniform, far_plane); return *this; } - PhongMultiLight& PhongMultiLight::setIsShadowed(bool shadows) + PhongMultiLight& PhongMultiLight::set_is_shadowed(bool shadows) { - setUniform(_isShadowedUniform, shadows); + setUniform(_is_shadowed_uniform, shadows); return *this; } - PhongMultiLight& PhongMultiLight::setTransparentShadows(bool shadows) + PhongMultiLight& PhongMultiLight::set_transparent_shadows(bool shadows) { - setUniform(_drawTransparentShadowsUniform, shadows); + setUniform(_transparent_shadows_uniform, shadows); return *this; } - PhongMultiLight& PhongMultiLight::bindShadowTexture(Magnum::GL::Texture2DArray& texture) + PhongMultiLight& PhongMultiLight::bind_shadow_texture(Magnum::GL::Texture2DArray& texture) { - texture.bind(_shadowTexturesLocation); + texture.bind(_shadow_textures_location); return *this; } - PhongMultiLight& PhongMultiLight::bindShadowColorTexture(Magnum::GL::Texture2DArray& texture) + PhongMultiLight& PhongMultiLight::bind_shadow_color_texture(Magnum::GL::Texture2DArray& texture) { - texture.bind(_shadowColorTexturesLocation); + texture.bind(_shadow_color_textures_location); return *this; } - PhongMultiLight& PhongMultiLight::bindCubeMapTexture(Magnum::GL::CubeMapTextureArray& texture) + PhongMultiLight& PhongMultiLight::bind_cube_map_texture(Magnum::GL::CubeMapTextureArray& texture) { - texture.bind(_cubeMapTexturesLocation); + texture.bind(_cube_map_textures_location); return *this; } - PhongMultiLight& PhongMultiLight::bindCubeMapColorTexture(Magnum::GL::CubeMapTextureArray& texture) + PhongMultiLight& PhongMultiLight::bind_cube_map_color_texture(Magnum::GL::CubeMapTextureArray& texture) { - texture.bind(_cubeMapColorTexturesLocation); + texture.bind(_cube_map_color_textures_location); return *this; } - Magnum::Int PhongMultiLight::maxLights() const { return _maxLights; } + Magnum::Int PhongMultiLight::max_lights() const { return _max_lights; } } // namespace gs } // namespace magnum } // namespace gui diff --git a/src/robot_dart/gui/magnum/gs/phong_multi_light.hpp b/src/robot_dart/gui/magnum/gs/phong_multi_light.hpp index bcf71eaf..0df9fd2a 100644 --- a/src/robot_dart/gui/magnum/gs/phong_multi_light.hpp +++ b/src/robot_dart/gui/magnum/gs/phong_multi_light.hpp @@ -30,38 +30,38 @@ namespace robot_dart { using Flags = Magnum::Containers::EnumSet; - explicit PhongMultiLight(Flags flags = {}, Magnum::Int maxLights = 10); + explicit PhongMultiLight(Flags flags = {}, Magnum::Int max_lights = 10); explicit PhongMultiLight(Magnum::NoCreateT) noexcept; Flags flags() const; - PhongMultiLight& setMaterial(Material& material); - PhongMultiLight& setLight(Magnum::Int i, const Light& light); + PhongMultiLight& set_material(Material& material); + PhongMultiLight& set_light(Magnum::Int i, const Light& light); - PhongMultiLight& setTransformationMatrix(const Magnum::Matrix4& matrix); - PhongMultiLight& setCameraMatrix(const Magnum::Matrix4& matrix); - PhongMultiLight& setNormalMatrix(const Magnum::Matrix3x3& matrix); - PhongMultiLight& setProjectionMatrix(const Magnum::Matrix4& matrix); + PhongMultiLight& set_transformation_matrix(const Magnum::Matrix4& matrix); + PhongMultiLight& set_camera_matrix(const Magnum::Matrix4& matrix); + PhongMultiLight& set_normal_matrix(const Magnum::Matrix3x3& matrix); + PhongMultiLight& set_projection_matrix(const Magnum::Matrix4& matrix); - PhongMultiLight& setFarPlane(Magnum::Float farPlane); - PhongMultiLight& setIsShadowed(bool shadows); - PhongMultiLight& setTransparentShadows(bool shadows); + PhongMultiLight& set_far_plane(Magnum::Float far_plane); + PhongMultiLight& set_is_shadowed(bool shadows); + PhongMultiLight& set_transparent_shadows(bool shadows); - PhongMultiLight& bindShadowTexture(Magnum::GL::Texture2DArray& texture); - PhongMultiLight& bindShadowColorTexture(Magnum::GL::Texture2DArray& texture); - PhongMultiLight& bindCubeMapTexture(Magnum::GL::CubeMapTextureArray& texture); - PhongMultiLight& bindCubeMapColorTexture(Magnum::GL::CubeMapTextureArray& texture); + PhongMultiLight& bind_shadow_texture(Magnum::GL::Texture2DArray& texture); + PhongMultiLight& bind_shadow_color_texture(Magnum::GL::Texture2DArray& texture); + PhongMultiLight& bind_cube_map_texture(Magnum::GL::CubeMapTextureArray& texture); + PhongMultiLight& bind_cube_map_color_texture(Magnum::GL::CubeMapTextureArray& texture); - Magnum::Int maxLights() const; + Magnum::Int max_lights() const; private: Flags _flags; - Magnum::Int _maxLights = 10; - Magnum::Int _transformationMatrixUniform{0}, _cameraMatrixUniform{7}, _projectionMatrixUniform{1}, _normalMatrixUniform{2}, - _shininessUniform{3}, _ambientColorUniform{4}, _diffuseColorUniform{5}, _specularColorUniform{6}, - _lightsUniform{11}, _lightsMatricesUniform, _farPlaneUniform{8}, _isShadowedUniform{9}, _drawTransparentShadowsUniform{10}, - _shadowTexturesLocation{3}, _cubeMapTexturesLocation{4}, _shadowColorTexturesLocation{5}, _cubeMapColorTexturesLocation{6}; - const Magnum::Int _lightLocSize = 12; + Magnum::Int _max_lights = 10; + Magnum::Int _transformation_matrix_uniform{0}, _camera_matrix_uniform{7}, _projection_matrix_uniform{1}, _normal_matrix_uniform{2}, + _shininess_uniform{3}, _ambient_color_uniform{4}, _diffuse_color_uniform{5}, _specular_color_uniform{6}, + _lights_uniform{11}, _lights_matrices_uniform, _far_plane_uniform{8}, _is_shadowed_uniform{9}, _transparent_shadows_uniform{10}, + _shadow_textures_location{3}, _cube_map_textures_location{4}, _shadow_color_textures_location{5}, _cube_map_color_textures_location{6}; + const Magnum::Int _light_loc_size = 12; }; CORRADE_ENUMSET_OPERATORS(PhongMultiLight::Flags) diff --git a/src/robot_dart/gui/magnum/gs/shadow_map.cpp b/src/robot_dart/gui/magnum/gs/shadow_map.cpp index a8c18157..033a6467 100644 --- a/src/robot_dart/gui/magnum/gs/shadow_map.cpp +++ b/src/robot_dart/gui/magnum/gs/shadow_map.cpp @@ -18,8 +18,11 @@ namespace robot_dart { Magnum::GL::Shader frag = Magnum::Shaders::Implementation::createCompatibilityShader( rs_shaders, version, Magnum::GL::Shader::Type::Fragment); + std::string defines = "#define POSITION_ATTRIBUTE_LOCATION " + std::to_string(Position::Location) + "\n"; + defines += "#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION " + std::to_string(TextureCoordinates::Location) + "\n"; + vert.addSource(flags ? "#define TEXTURED\n" : "") - .addSource(rs_shaders.get("generic.glsl")) + .addSource(defines) .addSource(rs_shaders.get("ShadowMap.vert")); frag.addSource(flags ? "#define TEXTURED\n" : "") .addSource(rs_shaders.get("ShadowMap.frag")); @@ -37,9 +40,9 @@ namespace robot_dart { CORRADE_INTERNAL_ASSERT_OUTPUT(link()); if (!Magnum::GL::Context::current().isExtensionSupported(version)) { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); - _projectionMatrixUniform = uniformLocation("projectionMatrix"); - _diffuseColorUniform = uniformLocation("diffuseColor"); + _transformation_matrix_uniform = uniformLocation("transformationMatrix"); + _projection_matrix_uniform = uniformLocation("projectionMatrix"); + _diffuse_color_uniform = uniformLocation("diffuseColor"); } if (!Magnum::GL::Context::current() @@ -53,26 +56,26 @@ namespace robot_dart { ShadowMap::Flags ShadowMap::flags() const { return _flags; } - ShadowMap& ShadowMap::setTransformationMatrix(const Magnum::Matrix4& matrix) + ShadowMap& ShadowMap::set_transformation_matrix(const Magnum::Matrix4& matrix) { - setUniform(_transformationMatrixUniform, matrix); + setUniform(_transformation_matrix_uniform, matrix); return *this; } - ShadowMap& ShadowMap::setProjectionMatrix(const Magnum::Matrix4& matrix) + ShadowMap& ShadowMap::set_projection_matrix(const Magnum::Matrix4& matrix) { - setUniform(_projectionMatrixUniform, matrix); + setUniform(_projection_matrix_uniform, matrix); return *this; } - ShadowMap& ShadowMap::setMaterial(Material& material) + ShadowMap& ShadowMap::set_material(Material& material) { - if (material.hasDiffuseTexture() && (_flags & Flag::DiffuseTexture)) { - (*material.diffuseTexture()).bind(DiffuseTextureLayer); - setUniform(_diffuseColorUniform, Magnum::Color4{1.0f}); + if (material.has_diffuse_texture() && (_flags & Flag::DiffuseTexture)) { + (*material.diffuse_texture()).bind(DiffuseTextureLayer); + setUniform(_diffuse_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_diffuseColorUniform, material.diffuseColor()); + setUniform(_diffuse_color_uniform, material.diffuse_color()); return *this; } diff --git a/src/robot_dart/gui/magnum/gs/shadow_map.hpp b/src/robot_dart/gui/magnum/gs/shadow_map.hpp index 59e60e68..59a18aa3 100644 --- a/src/robot_dart/gui/magnum/gs/shadow_map.hpp +++ b/src/robot_dart/gui/magnum/gs/shadow_map.hpp @@ -32,13 +32,13 @@ namespace robot_dart { Flags flags() const; - ShadowMap& setTransformationMatrix(const Magnum::Matrix4& matrix); - ShadowMap& setProjectionMatrix(const Magnum::Matrix4& matrix); - ShadowMap& setMaterial(Material& material); + ShadowMap& set_transformation_matrix(const Magnum::Matrix4& matrix); + ShadowMap& set_projection_matrix(const Magnum::Matrix4& matrix); + ShadowMap& set_material(Material& material); private: Flags _flags; - Magnum::Int _transformationMatrixUniform{0}, _projectionMatrixUniform{1}, _diffuseColorUniform{2}; + Magnum::Int _transformation_matrix_uniform{0}, _projection_matrix_uniform{1}, _diffuse_color_uniform{2}; }; CORRADE_ENUMSET_OPERATORS(ShadowMap::Flags) diff --git a/src/robot_dart/gui/magnum/gs/shadow_map_color.cpp b/src/robot_dart/gui/magnum/gs/shadow_map_color.cpp index 191be144..42933c5f 100644 --- a/src/robot_dart/gui/magnum/gs/shadow_map_color.cpp +++ b/src/robot_dart/gui/magnum/gs/shadow_map_color.cpp @@ -18,8 +18,11 @@ namespace robot_dart { Magnum::GL::Shader frag = Magnum::Shaders::Implementation::createCompatibilityShader( rs_shaders, version, Magnum::GL::Shader::Type::Fragment); + std::string defines = "#define POSITION_ATTRIBUTE_LOCATION " + std::to_string(Position::Location) + "\n"; + defines += "#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION " + std::to_string(TextureCoordinates::Location) + "\n"; + vert.addSource(flags ? "#define TEXTURED\n" : "") - .addSource(rs_shaders.get("generic.glsl")) + .addSource(defines) .addSource(rs_shaders.get("ShadowMap.vert")); frag.addSource(flags ? "#define TEXTURED\n" : "") .addSource(rs_shaders.get("ShadowMapColor.frag")); @@ -37,9 +40,9 @@ namespace robot_dart { CORRADE_INTERNAL_ASSERT_OUTPUT(link()); if (!Magnum::GL::Context::current().isExtensionSupported(version)) { - _transformationMatrixUniform = uniformLocation("transformationMatrix"); - _projectionMatrixUniform = uniformLocation("projectionMatrix"); - _diffuseColorUniform = uniformLocation("diffuseColor"); + _transformation_matrix_uniform = uniformLocation("transformationMatrix"); + _projection_matrix_uniform = uniformLocation("projectionMatrix"); + _diffuse_color_uniform = uniformLocation("diffuseColor"); } if (!Magnum::GL::Context::current() @@ -53,26 +56,26 @@ namespace robot_dart { ShadowMapColor::Flags ShadowMapColor::flags() const { return _flags; } - ShadowMapColor& ShadowMapColor::setTransformationMatrix(const Magnum::Matrix4& matrix) + ShadowMapColor& ShadowMapColor::set_transformation_matrix(const Magnum::Matrix4& matrix) { - setUniform(_transformationMatrixUniform, matrix); + setUniform(_transformation_matrix_uniform, matrix); return *this; } - ShadowMapColor& ShadowMapColor::setProjectionMatrix(const Magnum::Matrix4& matrix) + ShadowMapColor& ShadowMapColor::set_projection_matrix(const Magnum::Matrix4& matrix) { - setUniform(_projectionMatrixUniform, matrix); + setUniform(_projection_matrix_uniform, matrix); return *this; } - ShadowMapColor& ShadowMapColor::setMaterial(Material& material) + ShadowMapColor& ShadowMapColor::set_material(Material& material) { - if (material.hasDiffuseTexture() && (_flags & Flag::DiffuseTexture)) { - (*material.diffuseTexture()).bind(DiffuseTextureLayer); - setUniform(_diffuseColorUniform, Magnum::Color4{1.0f}); + if (material.has_diffuse_texture() && (_flags & Flag::DiffuseTexture)) { + (*material.diffuse_texture()).bind(DiffuseTextureLayer); + setUniform(_diffuse_color_uniform, Magnum::Color4{1.0f}); } else - setUniform(_diffuseColorUniform, material.diffuseColor()); + setUniform(_diffuse_color_uniform, material.diffuse_color()); return *this; } diff --git a/src/robot_dart/gui/magnum/gs/shadow_map_color.hpp b/src/robot_dart/gui/magnum/gs/shadow_map_color.hpp index 9b68ee4d..9aeb52a8 100644 --- a/src/robot_dart/gui/magnum/gs/shadow_map_color.hpp +++ b/src/robot_dart/gui/magnum/gs/shadow_map_color.hpp @@ -32,13 +32,13 @@ namespace robot_dart { Flags flags() const; - ShadowMapColor& setTransformationMatrix(const Magnum::Matrix4& matrix); - ShadowMapColor& setProjectionMatrix(const Magnum::Matrix4& matrix); - ShadowMapColor& setMaterial(Material& material); + ShadowMapColor& set_transformation_matrix(const Magnum::Matrix4& matrix); + ShadowMapColor& set_projection_matrix(const Magnum::Matrix4& matrix); + ShadowMapColor& set_material(Material& material); private: Flags _flags; - Magnum::Int _transformationMatrixUniform{0}, _projectionMatrixUniform{1}, _diffuseColorUniform{2}; + Magnum::Int _transformation_matrix_uniform{0}, _projection_matrix_uniform{1}, _diffuse_color_uniform{2}; }; CORRADE_ENUMSET_OPERATORS(ShadowMapColor::Flags) diff --git a/src/robot_dart/gui/magnum/resources/generic.glsl b/src/robot_dart/gui/magnum/resources/generic.glsl deleted file mode 100644 index 63000bb0..00000000 --- a/src/robot_dart/gui/magnum/resources/generic.glsl +++ /dev/null @@ -1,16 +0,0 @@ -/* Attribute Locations */ -#define POSITION_ATTRIBUTE_LOCATION 0 -#define TEXTURECOORDINATES_ATTRIBUTE_LOCATION 1 -#define COLOR_ATTRIBUTE_LOCATION 2 -#define TANGENT_ATTRIBUTE_LOCATION 3 -#define BITANGENT_ATTRIBUTE_LOCATION 4 /* also ObjectId */ -#define OBJECT_ID_ATTRIBUTE_LOCATION 4 /* also Bitangent */ -#define NORMAL_ATTRIBUTE_LOCATION 5 - -#define TRANSFORMATION_MATRIX_ATTRIBUTE_LOCATION 8 -#define NORMAL_MATRIX_ATTRIBUTE_LOCATION 12 -#define TEXTURE_OFFSET_ATTRIBUTE_LOCATION 15 - -/* Outputs */ -#define COLOR_OUTPUT_ATTRIBUTE_LOCATION 0 -#define OBJECT_ID_OUTPUT_ATTRIBUTE_LOCATION 1 diff --git a/src/robot_dart/gui/magnum/resources/resources.conf b/src/robot_dart/gui/magnum/resources/resources.conf index e55f9e9c..f35e415d 100644 --- a/src/robot_dart/gui/magnum/resources/resources.conf +++ b/src/robot_dart/gui/magnum/resources/resources.conf @@ -29,6 +29,3 @@ filename=CubeMapColor.frag [file] filename=compatibility.glsl - -[file] -filename=generic.glsl \ No newline at end of file diff --git a/src/robot_dart/gui/magnum/windowless_gl_application.cpp b/src/robot_dart/gui/magnum/windowless_gl_application.cpp index 2e912107..552f9a17 100644 --- a/src/robot_dart/gui/magnum/windowless_gl_application.cpp +++ b/src/robot_dart/gui/magnum/windowless_gl_application.cpp @@ -7,8 +7,9 @@ namespace robot_dart { namespace gui { namespace magnum { - WindowlessGLApplication::WindowlessGLApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, size_t width, size_t height, const std::string& title, bool isShadowed, bool drawTransparentShadows) - : BaseApplication(isShadowed, drawTransparentShadows), Magnum::Platform::WindowlessApplication({argc, argv}, Magnum::NoCreate) + WindowlessGLApplication::WindowlessGLApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, const GraphicsConfiguration& configuration) + : BaseApplication(configuration), + Magnum::Platform::WindowlessApplication({argc, argv}, Magnum::NoCreate) { /* Assume context is given externally, if not create it */ if (!Magnum::GL::Context::hasCurrent()) { @@ -22,7 +23,7 @@ namespace robot_dart { // Corrade::Utility::Debug{} << "Created context with: " << Magnum::GL::Context::current().versionString(); /* Create FrameBuffer to draw */ - int w = width, h = height; + int w = configuration.width, h = configuration.height; _framebuffer = Magnum::GL::Framebuffer({{}, {w, h}}); _color = Magnum::GL::Renderbuffer(); _depth = Magnum::GL::Renderbuffer(); @@ -37,22 +38,22 @@ namespace robot_dart { Magnum::GL::Framebuffer::BufferAttachment::Depth, _depth); /* Initialize DART world */ - init(world, width, height); + init(world, configuration.width, configuration.height); record(true); } WindowlessGLApplication::~WindowlessGLApplication() { - GLCleanUp(); + _gl_clean_up(); } void WindowlessGLApplication::render() { /* Update graphic meshes/materials and render */ - updateGraphics(); + update_graphics(); /* Update lights transformations */ - updateLights(*_camera); + update_lights(*_camera); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::DepthTest); Magnum::GL::Renderer::enable(Magnum::GL::Renderer::Feature::FaceCulling); diff --git a/src/robot_dart/gui/magnum/windowless_gl_application.hpp b/src/robot_dart/gui/magnum/windowless_gl_application.hpp index 9aaca469..8ad0beeb 100644 --- a/src/robot_dart/gui/magnum/windowless_gl_application.hpp +++ b/src/robot_dart/gui/magnum/windowless_gl_application.hpp @@ -11,7 +11,7 @@ namespace robot_dart { namespace magnum { class WindowlessGLApplication : public BaseApplication, public Magnum::Platform::WindowlessApplication { public: - explicit WindowlessGLApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, size_t width, size_t height, const std::string& title = "DART", bool isShadowed = true, bool drawTransparentShadows = true); + explicit WindowlessGLApplication(int argc, char** argv, const dart::simulation::WorldPtr& world, const GraphicsConfiguration& configuration = GraphicsConfiguration()); ~WindowlessGLApplication(); void render() override;