Page 2 of 2

Re: Debug Drawing Utility Class

Posted: Mon Jul 18, 2011 11:53 am
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.

Re: Debug Drawing Utility Class

Posted: Tue Jul 19, 2011 2:49 am
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

Re: Debug Drawing Utility Class

Posted: Tue Jul 19, 2011 4:49 am
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!

Re: Debug Drawing Utility Class

Posted: Sun Jul 01, 2012 3:56 pm
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.

Re: Debug Drawing Utility Class

Posted: Tue Apr 01, 2014 1:06 pm
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.

Re: Debug Drawing Utility Class

Posted: Tue Apr 01, 2014 1:20 pm
by Zonder
Check your ogre.log and ensure it's material is loaded.

Re: Debug Drawing Utility Class

Posted: Tue Apr 01, 2014 1:22 pm
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

Re: Debug Drawing Utility Class

Posted: Tue Apr 01, 2014 1:46 pm
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)

Re: Debug Drawing Utility Class

Posted: Tue Apr 01, 2014 1:57 pm
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.

Re: Debug Drawing Utility Class

Posted: Sun Apr 13, 2014 11:21 pm
by nickG
subscribed for integration in my code

Re: Debug Drawing Utility Class

Posted: Sun Apr 13, 2014 11:40 pm
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.

Re: Debug Drawing Utility Class

Posted: Mon Apr 14, 2014 12:58 am
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"

Re: Debug Drawing Utility Class

Posted: Mon Apr 14, 2014 1:00 pm
by Klaim
Learn to use bookmarks instead, you're polluting this discussion.

Re: Debug Drawing Utility Class

Posted: Sat Jan 31, 2015 9:48 am
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.

Re: Debug Drawing Utility Class

Posted: Sat Jan 31, 2015 10:00 am
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. :)

Re: Debug Drawing Utility Class

Posted: Sun Feb 01, 2015 1:17 am
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..

Re: Debug Drawing Utility Class

Posted: Wed Feb 04, 2015 10:30 pm
by jacmoe
This project now has a home in the OgreAddons -> https://bitbucket.org/ogreaddons/ogre-d ... ng-utility