[from now] 2013/06/04 15:39:14

diff --git a/fang.opensdf b/fang.opensdf
deleted file mode 100755
index 36c146e..0000000
Binary files a/fang.opensdf and /dev/null differ
diff --git a/fang.sdf b/fang.sdf
index ad5ee4c..60a78ed 100755
Binary files a/fang.sdf and b/fang.sdf differ
diff --git a/fang.v11.suo b/fang.v11.suo
index ec6208f..fc39d4a 100755
Binary files a/fang.v11.suo and b/fang.v11.suo differ
diff --git a/main.cpp b/main.cpp
index be87fea..bdfcbd9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,14 +1,43 @@
 #include <irrlicht.h>
+#include <vector>
 #include "driverChoice.h"

+using namespace std;
 using namespace irr;

 #ifdef _MSC_VER
 #pragma comment(lib, "Irrlicht.lib")
 #endif

-class CSampleSceneNode
-    : public scene::ISceneNode
+class MyEventReceiver : public IEventReceiver
+{
+public:
+    // This is the one method that we have to implement
+    virtual bool OnEvent(const SEvent &event)
+    {
+        // Remember whether each key is down or up
+        if (event.EventType == irr::EET_KEY_INPUT_EVENT) KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
+
+        return false;
+    }
+
+    // This is used to check whether a key is being held down
+    virtual bool IsKeyDown(EKEY_CODE keyCode) const
+    {
+        return KeyIsDown[keyCode];
+    }
+
+    MyEventReceiver()
+    {
+        for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i) KeyIsDown[i] = false;
+    }
+
+private:
+    // We use this array to store the current state of each key
+    bool KeyIsDown[KEY_KEY_CODES_COUNT];
+};
+
+class CSampleSceneNode : public scene::ISceneNode
 {
     core::aabbox3d <f32> Box;
     video::S3DVertex     Vertices[4];
@@ -20,17 +49,13 @@ public:
                      s32                   id)
         : scene::ISceneNode(parent, mgr, id)
     {
-        Material.Wireframe = false;
+        Material.Wireframe = true;
         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);
+        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);
     }
@@ -70,14 +95,30 @@ public:

 int main()
 {
+    vector <int> vec;
+    vec.push_back(1);
+    vec.push_back(2);
+
+    for (int &i : vec) {
+        i++; // increments the value in the vector
+    }
+    for (int i : vec) {
+        // show that the values are updated
+        cout << i << endl;
+    }
+
     // ask user for driver
-    video::E_DRIVER_TYPE driverType = driverChoiceConsole();
+    // video::E_DRIVER_TYPE driverType = driverChoiceConsole();
+    video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
     if (driverType == video::EDT_COUNT) return 1;

     // create device

+    // create device
+    MyEventReceiver receiver;
+
     IrrlichtDevice *device = createDevice(driverType,
-                                          core::dimension2d <u32>(640, 480), 16, false);
+                                          core::dimension2d <u32>(640, 480), 16, false, false, false, &receiver);

     if (device == 0) return 1; // could not create selected driver.

@@ -88,13 +129,63 @@ int main()
     video::IVideoDriver  *driver = device->getVideoDriver();
     scene::ISceneManager *smgr   = device->getSceneManager();

+    video::ITexture *images = driver->getTexture("./irrlicht/media/2ddemo.png");
+    driver->makeColorKeyTexture(images, core::position2d <s32>(0, 0));
+
+    gui::IGUIFont *font  = device->getGUIEnvironment()->getBuiltInFont();
+    gui::IGUIFont *font2 = device->getGUIEnvironment()->getFont("./irrlicht/media/fonthaettenschweiler.bmp");
+
+    core::rect <s32> imp1(349, 15, 385, 78);
+    core::rect <s32> imp2(387, 15, 423, 78);
+
+    driver->getMaterial2D().TextureLayer[0].BilinearFilter = true;
+    driver->getMaterial2D().AntiAliasing                   = video::EAAM_FULL_BASIC;
+
+    scene::ISceneNode *node = smgr->addSphereSceneNode();
+    if (node) {
+        node->setPosition(core::vector3df(0, 0, 30));
+        node->setMaterialTexture(0, driver->getTexture("./irrlicht/media/wall.bmp"));
+        node->setMaterialFlag(video::EMF_LIGHTING, false);
+    }
+
+//    scene::ISceneNode *n = smgr->addCubeSceneNode();
+//    if (n) {
+//        n->setMaterialTexture(0, driver->getTexture("./irrlicht/media/t351sml.jpg"));
+//        n->setMaterialFlag(video::EMF_LIGHTING, false);
+//        scene::ISceneNodeAnimator *anim = smgr->createFlyCircleAnimator(core::vector3df(0, 0, 30), 10.0f, 0.01f);
+//        if (anim) {
+//            n->addAnimator(anim);
+//            anim->drop();
+//        }
+//    }
+//
+//    scene::IAnimatedMeshSceneNode *anms = smgr->addAnimatedMeshSceneNode(smgr->getMesh("./irrlicht/media/ninja.b3d"));
+//    if (anms) {
+//        scene::ISceneNodeAnimator *anim = smgr->createFlyStraightAnimator(core::vector3df(100, 0, 60), core::vector3df(-100, 0, 60), 3500, true);
+//        if (anim) {
+//            anms->addAnimator(anim);
+//            anim->drop();
+//        }
+//
+//        anms->setMaterialFlag(video::EMF_LIGHTING, false);
+//
+//        anms->setFrameLoop(0, 13);
+//        anms->setAnimationSpeed(15);
+////      anms->setMD2Animation(scene::EMAT_RUN);
+//
+//        anms->setScale(core::vector3df(2.f, 2.f, 2.f));
+//        anms->setRotation(core::vector3df(0, -90, 0));
+////      anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
+//    }
+
+    // smgr->addCameraSceneNodeFPS();
+    // device->getCursorControl()->setVisible(false);
+
     smgr->addCameraSceneNode(0, core::vector3df(0, -40, 0), core::vector3df(0, 0, 0));

-    CSampleSceneNode *myNode =
-        new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
+    CSampleSceneNode *myNode = new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);

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

     if (anim) {
         myNode->addAnimator(anim);
@@ -104,25 +195,86 @@ int main()
     myNode->drop();
     myNode = 0; // As I shouldn't refer to it again, ensure that I can't

-    u32 frames = 0;
+    // device->getGUIEnvironment()->addImage(driver->getTexture("./irrlicht/media/irrlichtlogoalpha2.tga"), core::position2d <s32>(10, 20));
+    // gui::IGUIStaticText *diagnostics = device->getGUIEnvironment()->addStaticText(L"", core::rect <s32>(10, 10, 400, 20));
+    // diagnostics->setOverrideColor(video::SColor(255, 255, 255, 0));
+
+    int lastFPS = -1;
+
+    // In order to do framerate independent movement, we have to know
+    // how long it was since the last frame
+    u32 then = device->getTimer()->getTime();
+
+    // This is the movemen speed in units per second.
+    const f32 MOVEMENT_SPEED = 5.f;
+
     while (device->run()) {
-        driver->beginScene(true, true, video::SColor(0, 100, 100, 100));
+        // Work out a frame delta time.
+        const u32 now            = device->getTimer()->getTime();
+        const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
+        then = now;
+
+        core::vector3df nodePosition = node->getPosition();
+
+        if (receiver.IsKeyDown(irr::KEY_KEY_W)) nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
+        else if (receiver.IsKeyDown(irr::KEY_KEY_S)) nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;

-        smgr->drawAll();
+        if (receiver.IsKeyDown(irr::KEY_KEY_A)) nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
+        else if (receiver.IsKeyDown(irr::KEY_KEY_D)) nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;
+
+        node->setPosition(nodePosition);
+
+        u32 time = device->getTimer()->getTime();
+        driver->beginScene(true, true, video::SColor(255, 113, 113, 133));
+
+        driver->draw2DImage(images, core::position2d <s32>(50, 50), core::rect <s32>(0, 0, 342, 224), 0, video::SColor(255, 255, 255, 255), true);
+        driver->draw2DImage(images, core::position2d <s32>(164, 125), (time / 500 % 2) ? imp1 : imp2, 0, video::SColor(255, 255, 255, 255), true);
+        driver->draw2DImage(images, core::position2d <s32>(270, 105), (time / 500 % 2) ? imp1 : imp2, 0, video::SColor(255, (time) % 255, 255, 255), true);
+        if (font) font->draw(L"This demo shows that Irrlicht is also capable of drawing 2D graphics.", core::rect <s32>(130, 10, 300, 50), video::SColor(255, 255, 255, 255));
+        if (font2) font2->draw(L"Also mixing with 3d graphics is possible.", core::rect <s32>(130, 20, 300, 60), video::SColor(255, time % 255, time % 255, 255));
+
+        driver->enableMaterial2D();
+        driver->draw2DImage(images, core::rect <s32>(10, 10, 108, 48), core::rect <s32>(354, 87, 442, 118));
+        driver->enableMaterial2D(false);
+
+        core::position2d <s32> m = device->getCursorControl()->getPosition();
+        driver->draw2DRectangle(video::SColor(100, 255, 255, 255), core::rect <s32>(m.X - 20, m.Y - 20, m.X + 20, m.Y + 20));
+
+        smgr->drawAll();                        // draw the 3d scene
+        device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)

         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;
+
+        int fps = driver->getFPS();
+
+        if (lastFPS != fps) {
+            core::stringw tmp(L"Movement Example - Irrlicht Engine [");
+            tmp += driver->getName();
+            tmp += L"] fps: ";
+            tmp += fps;
+
+            device->setWindowCaption(tmp.c_str());
+            lastFPS = fps;
         }
     }

+    // u32 frames = 0;
+    // while (device->run()) {
+    //    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;
-}
\ No newline at end of file
+}
+