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_SOFTWARE, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
IVideoDriver * driver = device->getVideoDriver();
ISceneManager * smgr = device->getSceneManager();
IGUIEnvironment * guienv = device->getGUIEnvironment();
// Create a simple quad mesh
SMeshBuffer * buffer = new SMeshBuffer();
S3DVertex vertices[4];
vertices[0] = S3DVertex(1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, SColor(0, 255, 255, 255), 1.0f, 1.0f);
vertices[1] = S3DVertex(1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, SColor(0, 255, 255, 255), 1.0f, 0.0f);
vertices[2] = S3DVertex(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, SColor(0, 255, 255, 255), 0.0f, 0.0f);
vertices[3] = S3DVertex(-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, SColor(0, 255, 255, 255), 0.0f, 1.0f);
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
// Create 3 mesh nodes that use it.
IMeshSceneNode * nodes[3];
for(int node = 0; node < 3; ++node)
{
nodes[node] = smgr->addMeshSceneNode(mesh);
if (nodes[node])
{
nodes[node]->setMaterialFlag(EMF_LIGHTING, false);
ITexture * texture = driver->getTexture("../../media/wall.bmp");
nodes[node]->setMaterialTexture( 0, texture);
}
nodes[node]->setPosition(vector3df(node * 4.f, node * 3.f, 0.f));
}
mesh->drop();
// 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);
camera->setIsOrthogonal(true);
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
// Rotate the 3 nodes at different rates
for(int node = 0; node < 3; ++node)
{
vector3df rotation = nodes[node]->getRotation();
rotation.Z += 0.1f * (node + 1); // Framerate dependent!
nodes[node]->setRotation(rotation);
}
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}