Custom node inside custom node ?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
malimravbg
Posts: 3
Joined: Mon Sep 12, 2005 10:01 am

Custom node inside custom node ?

Post by malimravbg »

I wrote simple CAircraft symbol custom node that draws simple symbol (small rectangle):

Code: Select all

#include <irrlicht.h>

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

class CAircraftSymbol : public scene::ISceneNode
{
	core::aabbox3d<f32> Box; 

public:
	CAircraftSymbol(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
					: scene::ISceneNode(parent, mgr, id),center(0,0,0),
					lLeft(0, 0, 0), uLeft(0, 0, 10), uRight(10, 0, 10), lRight(10, 0, 0)
	{
		mtl.Lighting = false;
		// default symbol color is white
		mtl.AmbientColor = mtl.DiffuseColor = mtl.EmissiveColor = SColor(110,255,255,255); 
	}

	virtual void OnPreRender()
	{
		if (IsVisible)
			SceneManager->registerNodeForRendering(this);
		ISceneNode::OnPreRender();
	}

	virtual void render()
	{
		IVideoDriver* driver = SceneManager->getVideoDriver();
		driver->setTransform(ETS_WORLD, AbsoluteTransformation);

		driver->setMaterial(mtl);
		
		// aircraft rectangle symbol
		driver->draw3DLine(lLeft, uLeft, mtl.AmbientColor);
		driver->draw3DLine(uLeft, uRight, mtl.AmbientColor);
		driver->draw3DLine(uRight, lRight, mtl.AmbientColor);
		driver->draw3DLine(lRight, lLeft, mtl.AmbientColor);
	}

	virtual const core::aabbox3d<f32>& getBoundingBox() const
	{
		return Box;
	}

	virtual s32 getMaterialCount()
	{
		return 1;
	}

	virtual SMaterial& getMaterial(s32 i)
	{
		return mtl;
	}	

	core::vector3df center, lLeft, uLeft, uRight, lRight;
	f32 radius, size;
	SMaterial mtl; 
};
now I want to draw small label next to the symbol using ITextSceneNode:

Code: Select all

SceneManager->addTextSceneNode(guienv->getBuiltInFont(), L" SOME TEXT GOES HERE ", SColor(255,255,255,255), Parent);
 
but how I get pointer to BuiltInFont ?
or how to get pointer to my custom font inside custom scene node ?

like in 2dGraphic example:

Code: Select all

gui::IGUIFont* font2 = device->getGUIEnvironment()->getFont("../../media/fonthaettenschweiler.bmp"); 
In custom node I have access to SceneMenager, VideoDriver but not to IrrlichtDevice that is needed to get GUIEnviroment and built in font....

Thanks in advance.
tip
Posts: 50
Joined: Fri Feb 13, 2004 8:53 am
Location: grenoble, France
Contact:

use global class

Post by tip »

hi,
as far as i understood your problem, it seems you may need to class a static class containing pointers to the global datas you need in you project classes without having to pass many parameters to constructor.

for example :
-------------------------------------- myGlobalData.h ------------
class myGlobalData
{
IrrlichtDevice* m_device;
};

--------------------------------------- main.cpp --------------------
#include "myGlobalData.h"
static myGlobalData m_data;

void main()
{
m_data.m_device=createDevice(...);
...
}

---------------------------------- CAircraftSymbol.cpp ---------------
#include "myGlobalData.h"
extern myGlobalData m_data;

....
// here you can use "m_data.m_device", it contains the pointer you need
Guest

Post by Guest »

It Works. Thanks for advice.
Post Reply