Fix to text scenenode for bounding box

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
MattyBoy
Posts: 19
Joined: Fri Oct 24, 2003 3:07 pm

Fix to text scenenode for bounding box

Post by MattyBoy »

Changes to CTextSceneNode.cpp

Code: Select all

void CTextSceneNode::render()
{
	if (!Font || !Coll)
		return;

	/////////////////////////////////////////////////////////////////////
	video::IVideoDriver* driver = SceneManager->getVideoDriver();
	ICameraSceneNode* camera = SceneManager->getActiveCamera();

	if (!camera || !driver)
		return;

	if (DebugDataVisible)
	{
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		video::SMaterial m;
		m.Lighting = false;
		driver->setMaterial(m);
		driver->draw3DBox(Box, video::SColor(0,208,195,152));
	}
	//////////////////////////////////////////////////////////////////////

	core::position2d<s32> pos = Coll->getScreenCoordinatesFrom3DPosition(getAbsolutePosition(), 
		SceneManager->getActiveCamera());

	core::rect<s32> r(pos, core::dimension2d<s32>(1,1));
	Font->draw(Text.c_str(), r, Color, true, true);
}

Code: Select all

void CTextSceneNode::setText(const wchar_t* text)
{
	Text = text;

	//////////////////////////////////////////////////////////
	//Set Bounding box
	core::dimension2d<s32> dim = Font->getDimension(text);
	f32 halfWidth = (f32)dim.Width/2;
	f32 halfHeight = (f32)dim.Height/2;
	Box.MinEdge.set(-halfWidth,-halfHeight,-1.0);
	Box.MaxEdge.set(halfWidth,halfHeight,1.0);
	///////////////////////////////////////////////////////////
}
In the constructor change

Text = text;
to
setText(text);

AND
add this include
#include "IVideoDriver.h"

That should do it. Now you can pick this item with a selector.

Matt
IPv6
Posts: 188
Joined: Tue Aug 08, 2006 11:58 am

Post by IPv6 »

Thanks!!! it is still not fixed in 1.1, although text bbox is usefull in some cases
Post Reply