| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include <OgreHardwareVertexBuffer.h>
- #include <OgreRenderQueueListener.h>
- #include <OgreRoot.h>
- #include <OgreSingleton.h>
- #include <OgreFont.h>
- class DebugDraw : public Ogre::RenderQueueListener, public Ogre::Singleton<DebugDraw>{
- public:
- /**
- * Constructor.
- */
- DebugDraw();
- /**
- * Destructor.
- */
- virtual ~DebugDraw();
- /**
- * Sets the colour of the element to draw.
- *
- * @param[in] colour The color to apply.
- */
- void SetColour(const Ogre::ColourValue& colour);
- /**
- * Sets the screen space.
- *
- * @param[in] screen_space The screen space.
- * @todo Understand and document properly.
- */
- void SetScreenSpace(const bool screen_space);
- /**
- * Set the Z coordinate.
- *
- * @param[in] z The Z coordinate.
- */
- void SetZ(const float z);
- /**
- * Sets the fade distance for text.
- *
- * @param[in] fade_s The text starts fading at this distance.
- * @param[in] fade_e The text has faded completely at this distance.
- */
- void SetFadeDistance(const float fade_s, const float fade_e);
- /**
- * Text alignment modes.
- */
- enum TextAlignment{
- /**
- * Left aligned text.
- */
- LEFT,
- /**
- * Right aligned text.
- */
- RIGHT,
- /**
- * Center aligned text.
- */
- CENTER
- };
- void SetTextAlignment(TextAlignment alignment);
- /**
- * Draws a line in 2D space.
- *
- * If the debug vertex limit has been reached or if it would be
- * exceeded by drawing the line, a warning message will be printed and
- * nothing will be done.
- *
- * @param[in] x1 X coordinate of the starting point.
- * @param[in] y1 Y coordinate of the starting point.
- * @param[in] x2 X coordinate of the ending point.
- * @param[in] y2 Y coordinate of the ending point.
- */
- void Line(
- const float x1, const float y1, const float x2, const float y2
- );
- /**
- * Draws a line in 3D space.
- *
- * If the debug vertex limit has been reached or if it would be
- * exceeded by drawing the line, a warning message will be printed and
- * nothing will be done.
- *
- * @param[in] point1 Starting point.
- * @param[in] point2 Ending point.
- */
- void Line3d(const Ogre::Vector3& point1, const Ogre::Vector3& point2);
- /**
- * Draws a triangle in 3D space.
- *
- * If the debug vertex limit has been reached or if it would be
- * exceeded by drawing the triangle, a warning message will be printed
- * and nothing will be done.
- *
- * @param[in] point1 A triangle vertex point.
- * @param[in] point2 A triangle vertex point.
- * @param[in] point3 A triangle vertex point.
- */
- void Triangle3d(
- const Ogre::Vector3& point1, const Ogre::Vector3& point2,
- const Ogre::Vector3& point3
- );
- /**
- * Draws a quad in 2D space.
- *
- * If the debug vertex limit has been reached or if it would be
- * exceeded by drawing the quad, a warning message will be printed and
- * nothing will be done.
- *
- * @param[in] x1 X coordinate of the first point.
- * @param[in] y1 Y coordinate of the first point.
- * @param[in] x2 X coordinate of the second point.
- * @param[in] y2 Y coordinate of the second point.
- * @param[in] x3 X coordinate of the third point.
- * @param[in] y3 Y coordinate of the third point.
- * @param[in] x4 X coordinate of the fourth point.
- * @param[in] y4 Y coordinate of the fourth point.
- */
- void Quad(
- const float x1, const float y1, const float x2, const float y2,
- const float x3, const float y3, const float x4, const float y4
- );
- /**
- * Writes debug text on the game screen.
- *
- * The text won't be warped automatically. If the maximum number of
- * debug letters has been written, or if it would be exceeded by
- * writing, a warning message will be printed to console and nothing
- * will be done.
- *
- * @param[in] x Left position of the text in the screen.
- * @param[in] y Left position of the text in the screen.
- * @param[in] text The text to write.
- */
- void Text(const float x, const float y, const Ogre::String& text);
- /**
- * Writes debug text on the game screen.
- *
- * The text will be warped automatically. If the maximum number of
- * debug letters has been written, or if it would be exceeded by
- * writing, a warning message will be printed to console and nothing
- * will be done.
- *
- * @param[in] point Top left point of the screen where the text will be
- * written.
- * @param[in] x Text width.
- * @param[in] y Text height.
- * @param[in] text The text to write.
- */
- void Text(
- const Ogre::Vector3& point, const float x, const float y,
- const Ogre::String& text
- );
- /**
- * Ends the render queue.
- *
- * @param[in] queueGroupId The group id of the queue to end.
- * @param[in] invocation
- * @param[in] repeatThisInvocation
- * @todo Understand and document.
- */
- void renderQueueEnded(
- Ogre::uint8 queueGroupId, const Ogre::String& invocation,
- bool& repeatThisInvocation
- );
- private:
- /**
- * Creates a 2D line vertex buffer (2 vertices).
- */
- void CreateLineVertexBuffer();
- /**
- * Destroys a 2D line vertex buffer (2 vertices).
- */
- void DestroyLineVertexBuffer();
- /**
- * Creates a 3D line vertex buffer (2 vertices).
- */
- void CreateLine3dVertexBuffer();
- /**
- * Destroys a 3D line vertex buffer (2 vertices).
- */
- void DestroyLine3dVertexBuffer();
- /**
- * Creates a 3D triangle vertex buffer (3 vertices).
- */
- void CreateTriangle3dVertexBuffer();
- /**
- * Destroys a 3D triangle vertex buffer (3 vertices).
- */
- void DestroyTriangle3dVertexBuffer();
- /**
- * Creates a quad vertex buffer (4 vertices).
- */
- void CreateQuadVertexBuffer();
- /**
- * Destroys a quad vertex buffer (4 vertices).
- */
- void DestroyQuadVertexBuffer();
- /**
- * Creates a text vertex buffer.
- */
- void CreateTextVertexBuffer();
- /**
- * Destroys a text vertex buffer.
- */
- void DestroyTextVertexBuffer();
- /**
- * The scene manager.
- */
- Ogre::SceneManager* scene_manager_;
- /**
- * The render system.
- */
- Ogre::RenderSystem* render_system_;
- /**
- * A 2D line render operation.
- */
- Ogre::RenderOperation line_render_operation_;
- /**
- * A 2D line vertex buffer (2 vertices).
- */
- Ogre::HardwareVertexBufferSharedPtr line_vertex_buffer_;
- /**
- * Maximum number of vertices for debug 2D lines.
- */
- unsigned int line_max_vertex_;
- /**
- * A 3D line render operation.
- */
- Ogre::RenderOperation line_3d_render_operation_;
- /**
- * A 3D line vertex buffer (2 vertices).
- */
- Ogre::HardwareVertexBufferSharedPtr line_3d_vertex_buffer_;
- /**
- * Maximum number of vertices for debug 3D lines.
- */
- unsigned int line_3d_max_vertex_;
- /**
- * A 3D triangle render operation.
- */
- Ogre::RenderOperation triangle_3d_render_operation_;
- /**
- * A 3D triangle vertex buffer (3 vertices).
- */
- Ogre::HardwareVertexBufferSharedPtr triangle_3d_vertex_buffer_;
- /**
- * Maximum number of vertices for debug 3D triangles.
- */
- unsigned int triangle_3d_max_vertex_;
- /**
- * A quad render operation.
- */
- Ogre::RenderOperation quad_render_operation_;
- /**
- * A quad vertex buffer (4 vertices).
- */
- Ogre::HardwareVertexBufferSharedPtr quad_vertex_buffer_;
- /**
- * Maximum number of vertices for debug quads.
- */
- unsigned int quad_max_vertex_;
- /**
- * A text render operation.
- */
- Ogre::RenderOperation text_render_operation_;
- /**
- * A text vertex buffer.
- *
- * @todo Confirm if it's 6 vertices per letter.
- */
- Ogre::HardwareVertexBufferSharedPtr text_vertex_buffer_;
- /**
- * Maximum number of vertices for debug text.
- *
- * @todo Confirm if it's 6 vertices per letter.
- */
- unsigned int text_max_vertex_;
- /**
- * Font to use for debug text.
- */
- Ogre::FontPtr font_;
- /**
- * Font height for the debug text.
- */
- int font_height_;
- /**
- * Alignment for debug text.
- */
- TextAlignment text_alignment_;
- /**
- * Material for a 2D object.
- */
- Ogre::MaterialPtr material_;
- /**
- * Material for a 3D object.
- */
- Ogre::MaterialPtr material_3d_;
- /**
- * Color for the debug object or text.
- */
- Ogre::ColourValue colour_;
- /**
- * The screen space.
- */
- bool screen_space_;
- /**
- * Z coordinate for the debug object.
- */
- float z_coordinate_;
- /**
- * For text fading. The text start fading from this distance.
- */
- float fade_start_square_;
- /**
- * For text fading. The text fully fades at this distance.
- */
- float fade_end_square_;
- };
- /**
- * Shortcut for a DebugDraw singleton.
- */
- #define DEBUG_DRAW DebugDraw::getSingleton()
|