SetClipPlane

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
tmyke
Competition winner
Posts: 22
Joined: Thu Apr 03, 2008 4:43 pm
Location: France

SetClipPlane

Post by tmyke »

Hello all. Here is a small code with the use of the command setclipplane. Only, there is a small bug with OpenGL driver (it seem):
(Irrlicht 1.4.2)

Here are without clipplane:
Image

here is with clipplane (DX9) :)
Image

and the same code, with OpenGL driver. :?
Image

With the OpenGL driver, all the Objects are cut in the middle. Is this normal ?


the code:

Code: Select all

#include <iostream>
#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

// librairies
#ifdef _IRR_WINDOWS_
	#pragma comment(lib, "Irrlicht.lib")
#endif

// globals data
bool _bExit = false;
IVideoDriver* driver;
ISceneNode* node1;
ISceneNode* node2;
ISceneNode* node3;

// IEventReceiver, keyboard management
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(const SEvent& event)
	{
		if (event.EventType == irr::EET_KEY_INPUT_EVENT  && !event.KeyInput.PressedDown)
		{
			switch(event.KeyInput.Key)
			{
				case KEY_ESCAPE:
				{
					_bExit = true;
					return true;
				}
				case KEY_KEY_S:
				{
					core::plane3df reflexion  ( core::vector3df( 0 , 10 , 0 ) , core::vector3df ( 0 , 1 , 0 ) );
					driver->setClipPlane( 1 , reflexion  , false );
					return true;
				}
			}
		}
		return false;
	}
};
// main entry
int main()
{
	static int oldTime;

	MyEventReceiver _EventReceiver;

	// let user select driver type
	video::E_DRIVER_TYPE driverType;
	printf("Please select the driver you want for this example:\n"\
		" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
		" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
		" (f) NullDevice\n (otherKey) exit\n\n");

	char i;
	std::cin >> i;

	switch(i)
	{
		case 'a': driverType = video::EDT_DIRECT3D9;break;
		case 'b': driverType = video::EDT_DIRECT3D8;break;
		case 'c': driverType = video::EDT_OPENGL;   break;
		case 'd': driverType = video::EDT_SOFTWARE; break;
		case 'e': driverType = video::EDT_BURNINGSVIDEO; break;
		case 'f': driverType = video::EDT_NULL;     break;
		default: return 0;
	}	
	
	IrrlichtDevice *device = createDevice( driverType, 
											dimension2d<s32>(800, 600), 
											32,
											false, 
											false, 
											true, 
											&_EventReceiver);
	


	//		video driver, SceneManager et GUI.
	driver					= device->getVideoDriver();
	ISceneManager* smgr		= device->getSceneManager();
	ITimer *timer			= device->getTimer();

	// my nodes
	node1 = smgr->addCubeSceneNode(15.0f);
	node2 = smgr->addSphereSceneNode(7.0f);
	node2->setPosition( vector3df(10,20,0));
	node3 = smgr->addSphereSceneNode(7.0f);
	node3->setPosition( vector3df(-10,10,0));

	//textures and light=false
	if (node1)
	{	node1->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
		node1->setMaterialFlag ( video::EMF_LIGHTING , false );	}
	if (node2)
	{	node2->setMaterialTexture( 0, driver->getTexture("../../media/fire.bmp") );
	    node2->setMaterialFlag ( video::EMF_LIGHTING , false );	} 
	if (node3)
	{	node3->setMaterialTexture( 0, driver->getTexture("../../media/fire.bmp") );
	    node3->setMaterialFlag ( video::EMF_LIGHTING , false );	}

	// FPS Camera.
	SKeyMap keyMap[4] = 
	{
		{EKA_MOVE_FORWARD,	KEY_UP},
		{EKA_MOVE_BACKWARD,	KEY_DOWN},
		{EKA_STRAFE_LEFT,	KEY_LEFT},
		{EKA_STRAFE_RIGHT,	KEY_RIGHT},
	};
	smgr->addCameraSceneNodeFPS( NULL , 100.0f, 310.0f, -1, keyMap, 4);
	smgr->getActiveCamera()->setPosition(core::vector3df(0,20,-30));
	smgr->getActiveCamera()->setTarget(core::vector3df(0,5,0) );
	

    // clipping creation
    core::plane3df reflexion  ( core::vector3df( 0 , 4 , 0 ) , core::vector3df ( 0 , 1 , 0 ) );
    driver->setClipPlane( 1 , reflexion  , false );

	// main loop
	int lastFPS = -1;
	while(device->run() & !_bExit)
	{
		driver->beginScene(true, true, SColor(255,100,101,140));
			driver->enableClipPlane ( 1 , true );
            smgr->drawAll();
		driver->endScene();
	}
	device->drop();

	return 0;
}

Thank you in advance for your answers.
Strength and wisdom.
Admin of the http://www.irrlicht.fr and dad of N3xtD.
Sorry for my poor English.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

I LOVE those newcomers who on their first post contribute to the community! ^^

Welcome :)
Aranoth
Posts: 4
Joined: Sun Nov 12, 2006 11:53 am
Location: France
Contact:

Post by Aranoth »

I have the same problem with the latest SVN revision and a GeForce 7600

Looks like the clipping plane is applied in each object coordinates space instead of world coordinates space.

Maybe a problem with transformations matrix ? Could it be that they affect the clipping plane ?

EDIT: I forget to mention that I run under Windows XP SP2
Post Reply