Custom Scene Node problem

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
steveth45
Posts: 14
Joined: Fri Mar 03, 2006 2:42 am
Location: Eugene, OR, USA
Contact:

Custom Scene Node problem

Post by steveth45 »

I made a working custom scene node that is essentially a textured square panel. When I make one, it works fine, when I make more than one, I only see one. I made sure, each time I create a new one, I pass in a unique id number. Any ideas? Here's the code.

Code: Select all

class CFloorSceneNode : public scene::ISceneNode
{

	core::aabbox3d<f32> Box;
	video::S3DVertex Vertices[4];
	video::SMaterial Material;

public:

	CFloorSceneNode(irr_wrapper & parent, s32 id, char * tex, float size)
		: scene::ISceneNode(parent.getSmgr()->getRootSceneNode(), parent.getSmgr(), id)
	{
		Material.Wireframe = false;
		Material.Lighting = false;

        setMaterialTexture(0, parent.getDriver()->getTexture(tex));
        float half_size = size / 2.f;

		Vertices[0] = video::S3DVertex(half_size,half_size,0, 0,0,1, video::SColor(255,255,255,255), 1, 0);
		Vertices[1] = video::S3DVertex(half_size,-half_size,0, 0,0,1, video::SColor(255,255,255,255), 1, 1);
		Vertices[2] = video::S3DVertex(-half_size,-half_size,0, 0,0,1, video::SColor(255,255,255,255), 0, 1);
		Vertices[3] = video::S3DVertex(-half_size,half_size,0, 0,0,1, video::SColor(255,255,255,255), 0, 0);

		Box.reset(Vertices[0].Pos);
		for (s32 i=1; i<4; ++i)
			Box.addInternalPoint(Vertices[i].Pos);
	}

	virtual void OnRegisterSceneNode()
	{
		if (IsVisible)
			SceneManager->registerNodeForRendering(this);

		ISceneNode::OnRegisterSceneNode();
	}

	virtual void render()
	{
		u16 indices[] = { 0,2,1, 2,0,3 };
		video::IVideoDriver* driver = SceneManager->getVideoDriver();

		driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 2);
	}

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

	virtual u32 getMaterialCount() { return 1; }

	virtual SMaterial& getMaterial(u32 i) { return Material; }
};
+--------+
steveth45
+--------+
Phant0m51
Posts: 106
Joined: Mon Jan 15, 2007 6:07 am

Post by Phant0m51 »

Are you placing 2 nodes on top of each other so that you can only see the 1? And can you show some code for placing the node into the scene, so we can see if there is anything there that might be causing issues?
steveth45
Posts: 14
Joined: Fri Mar 03, 2006 2:42 am
Location: Eugene, OR, USA
Contact:

Fixed

Post by steveth45 »

Whoops! This scene node works fine, actually. I wasn't setting the position correctly, so they were indeed all overlapping. It's actually working fine. I've been coding for the last 10 hours straight for a competition, and so I'm prone to making small mistakes. Thanks for looking at it though.
+--------+
steveth45
+--------+
Phant0m51
Posts: 106
Joined: Mon Jan 15, 2007 6:07 am

Post by Phant0m51 »

No problem, good luck on your competition!
Post Reply