(C++) DrawNormals

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

(C++) DrawNormals

Post by Isometric God »

This code draws all normals of a scene. You have to either use IrrSpinzt or write your own getMesh() function.

Code: Select all

void CGame::DrawNormals(const scene::ISceneNode* parent)
{
	scene::ISceneManager* smgr = g_Device->getSceneManager();
	video::IVideoDriver* driver = g_Device->getVideoDriver();

	if (parent == NULL)
		parent = smgr->getRootSceneNode();

	core::list<scene::ISceneNode*>::Iterator it;

	video::SMaterial mat;
	mat.Lighting = false;

	driver->setMaterial(mat);

	for (it = parent->getChildren().begin(); it != parent->getChildren().end(); ++it)
	{
		scene::IAnimatedMeshSceneNode* node = (scene::IAnimatedMeshSceneNode*)*it;

		if (!node->isVisible())
			continue;				// no recursion 

		scene::IMesh* mesh = node->getMesh();

		if (mesh)
		{
			driver->setTransform(video::ETS_WORLD, node->getAbsoluteTransformation()); 

			for (s32 b = 0; b < mesh->getMeshBufferCount(); ++b)
			{
				scene::IMeshBuffer* mb = mesh->getMeshBuffer(b);

				if (mb->getVertexType() == video::EVT_STANDARD)
				{
					video::S3DVertex* v = (video::S3DVertex*)mb->getVertices();

					for (s32 i = 0; i < mb->getVertexCount(); ++i, ++v)
					{
						driver->draw3DLine(v->Pos, v->Pos + v->Normal, 0xFF0000FF);
					}
				}
			}
		}

		DrawNormals(*it);		// recursive call
	}
}
Post Reply