Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
IrrlichtDevice * device =
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 32);
IVideoDriver * driver = device->getVideoDriver();
ISceneManager * smgr = device->getSceneManager();
IGUIEnvironment * guienv = device->getGUIEnvironment();
// Create an orthogonal (orthographic projection) camera
ICameraSceneNode * camera = smgr->addCameraSceneNode(0, vector3df(0,0,-10), vector3df(0,0,0));
matrix4 orthoMatrix;
orthoMatrix.buildProjectionMatrixOrthoLH(20.f, 15.f, 5.f, 100.f);
camera->setProjectionMatrix(orthoMatrix, true); // SVN / 1.5
// camera->setProjectionMatrix(orthoMatrix); // <= 1.4.2
// camera->setIsOrthogonal(true);
// Create a simple quad mesh
SMeshBuffer * buffer = new SMeshBuffer();
S3DVertex vertices[4];
vertices[0] = S3DVertex(0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -1.0f, SColor(0, 255, 255, 255), 1.0f, 1.0f);
vertices[1] = S3DVertex(0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -0.5f, SColor(0, 255, 255, 255), 0.5f, 0.0f);
vertices[2] = S3DVertex(-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, -0.5f, SColor(0, 255, 255, 255), 0.0f, 0.0f);
vertices[3] = S3DVertex(-0.5f, 0.5f, 0.0f, 0.0f, 0.0f, -0.5f, SColor(0, 255, 255, 255), 0.0f, 0.5f);
u16 indices[6] = { 0, 1, 2, 0, 2, 3 };
buffer->append(vertices, 4, indices, 6);
SMesh * mesh = new SMesh();
mesh->addMeshBuffer(buffer);
buffer->drop();
// That's our quad mesh created
// Fill the screen with nodes that use this quad mesh. We are using an ortho camera
// that defines a 20 x 15 view over 1x1 nodes, so we need 20 x 15 nodes.
const u32 MAX_NODES = 20 * 15;
IMeshSceneNode * nodes[MAX_NODES];
for(int index = 0; index < MAX_NODES; ++index)
{
nodes[index] = smgr->addMeshSceneNode(mesh);
if (nodes[index])
{
nodes[index]->setMaterialFlag(EMF_LIGHTING, true);
ITexture * texture;
u32 nodeX = index % 20;
u32 nodeY = index / 20;
nodes[index]->setPosition(vector3df((f32)nodeX - 9.5f, (f32)nodeY - 7.f, 0.f));
if((nodeX + nodeY) % 2)
texture = driver->getTexture("../../media/wall.bmp");
else
texture = driver->getTexture("../../media/detailmap3.jpg");
nodes[index]->setMaterialTexture( 0, texture);
}
}
mesh->drop();
mesh = 0;
// Move a light over the scene
IBillboardSceneNode * billboard = smgr->addBillboardSceneNode();
if(billboard)
{
billboard->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
billboard->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
billboard->setMaterialFlag(video::EMF_LIGHTING, false);
billboard->setMaterialFlag(video::EMF_ZBUFFER, false);
billboard->setSize(core::dimension2d<f32>(1.0f, 1.0f));
ISceneNodeAnimator * animator = smgr->createFlyCircleAnimator(vector3df(0, 0, -1.f), 7.f, 0.001f, vector3df(0, 0, -1));
if(animator)
{
billboard->addAnimator(animator);
animator->drop();
animator = 0;
}
(void)smgr->addLightSceneNode(billboard, vector3df(0, 0, 0), SColorf(1.f, 1.f, 0.f, 1.f), 5.f);
}
smgr->setAmbientLight(SColorf(0.25f, 0.25f, 0.5f, 1.0f));
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}