Debug Drawing Utility Class

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
fishcakedev
Gnoblar
Posts: 24
Joined: Mon Mar 14, 2011 3:23 pm
x 10

Re: Debug Drawing Utility Class

Post by fishcakedev »

Beauty wrote:It would be good if you add the material file to the repository, too.
Totally forgot about that! Done. :)
Beauty wrote:To the overview page of your repository you could add these Links:
* Wiki page: http://ogre3d.org/tikiwiki/Debug+Drawing+Utility+Class
* This forum thread: viewtopic.php?f=5&t=64941
Done. :)
Beauty wrote:If you allow shared write access with user Tubulii, you also could create a subdirectory called "Mogre port", which includes the VB script. Then both codes are available in your repository and also Tubulii could maintain it easily.
If you don't want to allow shared access, just say no.
Sure thing, but I need his Bitbucket username.
User avatar
happy_spike
Halfling
Posts: 44
Joined: Wed Mar 03, 2010 3:05 am
Location: Australia
x 5

Re: Debug Drawing Utility Class

Post by happy_spike »

Hi. I've made one quick adjustment to you class to make it easier to enable/disable. I don't know if you want to include it or not but i'll post it here anyway.

Code: Select all

class DebugDrawer : public Ogre::Singleton<DebugDrawer>
{

.......

//NEW ACCESOR/MUTATORS

   bool getEnabled() { return enabled; }
   void setEnabled( bool enabledSetting ) { enabled = enabledSetting; }
   void switchEnabled() { enabled = !enabled; }

.......

private:
 
   Ogre::SceneManager *sceneManager;
   Ogre::ManualObject *manualObject;
   float fillAlpha;
   bool enabled; //                      <---------ADDED THIS VAR
   IcoSphere icoSphere;
 
......
};
and a quick change to the build() function

Code: Select all

void DebugDrawer::build()
{
	manualObject->beginUpdate(0);

	//if lineVertices has information and the drawer is enabled build objects

	if (lineVertices.size() > 0 && enabled) //ADDED && enabled
	{
		manualObject->estimateVertexCount(lineVertices.size());
		manualObject->estimateIndexCount(lineIndices.size());
		for (std::list<VertexPair>::iterator i = lineVertices.begin(); i != lineVertices.end(); i++)
		{
			manualObject->position(i->first);
			manualObject->colour(i->second);
		}
		for (std::list<int>::iterator i = lineIndices.begin(); i != lineIndices.end(); i++)
			manualObject->index(*i);
	}
	manualObject->end();

	manualObject->beginUpdate(1);

	//if lineVertices has information and the drawer is enabled build objects

	if (triangleVertices.size() > 0 && enabled) //ADDED && enabled
	{
		manualObject->estimateVertexCount(triangleVertices.size());
		manualObject->estimateIndexCount(triangleIndices.size());
		for (std::list<VertexPair>::iterator i = triangleVertices.begin(); i != triangleVertices.end(); i++)
		{
			manualObject->position(i->first);
			manualObject->colour(i->second.r, i->second.g, i->second.b, fillAlpha);
		}
		for (std::list<int>::iterator i = triangleIndices.begin(); i != triangleIndices.end(); i++)
			manualObject->index(*i);
	}
	manualObject->end();
}
and finaly on the section where the draw*SHAPE*() function is called

Code: Select all

void Carosel::Update( float dt )
{
	//if( static_cast<MainMenuState*>( StateManager::Instance()->GetCurrentState() )->debugBoundsOn )
	if( DebugDrawer::getSingleton().getEnabled() ) //check to see if debugDrawer is turned on otherwise skip drawing the shape
	{
		for( std::vector<Platform*>::iterator itr = m_platforms.begin(); itr != m_platforms.end(); itr++ )
		{
			Shape * shape = (*itr)->shape;
			float yOffset = shape->GetCustomProperty(SHAPE_HEIGHT)/2;
			Ogre::Vector3 drawPos = shape->origin->_getDerivedPosition() + Ogre::Vector3( 0, yOffset, 0 );
			DebugDrawer::getSingleton().drawCylinder( drawPos, shape->GetCustomProperty(SHAPE_RADIUS), 10, shape->GetCustomProperty(SHAPE_HEIGHT), Ogre::ColourValue::Red, false );
		}
	}

}
and finaly in the input

Code: Select all


bool MainMenuInput::keyPressed( const OIS::KeyEvent &arg ) 
{
	GameState * gameState = StateManager::Instance()->GetCurrentState();

	CEGUI::System &ceguiSystem = CEGUI::System::getSingleton();
	ceguiSystem.injectKeyDown(arg.key);
	ceguiSystem.injectChar(arg.text);

	switch (arg.key)
	{
	case OIS::KC_ESCAPE : 
		Application::Instance()->SetRunning( false );
		break;
		
	case OIS::KC_RETURN : 
		{
			//Switch debugDrawer on and off
			//m_state->debugBoundsOn = !m_state->debugBoundsOn;
			DebugDrawer::getSingleton().switchEnabled(); 
		}
		break;
		
	......

	}
	return true;
}
now when I press <enter> the debug bounds turn on and off. And at any time if you want to change it's state you can just call

Code: Select all

DebugDrawer::getSingleton().setEnabled(true); //turn on 
DebugDrawer::getSingleton().setEnabled(false); //turn off
DebugDrawer::getSingleton().switchEnabled(); //switch on/off
hope you like
fishcakedev
Gnoblar
Posts: 24
Joined: Mon Mar 14, 2011 3:23 pm
x 10

Re: Debug Drawing Utility Class

Post by fishcakedev »

Ah, that would be useful. Added it to the class. :) Oh, and previously I uploaded the wrong .cpp file to the repository. :oops: It's now fixed!
rswa
Gnoblar
Posts: 6
Joined: Fri Apr 09, 2010 6:37 am

Re: Debug Drawing Utility Class

Post by rswa »

I change the std::list to std::vector ...
It can improves performance when has too many object to draw.
I think that base on continue memory.
danduk82
Gnoblar
Posts: 9
Joined: Wed Oct 09, 2013 2:39 pm

Re: Debug Drawing Utility Class

Post by danduk82 »

Helly everybody,
I know this quite an old thread, but I'm trying to use the Debug Drawing Utility Class, which seems exactly what I needed.

I am using Ogre 1.8 on a Linux machine with OpenGL rendered. I had to modify a few things to get it work:
A) changed "__int64" (which is a MSVC specific type) to "Ogre::int64" (which takes care to use __int64 on windows and other types with gcc).
B) changed "ms_Singelton" to "msSingelton"

Now I have tryied to do exactly what is explained in the wiki to get it work. It compiles, but I don't see any debug plot on sreen when the application runs.
So:

I initialize it in my APP::startup() function (I'm not using the exampleApplication) like this:

Code: Select all

	_sceneManager = _root->createSceneManager(Ogre::ST_GENERIC);

	// debug drawing facilites
	new DebugDrawer(_sceneManager, 0.5f);
and unallocating it in my APP::shutdown() function like this:

Code: Select all

        // destroy debug facilities
	delete DebugDrawer::getSingletonPtr();
		
In my FrameListener::frameStarted function, at the end of the function, I iterate all the objects I have put in a special <vector> and call DebugDraw, I also call the .build() method, like this:

Code: Select all

	// Right before the frame is rendered, call DebugDrawer to display all the entities
	// that are in debug mode
	for(int i_ent =0; i_ent!=_debugEntitiesVector->size(); ++i_ent){
		DebugDrawer::getSingleton().drawCuboid(_debugEntitiesVector->at(i_ent)->getBoundingBox().getAllCorners(), Ogre::ColourValue::Red, true);
	}
	DebugDrawer::getSingleton().build();
	return true;
And finally, I call .clean() in frameEnded:

Code: Select all

	// After the frame is rendered, call DebugDrawer::clear()
	DebugDrawer::getSingleton().clear();
	return true;
I get no compilation errors, but when I run the code, I don't see any red box aroung my debug meshes... I have also tried to copy the for loops in the examples that plot a lot of colored boxes all around, I'don't see anything.

Does anyone understand the problem? I'm I doing something wrong?
thanks in advance.
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: Debug Drawing Utility Class

Post by Zonder »

Check your ogre.log and ensure it's material is loaded.
There are 10 types of people in the world: Those who understand binary, and those who don't...
danduk82
Gnoblar
Posts: 9
Joined: Wed Oct 09, 2013 2:39 pm

Re: Debug Drawing Utility Class

Post by danduk82 »

It is, apparently:

Code: Select all

$ grep -i debug Ogre.log 
14:03:33: Creating resource group Debug
14:03:33: Added resource location 'Media/Material' of type 'FileSystem' to resource group 'Debug'
14:03:33: Parsing scripts for resource group Debug
14:03:33: Parsing script Debug.material
14:03:33: Finished parsing scripts for resource group Debug
14:03:33: Creating resources for group Debug
edit: Hey thanks for super fast answer ;)
edit 2:
Btw, I don't get where Debug material is used within DebugDrawer.cpp or .h . I don't see it called anywhere in the sources...
EDIT 3 : [SOLVED]
Hi Guys, please add one line to your WIKI page. I had to simply add

Code: Select all

DebugDrawer::getSingleton().setEnabled(true);
to make it work. But this is not documentented in the WIKI.

Sorry for the (basic) question. Thanks for reply.
Bests
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: Debug Drawing Utility Class

Post by Zonder »

Copy the material details to a file callled "debug_draw.material" and place on your file system along side your other materials that should pick it up (Media/Material)
There are 10 types of people in the world: Those who understand binary, and those who don't...
danduk82
Gnoblar
Posts: 9
Joined: Wed Oct 09, 2013 2:39 pm

Re: Debug Drawing Utility Class

Post by danduk82 »

It was not a material problem, but a initializing problem:

in the wiki, it is said to put

Code: Select all

isEnable(true);
in the constructor to be sure that it is enabled from the beginning.

This is an error, because isEnabled is a bool, so it should be written:

Code: Select all

isEnable = true;
in the constructor...

Anyway, you can solve the problem like me putting:

Code: Select all

DebugDrawer::getSingleton().setEnabled(true);
after initializing DebugDrawer.

In this way it works without problems.
nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow
x 1

Re: Debug Drawing Utility Class

Post by nickG »

subscribed for integration in my code
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: Debug Drawing Utility Class

Post by Klaim »

nickG wrote:subscribed for integration in my code
Just use the suscribe button in the bottom part of the thread page, instead of posting.
nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow
x 1

Re: Debug Drawing Utility Class

Post by nickG »

Klaim wrote:
nickG wrote:subscribed for integration in my code
Just use the suscribe button in the bottom part of the thread page, instead of posting.
i know it,but i want see theme on "view your posts"
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56
Contact:

Re: Debug Drawing Utility Class

Post by Klaim »

Learn to use bookmarks instead, you're polluting this discussion.
theydidntnameme
Gnoblar
Posts: 3
Joined: Sat Nov 30, 2013 8:03 pm

Re: Debug Drawing Utility Class

Post by theydidntnameme »

Is there a license somewhere for the code in the repository? I'm wondering if the code can be used in proprietary software.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Debug Drawing Utility Class

Post by jacmoe »

Since the code has been posted on our wiki, it can be considered to be in the public domain.
Here's a link to the Public Domain Unlicense that we are using for contributed code content.
However, the repository manager really should add a license notice. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
theydidntnameme
Gnoblar
Posts: 3
Joined: Sat Nov 30, 2013 8:03 pm

Re: Debug Drawing Utility Class

Post by theydidntnameme »

Excellent. That makes me feel better about using the code. :D The original creator appears to have disappeared however, I don't see any activity from the past couple of years..
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Debug Drawing Utility Class

Post by jacmoe »

This project now has a home in the OgreAddons -> https://bitbucket.org/ogreaddons/ogre-d ... ng-utility
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Post Reply