/* This file is part of Magnum. Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026 Vladimír Vondruš Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define _MAGNUM_NO_DEPRECATED_FORCERENDERER #define _MAGNUM_NO_DEPRECATED_RESOURCEMANAGER /* This damn joke of a compiler, even the 2022 version, ignores the _MAGNUM_NO_DEPRECATED_FORCERENDERER macro for some reason, printing the ForceRenderer.h file deprecation warning here, so I have to work around it like this. Same in the test and in ObjectRenderer.h and its test, but in ResourceManager.cpp as well as in doc/snippets/Magnum.cpp the macro works. What the hell. */ #include #ifdef CORRADE_TARGET_MSVC #define CORRADE_DEPRECATED_FILE(...) #endif #include "ForceRenderer.h" #include "Magnum/GL/Mesh.h" #include "Magnum/DebugTools/ResourceManager.h" #include "Magnum/SceneGraph/Camera.h" #include "Magnum/Shaders/FlatGL.h" #include "Magnum/DebugTools/Implementation/ForceRendererTransformation.h" namespace Magnum { namespace DebugTools { CORRADE_IGNORE_DEPRECATED_PUSH namespace { template ResourceKey shaderKey(); template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } constexpr Vector2 positions[]{ {0.0f, 0.0f}, {1.0f, 0.0f}, {0.9f, 0.1f}, {0.9f, -0.1f} }; constexpr UnsignedByte indices[]{ 0, 1, 1, 2, 1, 3 }; } template ForceRenderer::ForceRenderer(ResourceManager& manager, SceneGraph::AbstractObject& object, const VectorTypeFor& forcePosition, const VectorTypeFor& force, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(object, drawables), _forcePosition(forcePosition), _force(force), _options(manager.get(options)) { /* Shader */ _shader = manager.get>(shaderKey()); if(!_shader) manager.set(_shader.key(), new Shaders::FlatGL); /* Mesh and vertex buffer */ _mesh = manager.get("force"); if(_mesh) return; /* Create the mesh */ GL::Buffer vertexBuffer{GL::Buffer::TargetHint::Array}; vertexBuffer.setData(positions, GL::BufferUsage::StaticDraw); GL::Buffer indexBuffer{GL::Buffer::TargetHint::ElementArray}; indexBuffer.setData(indices, GL::BufferUsage::StaticDraw); GL::Mesh mesh{GL::MeshPrimitive::Lines}; mesh.setCount(Containers::arraySize(indices)) .addVertexBuffer(std::move(vertexBuffer), 0, typename Shaders::FlatGL::Position(Shaders::FlatGL::Position::Components::Two)) .setIndexBuffer(std::move(indexBuffer), 0, GL::MeshIndexType::UnsignedByte, 0, Containers::arraySize(positions)); manager.set(_mesh.key(), std::move(mesh), ResourceDataState::Final, ResourcePolicy::Manual); } /* To avoid deleting pointers to incomplete type on destruction of Resource members */ template ForceRenderer::~ForceRenderer() = default; template void ForceRenderer::draw(const MatrixTypeFor& transformationMatrix, SceneGraph::Camera& camera) { _shader->setTransformationProjectionMatrix(camera.projectionMatrix()*Implementation::forceRendererTransformation(transformationMatrix.transformPoint(_forcePosition), _force)*MatrixTypeFor::scaling(VectorTypeFor{_options->size()})) .setColor(_options->color()) .draw(*_mesh); } template class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer<2>; template class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer<3>; CORRADE_IGNORE_DEPRECATED_POP }}