[from now] 2013/05/23 19:46:44

diff --git a/main.cpp b/main.cpp
index 9dbb0aa..be87fea 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,66 +1,127 @@
-#include <iostream>
-#include <windows.h>
 #include <irrlicht.h>
+#include "driverChoice.h"

-#ifdef _IRR_WINDOWS_
-#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
+using namespace irr;
+
+#ifdef _MSC_VER
 #pragma comment(lib, "Irrlicht.lib")
 #endif

-using namespace std;
-using namespace irr;
+class CSampleSceneNode
+    : public scene::ISceneNode
+{
+    core::aabbox3d <f32> Box;
+    video::S3DVertex     Vertices[4];
+    video::SMaterial     Material;
+
+public:
+    CSampleSceneNode(scene::ISceneNode    *parent,
+                     scene::ISceneManager *mgr,
+                     s32                   id)
+        : scene::ISceneNode(parent, mgr, id)
+    {
+        Material.Wireframe = false;
+        Material.Lighting  = false;
+
+        Vertices[0] = video::S3DVertex(0, 0, 10, 1, 1, 0,
+                                       video::SColor(255, 0, 255, 255), 0, 1);
+        Vertices[1] = video::S3DVertex(10, 0, -10, 1, 0, 0,
+                                       video::SColor(255, 255, 0, 255), 1, 1);
+        Vertices[2] = video::S3DVertex(0, 20, 0, 0, 1, 1,
+                                       video::SColor(255, 255, 255, 0), 1, 0);
+        Vertices[3] = video::S3DVertex(-10, 0, -10, 0, 0, 1,
+                                       video::SColor(255, 0, 255, 0), 0, 0);
+        Box.reset(Vertices[0].Pos);
+        for (s32 i = 1; i < 4; ++i) Box.addInternalPoint(Vertices[i].Pos);
+    }
+
+    virtual void OnRegisterSceneNode()
+    {
+        if (IsVisible) SceneManager->registerNodeForRendering(this);

-using namespace core;
-using namespace scene;
-using namespace video;
-using namespace io;
-using namespace gui;
+        ISceneNode::OnRegisterSceneNode();
+    }
+
+    virtual void render()
+    {
+        u16                  indices[] = {   0, 2, 3, 2, 1, 3, 1, 0, 3, 2, 0, 1  };
+        video::IVideoDriver *driver    = SceneManager->getVideoDriver();
+
+        driver->setMaterial(Material);
+        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
+        driver->drawVertexPrimitiveList(&Vertices[0], 4, &indices[0], 4, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
+    }
+
+    virtual const core::aabbox3d <f32> &getBoundingBox() const
+    {
+        return Box;
+    }
+
+    virtual u32 getMaterialCount() const
+    {
+        return 1;
+    }
+
+    virtual video::SMaterial &getMaterial(u32 i)
+    {
+        return Material;
+    }
+};

 int main()
 {
-    IrrlichtDevice *device = createDevice(video::EDT_OPENGL, dimension2d <u32>(640, 480), 16, false, false, false, 0);
+    // ask user for driver
+    video::E_DRIVER_TYPE driverType = driverChoiceConsole();
+    if (driverType == video::EDT_COUNT) return 1;
+
+    // create device

-    if (!device) return 1;
+    IrrlichtDevice *device = createDevice(driverType,
+                                          core::dimension2d <u32>(640, 480), 16, false);

-    IVideoDriver    *driver = device->getVideoDriver();
-    ISceneManager   *smgr   = device->getSceneManager();
-    IGUIEnvironment *guienv = device->getGUIEnvironment();
+    if (device == 0) return 1; // could not create selected driver.

-    guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!", rect <s32>(10, 10, 260, 22), true);
+    // create engine and camera

-    device->getFileSystem()->addFileArchive("./map-20kdm2.pk3");
-    scene::IAnimatedMesh *mesh = smgr->getMesh("20kdm2.bsp");
-    scene::ISceneNode    *node = 0;
+    device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");

-    if (mesh) node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
+    video::IVideoDriver  *driver = device->getVideoDriver();
+    scene::ISceneManager *smgr   = device->getSceneManager();

-    if (node) node->setPosition(core::vector3df(-1300, -144, -1249));
+    smgr->addCameraSceneNode(0, core::vector3df(0, -40, 0), core::vector3df(0, 0, 0));

-    smgr->addCameraSceneNodeFPS();
-    device->getCursorControl()->setVisible(false);
+    CSampleSceneNode *myNode =
+        new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);

-    int lastFPS = -1;
+    scene::ISceneNodeAnimator *anim =
+        smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f));

+    if (anim) {
+        myNode->addAnimator(anim);
+        anim->drop();
+        anim = 0;
+    }
+    myNode->drop();
+    myNode = 0; // As I shouldn't refer to it again, ensure that I can't
+
+    u32 frames = 0;
     while (device->run()) {
-        if (device->isWindowActive()) {
-            driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
-            smgr->drawAll();
-            guienv->drawAll();
-            driver->endScene();
-
-            int fps = driver->getFPS();
-
-            if (lastFPS != fps) {
-                core::stringw str = L"Irrlicht Engine - Quake 3 Map example [";
-                str += driver->getName();
-                str += "] FPS:";
-                str += fps;
-
-                device->setWindowCaption(str.c_str());
-                lastFPS = fps;
-            }
-        } else device->yield();
+        driver->beginScene(true, true, video::SColor(0, 100, 100, 100));
+
+        smgr->drawAll();
+
+        driver->endScene();
+        if (++frames == 100) {
+            core::stringw str = L"Irrlicht Engine [";
+            str += driver->getName();
+            str += L"] FPS: ";
+            str += (s32)driver->getFPS();
+
+            device->setWindowCaption(str.c_str());
+            frames = 0;
+        }
     }
+
     device->drop();

     return 0;