I guess the name of this thread doesn't fully explain the problem so here goes. The code posted works fine but if you move the camera around a green cube you'll notice that at one camera angle the backface culling doesn't cut the faces but if you move 180 degrees or so on the other side you will see parts of the cube begin to cull out of existence leaving only pieces of it till most or all of it is gone?
The question I have is how do I backface cull from every possible camera angle?
Another question (on a similar note) I have is can I use a single
Code: Select all
drawVertexPrimitiveList
Code: Select all
irr::video::SMaterial
Code: Select all
cube_material.BackfaceCulling = true;
cube_material.Wireframe = false;
cube_material.EmissiveColor.set(0x00ff00);
driver->setMaterial(cube_material);
Code: Select all
drawVertexPrimitiveList
thanks here's the code.
Code: Select all
#include <irrlicht.h>
using namespace irr;
int main()
{
IrrlichtDevice* device = 0;
device = createDevice( video::EDT_OPENGL, core::dimension2d<u32>(640, 480));
if (device == 0)
return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* gui = device->getGUIEnvironment();
//driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
cam->setPosition(core::vector3df(0,0,0));
cam->setTarget(core::vector3df(0,0,0));
device->getCursorControl()->setVisible(false);
irr::video::SMaterial cube_material;
cube_material.BackfaceCulling = true;
cube_material.Wireframe = false;
cube_material.EmissiveColor.set(0x00ff00);
driver->setMaterial(cube_material);
driver->setTransform(irr::video::ETS_WORLD, irr::core::matrix4());
irr::u16 cube_i[24];
for(int index = 0; index < 24; index++)
cube_i[index] = index;
int a, x, y, z;
a = 1;
x = y = z = 0;
irr::video::S3DVertex cube_v[24];
// bottom face
cube_v[0].Pos.set(x, y, z);
cube_v[1].Pos.set(a+x, y, z);
cube_v[2].Pos.set(a+x ,y, a+z);
cube_v[3].Pos.set(x, y, a+z);
// top face
cube_v[4].Pos.set(x, a+y, z);
cube_v[5].Pos.set(a+x, a+y, z);
cube_v[6].Pos.set(a+x, a+y, a+z);
cube_v[7].Pos.set(x, a+y, a+z);
// front face
cube_v[8].Pos.set(x,y,z);
cube_v[9].Pos.set(x, a+y, z);
cube_v[10].Pos.set(a+x, a+y, z);
cube_v[11].Pos.set(a+x, y, z);
// back face
cube_v[12].Pos.set(x, y, a+z);
cube_v[13].Pos.set(x, a+y, a+z);
cube_v[14].Pos.set(a+x, a+y, a+z);
cube_v[15].Pos.set(a+x, y, a+z);
// draw
cube_v[16].Pos.set(x+a, y, z);//red 1
cube_v[17].Pos.set(x+a, y, a+z);
cube_v[18].Pos.set(a+x, a+y, a+z);
cube_v[19].Pos.set(a+x, y + a, z);
// right face
cube_v[20].Pos.set(x,y,z);//red 0
cube_v[21].Pos.set(x, y, a + z);
cube_v[22].Pos.set(x, a+y, a+z);
cube_v[23].Pos.set(x, a+y, z);
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->drawAll();
cube_material.BackfaceCulling = true;
cube_material.Wireframe = false;
cube_material.EmissiveColor.set(0x00ff00);
driver->setMaterial(cube_material);
driver->setTransform(irr::video::ETS_WORLD, irr::core::matrix4());
driver->drawVertexPrimitiveList(cube_v, 24, cube_i, 6, irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT);
driver->endScene();
device->sleep(50);
}
device->drop();
return 0;
}