在Irrlicht中获取节点位置

时间:2016-10-18 11:01:35

标签: c++ irrlicht

我使用Irrlicht和C ++玩了一下,得到了以下MWE:

#include <iostream>
#include <Irrlicht/irrlicht.h>
#include <Irrlicht/driverChoice.h>
#include <cstdio>
#include <Irrlicht/EDriverTypes.h>
#include <Irrlicht/irrTypes.h>
#include <Irrlicht/IrrlichtDevice.h>

class MyEventReceiver : public irr::IEventReceiver
{
private:
    bool KeyIsDown[irr::KEY_KEY_CODES_COUNT];

public:
    virtual bool OnEvent(const irr::SEvent &event)
    {
        if(event.EventType == irr::EET_KEY_INPUT_EVENT)
            this->KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
        return false;
    }

    virtual bool IsKeyDown(irr::EKEY_CODE keyCode) const
    {
        return this->KeyIsDown[keyCode];
    }

    MyEventReceiver()
    {
        for(irr::u32 i = 0; i < irr::KEY_KEY_CODES_COUNT; ++i)
        {
            this->KeyIsDown[i] = false;
        }
    }
};

int main(void)
{
    MyEventReceiver receiver;
    irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_OPENGL, irr::core::dimension2d<irr::u32>(1024, 800), 16, false, false, false, &receiver);
    irr::video::IVideoDriver* driver = device->getVideoDriver();

    irr::scene::ISceneManager* scmg = device->getSceneManager();
    irr::scene::ICameraSceneNode *camera = scmg->addCameraSceneNodeFPS();
    getchar();

    const double pref_pos = 2.5;
    irr::core::vector3df sphere_cur_pos = irr::core::vector3df(0, 0, 0);
    irr::core::vector3df sphere_position = irr::core::vector3df(0, 0, 0);
    std::cout << "Set initial vectors\n!";
    irr::scene::ISceneNode *cur_node = nullptr;
    cur_node = scmg->addSphereSceneNode(1.0f, 16, 0, -1, irr::core::vector3df(10, 0, 0));
    std::cout << "Set node\n";
    sphere_cur_pos = (*cur_node).getPosition();
    std::cout << "New sphere is at (" << sphere_cur_pos.X << ", " << sphere_cur_pos.Y << ", " << sphere_cur_pos.Z << ')' << '\n';
    std::cout << "Hello World\n";
    getchar();
    return 0;
}

编译行是

g++-5 -std=c++14 irrlicht_vector_test.cpp -o irrlicht -lIrrlicht `pkg-config --libs x11` `pkg-config --libs xxf86vm` `pkg-config --libs gl`  && ./irrlicht

程序的输出是

Set initial vectors
!Set node
New sphere is at (2.70951e-35, 37135.9, 2.83893e-29)
Hello World

如果我交换

sphere_cur_pos = (*cur_node).getPosition();

sphere_cur_pos = (*cur_node).getAbsolutePosition();

我得到输出

Set initial vectors
!Set node
New sphere is at (1, 1, 1)
Hello World

两个输出均与addSphereSceneNode()中的矢量设置无关。我做错了什么?

0 个答案:

没有答案