I'd like to generate a simple mesh.
It's a hexagon.
This code compile without error with
Code: Select all
g++ 04-hexagons.cpp -o 04-hexagons.elf -I/usr/include/irrlicht -L/usr/X11R6/lib -lX11 -lXxf86vm -lIrrlicht -lpng -ljpeg -lGL -Wall
I don't think it's a camera problem : I've shaked the mouse with motivation, nothing seems to hide "behind" me.
I'd like to have some advices.
Thanks.
Code: Select all
#include <irrlicht.h>
#include <math.h>
irr::IrrlichtDevice *device=0;
irr::video::IVideoDriver *driver=0;
irr::scene::ISceneManager *scenemgr=0;
irr::scene::ICameraSceneNode *cam=0;
#define PI 3.14159265
void start_irr()
{
/* createDevice has optionnals parameters(vsync, fullscreen, bpp..) */
device = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::s32>(800,600), 32 );
if (!device) { printf("Impossible to create device!\n"); exit(0); }
device->setWindowCaption(L"Hexagon test");
driver = device->getVideoDriver();
if (!driver) printf("Driver error\n");
scenemgr = device->getSceneManager();
}
void stop_irr()
{
device->drop();
}
irr::scene::SMesh * create_hexagon(int x, int y, int z, int diameter)
{
irr::scene::SMesh *mesh; //mesh (Smesh = implémentation of IMesh)
irr::scene::SMeshBuffer *mesh_buffer; //its buffer
#define NB_TRIANGLES 4 //nbr of triangles which mesh is made of.
irr::video::SColor hexagonColor(255,255,255,255);
mesh = new irr::scene::SMesh();
//SMeshBuffer == CMeshBuffer: material, and 3 buffers: Vertices, Indices, BoundingBox
mesh_buffer = new irr::scene::SMeshBuffer();
//now, we define indices of the mesh
mesh_buffer->Vertices.set_used(6); //vertices for a hexagon
mesh_buffer->Indices.set_used(NB_TRIANGLES*3); //indices for hexagon
//we build hexagon with the vertices list
irr::u16 liste_sommets[NB_TRIANGLES*3] =
{ 0,4,5, 0,1,4, 1,3,4, 1,2,3 };
for (irr::s32 i=0; i<NB_TRIANGLES*3; ++i)
mesh_buffer->Indices[i] = liste_sommets[i];
for (int i=0; i<6; i++) {
//S3DVertex: pos(x,y,z) normal(x,y,z) color(c) texture_coords(u,v)
mesh_buffer->Vertices[i] = irr::video::S3DVertex (
x+cos(PI/3*i)*diameter/2, z, y+sin(PI/3*i)*diameter/2,
0,0,0, //no normals today
hexagonColor,
0,0 //no tex coordinates either.
);
}
mesh->addMeshBuffer(mesh_buffer);
return mesh;
/* this is my hexagon. It's not very nice, but it's mine.
0 1
-----
5/ \2
\_____/
4 3
*/
}
static void main_loop()
{
//hexagon
irr::scene::SMesh *mesh_hexagon;
irr::scene::ISceneNode *scenenode_hexagon;
mesh_hexagon = create_hexagon(1.0,1.0,1.0,2.0);
scenenode_hexagon = scenemgr->addMeshSceneNode(mesh_hexagon);
scenenode_hexagon->setPosition(irr::core::vector3df(1.0,1.0,-1.0));
cam = scenemgr->addCameraSceneNodeFPS (0, 100.0f, 300.0f, 0, 0, 0, false);
//with fps cam, we better not show the cursor.
device->getCursorControl ()-> setVisible (false);
while(device->run() && driver)
{
driver->beginScene(true, true, irr::video::SColor(255,0,0,255));
scenemgr->drawAll();
driver->endScene();
device->sleep(20);
}
}
int main()
{
start_irr();
main_loop();
stop_irr();
return 0;
}