OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: Debug Drawing Utility Class
View page
Source of version: 15
(current)
{DIV(class="clearRight")}{img fileId="2055" align="right" width="300" stylebox="border"}{DIV} !Debug Drawing Utility Class {maketoc} !!Description It's a utility class for rendering simple primitives like 3D lines, quads and cuboids, without having to keep track of manual objects. It is useful for debugging purposes, since it is quite a hassle to keep track of ManualObject instances, initializing them, attaching them to scene nodes and destroying them just for the sake of debugging. Using this class, all it takes is just one function call to draw a primitive. Note that it works like 2D rendering, e.g. it is cleared every frame. Thus, the draw functions need to be called every frame. Currently, it supports rendering of: * lines * quads * circles * cuboids * icospheres * cylinders * tetrahedrons For questions use [http://www.ogre3d.org/forums/viewtopic.php?f=5&t=64941|this forum topic]. A C# and Visual Basic port for ((Mogre)) is available ((Debug Drawing Utility Class for MOGRE|here)). !!Source code The needed files ''DebugDrawer.h'' and ''DebugDrawer.cpp'' are available in this [https://github.com/hasyimibhar/ogre-debug-drawing-utility]. __NOTE:__ Be sure to add this line to the initializer list of the DebugDrawer constructor. It's missing from the archive and without it, the debug display may or may not appear. {CODE(wrap="1", colors="c++")}isEnabled(true){CODE} !!Usage Example: Drawing a Bounding Box This usage example is made based on the basic application framework generated by [https://bitbucket.org/ogreaddons/ogreappwizards/src/default/|OgreApp Wizard]. It requires destroyScene(), frameStarted() and frameEnded() to be overridden: {CODE(wrap="1", colors="c++")}// Override me! virtual void createScene(void); virtual bool frameStarted(const Ogre::FrameEvent& evt); virtual bool frameEnded(const Ogre::FrameEvent& evt);{CODE} First, the DebugDrawer instance (DebugDrawer is a singleton) needs to be created and initialized. This is done inside createScene() by initializing DebugDrawer's singleton instance: {CODE(wrap="1", colors="c++")}// Initialise the DebugDrawer singleton new DebugDrawer(mSceneMgr, 0.5f);{CODE} Don't forget to destroy DebugDrawer once you're done using it. This is done inside destroyScene() by calling deleting its singleton's instance: {CODE(wrap="1", colors="c++")} // Goodbye~ delete DebugDrawer::getSingletonPtr(); {CODE} Right before the frame is rendered, DebugDrawer::build() needs to be called. This will build the ManualObject wrapped by the class. In this example, DebugDrawer::build() is called at the end of frameStarted(): {CODE(wrap="1", colors="c++")}// Right before the frame is rendered, call DebugDrawer::build(). DebugDrawer::getSingleton().build();{CODE} At the end of each frame (after the frame has been rendered), DebugDrawer needs to be cleared. This is done by calling DebugDrawer::clear() inside frameEnded(): {CODE(wrap="1", colors="c++")}// After the frame is rendered, call DebugDrawer::clear() DebugDrawer::getSingleton().clear();{CODE} Finally, the class can be used. Since the framework lacks a proper update loop, the draw functions need to be called inside frameStarted(), but before DebugDrawer::build() is called. The code below will draw a filled cuboid as the bounding box of the entity (the ogre head): {CODE(wrap="1", colors="c++")}// Let's draw the bounding box for the ogre head! DebugDrawer::getSingleton().drawCuboid(mOgreHead->getBoundingBox().getAllCorners(), Ogre::ColourValue::Red, true);{CODE} The entire example application code: {CODE(wrap="1", colors="c++")} void DebugDrawingUtility::createScene(void) { mOgreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); headNode->attachObject(mOgreHead ); // Set ambient light mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); // Create a light Ogre::Light* l = mSceneMgr->createLight("MainLight"); l->setPosition(20,80,50); // Initialise the DebugDrawer singleton new DebugDrawer(mSceneMgr, 0.5f); } void DebugDrawingUtility::destroyScene(void) { // Goodbye~ delete DebugDrawer::getSingletonPtr(); } bool DebugDrawingUtility::frameStarted(const Ogre::FrameEvent& evt) { // Since this framework lacks a proper update loop, let's just place the drawing codes here. // Drawing codes should go inside an update loop, before the frame is rendered. // Let's draw the bounding box for the ogre head! DebugDrawer::getSingleton().drawCuboid(mOgreHead->getBoundingBox().getAllCorners(), Ogre::ColourValue::Red, true); // =================================================================== // Right before the frame is rendered, call DebugDrawer::build(). DebugDrawer::getSingleton().build(); return true; } bool DebugDrawingUtility::frameEnded(const Ogre::FrameEvent& evt) { // After the frame is rendered, call DebugDrawer::clear() DebugDrawer::getSingleton().clear(); return true; } {CODE} The result (release build): {img fileId="2055" thumb="y" rel="box[g]" width=400} !!Another Usage Example: Pretty Cubes For the sake of fun, let's draw lots of pretty colorful cubes! (:biggrin:): {CODE(wrap="1", colors="c++")} for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { Ogre::AxisAlignedBox box (Ogre::Vector3(i * 10.0f + 2.0f, j * 10.0f + 2.0f, k * 10.0f + 2.0f), Ogre::Vector3((i + 1) * 10.0f - 2.0f, (j + 1) * 10.0f - 2.0f, (k + 1) * 10.0f - 2.0f)); DebugDrawer::getSingleton().drawCuboid(box.getAllCorners(), Ogre::ColourValue(51.0f * i / 255.0f, 51.0f * j / 255.0f, 51.0f * k / 255.0f), true); } } }{CODE} The result (release build): {img fileId="2056" thumb="y" rel="box[g]" width=400} !!Icosphere Example The class can now draw icospheres! {CODE(wrap="1", colors="c++")} for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { // Draws a sphere with radius 20.0f DebugDrawer::getSingleton().drawSphere(Ogre::Vector3(i * 50.0f, j * 50.0f, k * 50.0f), 20.0f, Ogre::ColourValue(51.0f * i / 255.0f, 51.0f * j / 255.0f, 51.0f * k / 255.0f), true); } } } {CODE} The result (to be honest, this example was run from a more powerful PC than the previous examples): {img fileId="2073" thumb="y" rel="box[g]" width="400"} The recursion level of the icosphere can be changed to get a more detailed icosphere. This is done by calling setIcoSphereRecursionLevel(). Note that this function rebuilds the icosphere, so don't call it in a loop. {CODE(wrap="1", colors="c++")} // 2 is more than enough! DebugDrawer::getSingleton().setIcoSphereRecursionLevel(2); {CODE} The result: {img fileId="2057" thumb="y" rel="box[g]" width="400"} !!To Do *Properly document the class. Currently, the class is being documented through usage examples, which is inadequate *Add more primitives! *Add screen shots to show all the primitives *Further optimize the class
Search by Tags
Search Wiki by Freetags
Latest Changes
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
...more
Search
Find
Advanced
Search Help
Online Users
232 online users