Page 1 of 1

[solved] Strange zbuffer problem

Posted: Fri Aug 31, 2007 5:36 pm
by ferdy182
Hi, I have a very newbie question XD

I have created a customSceneNode that draws a plane.

Then, I use the scenemanager to add a cube an place it over the plane.

But, the plane is always drawn over the cube, no matter which angle the camera is, and both are only seen when you look at the scene from the profile (the plane doesn't touch the cube).

Any suggestions? code are pretty similar to the customscenenode tutorial.

I'm stuck.

Thanks!

Posted: Fri Aug 31, 2007 8:27 pm
by hybrid
You seem to have set up your scene node's material in a wrong way. Be sure to have zbuffer enabled (also writing). For a plane it could be useful to have backface culling of to see the other side of the plane, too.
Did you add the plane to the scene manager or do you render it manually?
BTW: Irrlicht has a hill plane node which you can instantiate without hills and with arbitrary tesselation.

Posted: Sat Sep 01, 2007 11:46 am
by ferdy182
Hi,

It still doesn't work, I have uploaded a video demonstration to youtube here because I explain very badly XD http://youtube.com/watch?v=B9KfU__tAoM

Cube is still always behind the plane T_T

Zbuffer is enabled and writable. I post the code here, even with hillplanemesh, it doesn't work at all and I need to finish this ASAP T_T

Thank you for the interest :)

Code:

Code: Select all

int main(void){
	device = createDevice(video::EDT_DIRECT3D9,dimension2d<s32>(800,600),16,false,false,false,0);

	device->setWindowCaption(L"Escena 3D");
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	guienv = device->getGUIEnvironment();

	guienv->addStaticText(L"Bienvenido a UjiToys Basket!!", rect<int>(10,10,200,22), false);	
	ICameraSceneNode *irrcamera = smgr->addCameraSceneNodeMaya();
	irrcamera->setPosition(vector3df(160,172,323));
	irrcamera->setTarget(vector3df(160,0,50));
	irrcamera->setAutomaticCulling(scene::E_CULLING_TYPE::EAC_OFF);
	irrcamera->setFarValue(1000.0);
	irrcamera->setNearValue(0.0);

	
	IAnimatedMeshSceneNode *cancha = smgr->addAnimatedMeshSceneNode(smgr->addHillPlaneMesh("cancha",dimension2d<f32>(240,320),dimension2d<s32>(1,1)),0,-1,vector3df(160,-1,120),vector3df(0,-90,0));
	cancha->setAutomaticCulling(scene::E_CULLING_TYPE::EAC_OFF);
	cancha->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_LIGHTING,false);
	cancha->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_BACK_FACE_CULLING,false);
	cancha->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_ZBUFFER,true);
	cancha->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_ANISOTROPIC_FILTER,true);
	cancha->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_TRILINEAR_FILTER,true);
	ITexture *tex = driver->getTexture("court.png");
	cancha->setMaterialTexture(0,tex);	
	ISceneNode *spheres[4];
	spheres[0]=smgr->addSphereSceneNode();
	spheres[1]=smgr->addSphereSceneNode(5,16,0,-1,vector3df(320,0,0));
	spheres[2]=smgr->addSphereSceneNode(5,16,0,-1,vector3df(320,0,240));
	spheres[3]=smgr->addSphereSceneNode(5,16,0,-1,vector3df(0,0,240));
	for(int i=0;i<4;i++)
		spheres[i]->setAutomaticCulling(EAC_OFF);


	ISceneNode * cubo = smgr->addCubeSceneNode(10,0,-1,vector3df(160,10,50));
	cubo->setAutomaticCulling(EAC_OFF);	
	

	while(1){
		if(device->run()){
			driver->beginScene(true,true,SColor(255,255,100,101));
			smgr->drawAll();
			guienv->drawAll();
			driver->endScene();
		}		
	}
	device->drop();
}

Posted: Sat Sep 01, 2007 12:59 pm
by ferdy182

Posted: Sun Sep 02, 2007 9:21 am
by ferdy182
I got it!!
I found the cause of the problem, was this line:
irrcamera->setNearValue(0.0);
The value must be greater than 0.

I hope this help somebody.