Custom scene node- culling and triangle strips questions

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Broodingspark
Posts: 8
Joined: Sun Dec 30, 2007 12:26 am

Custom scene node- culling and triangle strips questions

Post by Broodingspark »

Hello,

I have two questions- both of which probably involve somebody graciously linking me somewhere that answers them (a location I have been unable to find as of yet).

The first is simple:

I'm playing around with the custom scene node tutorial, and trying to get it to draw a cube instead of the pyramidal structure it draws.

Code: Select all

	CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
		: scene::ISceneNode(parent, mgr, id)
	{
		Material.Wireframe = false;
		Material.Lighting = false;

		Vertices[0] = video::S3DVertex(-10,-10,-10, 1,1,1, video::SColor(255,0,255,255), 1, 1);
		Vertices[1] = video::S3DVertex(10,-10,-10, 1,1,1, video::SColor(255,255,0,255), 1, 1);
		Vertices[2] = video::S3DVertex(10,10,-10, 1,1,1, video::SColor(255,255,255,0), 1, 1);
		Vertices[3] = video::S3DVertex(-10,10,-10, 1,1,1, video::SColor(255,0,255,0), 1, 1);
        Vertices[4] = video::S3DVertex(-10,-10,10, 1,1,1, video::SColor(255,0,255,0), 1, 1);
		Vertices[5] = video::S3DVertex(10,-10,10, 1,1,1, video::SColor(255,255,255,0), 1, 1);
		Vertices[6] = video::S3DVertex(10,10,10, 1,1,1, video::SColor(255,0,255,0), 1, 1);
        Vertices[7] = video::S3DVertex(-10,10,10, 1,1,1, video::SColor(255,0,255,0), 1, 1);
	
		Box.reset(Vertices[0].Pos);
		for (s32 i=1; i<8; ++i)
			Box.addInternalPoint(Vertices[i].Pos);
	}


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

		ISceneNode::OnRegisterSceneNode();
	}

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

		driver->setMaterial(Material);
		driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
		driver->drawIndexedTriangleList(&Vertices[0], 12, &indices[0], 12);
	}
Basically, I added a few more vertices, and a few more triangles in the appropriate locations.

I do now have a cube, but there's some weird reverse culling going on, and I can't figure out how to sort out my normals to stop that (roughly half of my triangles are invisible at any given time).

I tried to do the:

AutomaticCullingEnabled = false;

bit, but I get an error:

"AutomaticCullingEnabled' undeclared (first use this function)

So, essentially, I'm not sure what I need to do to get that to work (although in the long run, I'd rather be pointed to something that will help explain to me how to sort out a way to cull the correct triangles rather than none at all).



Aside from that, for efficiency's sake, I'd really rather be drawing odd geometric shapes using triangle strips when I can (as I'm looking to make some rather big shapes- polygon count wise).

I searched the forum for discussion on triangles strips and found some really old posts that just told me it wasn't implemented a few years ago.

Any change there? If so, how does one draw triangle strips?

If not, can anybody suggest to me an efficient means to that end? I'm guessing I'll need to modify the core engine if it's not supported? I do gather that people have already done this, so perhaps there is some example code floating around somewhere that would help.


Thanks,[/code]
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

Perhaps you should try to get used to the docs. A search for "AutomaticCullingEnabled" gets no results, so you can bet it isn't in the engine (any more). Automatic culling isn't what you want, anyway. Search for "setMaterialFlag" and "backfaceculling".

Second, your normals depend on the order of your vertices. If they are counter-clockwise, you will get wrong normals.
Broodingspark
Posts: 8
Joined: Sun Dec 30, 2007 12:26 am

Post by Broodingspark »

Back face culling, thanks.
shogun wrote:Second, your normals depend on the order of your vertices. If they are counter-clockwise, you will get wrong normals.
Brilliant. Thank you very much; that makes a lot of sense, I thought it would be something simple like that.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

From quick look at your code I see that all your vertices have the same normal (vector 1,1,1) which of course is wrong. That may probably cause your triangles to not be seen.
They all have the same UV coordinates too ...which would cause your cube to not show texture properly if you attach one.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The automatic culling is now set within a method:
void setAutomaticCulling( E_CULLING_TYPE state)
Which not only enables/disables, but also changes the way culling is done. But this is per-scene-node culling, you really want backface cullling.
However, you should create your faces in the same orientation, because you will otherwise get problems with textures and lighting.
Post Reply