4#ifndef GREM_PHYSICS_DEBUG_VISUZLIATION_HPP
5#define GREM_PHYSICS_DEBUG_VISUZLIATION_HPP
9#ifdef GREM_PHYSICS_USE_DEBUG_VISUALIZATION
47#ifdef GREM_PHYSICS_USE_DEBUG_VISUALIZATION
53 void clear() noexcept {
54 worldDrawCommands.clear();
55 uiDrawCommands.clear();
69 void drawWorldCube(
const mat4& transformation,
Color color)
requires(N == 3) {
70 worldDrawCommands.emplace_back(DrawWorldCubeCommand{.transformation = transformation, .color = color});
83 void drawWorldCubeWireframe(
const mat4& transformation, Color color)
requires(
N == 3) {
84 worldDrawCommands.emplace_back(DrawWorldCubeWireframeCommand{.transformation = transformation, .color = color});
97 void drawWorldAABBWireframe(
const Box<N>& aabb, Color color) {
98 worldDrawCommands.emplace_back(DrawWorldAABBWireframeCommand{.aabb = aabb, .color = color});
111 void drawWorldAABBWireframe(
const grem::Box<N, Scalar>& aabb, Color color) {
127 worldDrawCommands.emplace_back(DrawWorldPointCommand{.point = point, .color = color, .radiusCoefficient = radiusCoefficient});
144 worldDrawCommands.emplace_back(DrawWorldLineSegmentCommand{.pointA = pointA, .pointB = pointB, .color = color, .thicknessCoefficient = thicknessCoefficient});
163 drawWorldLineSegment(point, point + directionScale *
Scalar{0.25} * METERS * lengthCoefficient, color, thicknessCoefficient);
178 void drawUIText(
vec2 position, uint32_t characterSize, Color color,
UTF8StringView string) {
180 throw std::length_error{
"Maximum internal string buffer size exceeded."};
182 const uint32_t stringDataOffset =
static_cast<uint32_t
>(stringData.size());
183 const uint32_t stringDataSize =
static_cast<uint32_t
>(
string.size());
184 stringData.append(
string);
185 uiDrawCommands.emplace_back(
186 DrawUITextCommand{.position = position, .characterSize = characterSize, .color = color, .stringDataOffset = stringDataOffset, .stringDataSize = stringDataSize});
201 void drawUIText(
vec2 position, uint32_t characterSize, Color color,
StringView string) {
202 drawUIText(position, characterSize, color,
UTF8StringView{std::launder(
reinterpret_cast<const char8_t*
>(
string.data())),
string.size()});
217 void putWorldVisualizationInstances(graphics::Renderer2D& renderer2D, graphics::Instances2D& instances,
Length2D lengthUnit =
Length2D{
Scalar{1} * METERS})
const
221 for (
const WorldDrawCommand& worldDrawCommand : worldDrawCommands) {
223 GREM_CASE(
const DrawWorldCubeCommand& command)
break;
224 GREM_CASE(
const DrawWorldCubeWireframeCommand& command)
break;
225 GREM_CASE(
const DrawWorldAABBWireframeCommand& command) {
226 const vec2 aabbMin = lengthScale * command.aabb.min.in(Position2D::UNIT);
227 const vec2 aabbMax = lengthScale * command.aabb.max.in(Position2D::UNIT);
228 const vec2 aabbSize = aabbMax - aabbMin;
229 instances.putRectangleInstance(graphics::RectangleInstance2D{.position{aabbMin.x, aabbMin.y}, .size{aabbSize.x, 1.0f}, .color = command.color});
230 instances.putRectangleInstance(graphics::RectangleInstance2D{.position{aabbMin.x, aabbMax.y - 1.0f}, .size{aabbSize.x, 1.0f}, .color = command.color});
231 instances.putRectangleInstance(graphics::RectangleInstance2D{.position{aabbMin.x, aabbMin.y + 1.0f}, .size{1.0f, aabbSize.y - 2.0f}, .color = command.color});
232 instances.putRectangleInstance(
233 graphics::RectangleInstance2D{.position{aabbMax.x - 1.0f, aabbMin.y + 1.0f}, .size{1.0f, aabbSize.y - 2.0f}, .color = command.color});
236 GREM_CASE(
const DrawWorldPointCommand& command) {
237 instances.putRectangleInstance(graphics::RectangleInstance2D{
238 .position = lengthScale * command.point.in(Position2D::UNIT),
239 .size{
static_cast<float>(
Scalar{4} * command.radiusCoefficient)},
241 .color = command.color,
245 GREM_CASE(
const DrawWorldLineSegmentCommand& command) {
246 const Length2D difference = command.pointB - command.pointA;
247 if (difference != 0) {
248 instances.putRectangleInstance(graphics::RectangleInstance2D{
249 .position = lengthScale * command.pointA.in(Position2D::UNIT),
250 .angle = (
Scalar{-90} * DEGREES).as(RADIANS) +
getAngle(difference),
251 .size{
static_cast<float>(
Scalar{2} * command.thicknessCoefficient),
static_cast<float>(
length(lengthScale * difference.in(Distance::UNIT)))},
253 .color = command.color,
274 void putWorldVisualizationInstances(graphics::Renderer3D& renderer3D, graphics::Instances3D& instances,
Length3D lengthUnit =
Length3D{
Scalar{1} * METERS})
const
277 for (
const WorldDrawCommand& worldDrawCommand : worldDrawCommands) {
279 GREM_CASE(
const DrawWorldCubeCommand& command) {
280 instances.putShadedModelInstance(renderer3D.getHDRUnlitModel3DShaderPipelineSet(), renderer3D.getCubeModel3D(), lengthScale * command.transformation,
281 graphics::ModelInstance3D{.color = command.color});
284 GREM_CASE(
const DrawWorldCubeWireframeCommand& command) {
285 instances.putShadedModelInstance(renderer3D.getHDRWireframeModel3DShaderPipelineSet(), renderer3D.getCubeModel3D(), lengthScale * command.transformation,
286 graphics::ModelInstance3D{.color = command.color});
289 GREM_CASE(
const DrawWorldAABBWireframeCommand& command) {
291 const Length3D aabbHalfExtents = (command.aabb.max - command.aabb.min) *
Scalar{0.5};
292 const mat4 transformation =
translateScale(aabbCenter, aabbHalfExtents.in(Length3D::UNIT));
293 instances.putShadedModelInstance(renderer3D.getHDRWireframeModel3DShaderPipelineSet(), renderer3D.getCubeModel3D(), lengthScale * transformation,
294 graphics::ModelInstance3D{.color = command.color});
297 GREM_CASE(
const DrawWorldPointCommand& command) {
298 const mat4 transformation =
translateScale(command.point,
Scale3D{static_cast<Scalar>(0.02) * command.radiusCoefficient});
299 instances.putShadedModelInstance(renderer3D.getHDRUnlitModel3DShaderPipelineSet(), renderer3D.getCubeModel3D(), lengthScale * transformation,
300 graphics::ModelInstance3D{.color = command.color});
303 GREM_CASE(
const DrawWorldLineSegmentCommand& command) {
304 const Length3D difference = command.pointB - command.pointA;
305 if (difference != 0) {
308 Scale3D{static_cast<Scalar>(0.01) * command.thicknessCoefficient, static_cast<Scalar>(0.01) * command.thicknessCoefficient,
309 Scalar{0.5} *
length(difference).in(Distance::UNIT)});
310 instances.putShadedModelInstance(renderer3D.getHDRUnlitModel3DShaderPipelineSet(), renderer3D.getCubeModel3D(), lengthScale * transformation,
311 graphics::ModelInstance3D{.color = command.color});
331 void putUIVisualizationInstances(graphics::Renderer2D& renderer2D, graphics::Instances2D& instances, graphics::Font2D& font)
const {
333 for (
const UIDrawCommand& uiDrawCommand : uiDrawCommands) {
335 GREM_CASE(
const DrawUITextCommand& command) {
336 instances.putTextStringInstance(font,
UTF8StringView{stringData}.substr(command.stringDataOffset, command.stringDataSize),
337 graphics::TextStringInstance2D{.characterSize = command.characterSize, .position = command.position, .color = command.color});
345 struct DrawWorldCubeCommand {
350 struct DrawWorldCubeWireframeCommand {
355 struct DrawWorldAABBWireframeCommand {
360 struct DrawWorldPointCommand {
366 struct DrawWorldLineSegmentCommand {
373 struct DrawUITextCommand {
375 uint32_t characterSize;
377 uint32_t stringDataOffset;
378 uint32_t stringDataSize;
381 using WorldDrawCommand =
Variant<
382 DrawWorldCubeCommand,
383 DrawWorldCubeWireframeCommand,
384 DrawWorldAABBWireframeCommand,
385 DrawWorldPointCommand,
386 DrawWorldLineSegmentCommand>;
390 ArrayList<WorldDrawCommand> worldDrawCommands{};
391 ArrayList<UIDrawCommand> uiDrawCommands{};
#define GREM_MATCH(...)
Definition Variant.hpp:1997
#define GREM_CASE(...)
Definition Variant.hpp:1998
Floating-point linear RGBA color in the Rec.
Definition Color.hpp:60
Bundle of draw commands for drawing debugging information about a Simulation.
Definition DebugVisualization.hpp:46
@ N
'n'
Definition keyboard.hpp:84
json::VariantBase< std::allocator > Variant
JSON value type using the default allocator.
Definition json.hpp:1094
Definition Broadphase.hpp:24
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL length(A a)
Definition quantities.hpp:3302
constexpr Direction3D Z_AXIS_3D
The Z axis in 3-dimensional space.
Definition quantities.hpp:4914
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL midpoint(A a, B b)
Definition quantities.hpp:3497
float Scalar
Underlying scalar type of physics quantity components.
Definition quantities.hpp:1480
DebugVisualization< 2 > DebugVisualization2D
Bundle of draw commands for drawing debugging information about a 2-dimensional Simulation.
Definition DebugVisualization.hpp:48
GREM_ALWAYS_INLINE LocalTransformation< N > GREM_VECTORCALL translateRotateScale(Length< N > localOffset, Orientation< N > localOrientation, Scale< N > localScale)
Definition quantities.hpp:5063
Scale< 3 > Scale3D
Dimensionless scale in 3-dimensional space. Unitless.
Definition quantities.hpp:3987
GREM_ALWAYS_INLINE Basis< N > scale(Quantity< N, UnitT > s)
Definition quantities.hpp:4708
Scale1D Coefficient
Unitless scalar quantity.
Definition quantities.hpp:3988
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL normalize(A a)
Definition quantities.hpp:4187
Length< 3 > Length3D
Relative distance/length offset in 3-dimensional space. Unit: Meters.
Definition quantities.hpp:4927
GREM_ALWAYS_INLINE constexpr auto GREM_VECTORCALL getAngle(A a)
Definition quantities.hpp:3323
GREM_ALWAYS_INLINE LocalTransformation< N > GREM_VECTORCALL translateScale(Length< N > localOffset, Scale< N > localScale)
Definition quantities.hpp:5089
DebugVisualization< 3 > DebugVisualization3D
Bundle of draw commands for drawing debugging information about a 3-dimensional Simulation.
Definition DebugVisualization.hpp:49
Position< 3 > Position3D
Absolute position in 3-dimensional space. Unit: Meters.
Definition quantities.hpp:4952
Quantity< N, Absolute< Meters > > Position
Absolute position in world space.
Definition quantities.hpp:4949
Quantity< N, Unitless > Scale
Dimensionless scale.
Definition quantities.hpp:3984
Scale< 2 > Scale2D
Dimensionless scale in 2-dimensional space. Unitless.
Definition quantities.hpp:3986
Length< 2 > Length2D
Relative distance/length offset in 2-dimensional space. Unit: Meters.
Definition quantities.hpp:4926
vec< 2, float > vec2
Definition math.hpp:438
mat< 3, 3, float > mat3
Definition math.hpp:805
StringBase< char8_t, std::char_traits< char8_t >, std::allocator< char8_t > > UTF8String
Definition String.hpp:18
mat< 4, 4, float > mat4
Definition math.hpp:806
StringViewBase< char, std::char_traits< char > > StringView
Definition StringView.hpp:16
StringViewBase< char8_t, std::char_traits< char8_t > > UTF8StringView
Definition StringView.hpp:17
static constexpr T MAX
Definition fundamentals.hpp:29
static constexpr Unit UNIT
Unit.
Definition Shape.hpp:817
static GREM_ALWAYS_INLINE Orientation rotation(Scale3D from, Scale3D to)
Definition quantities.hpp:4522