3

我一直试图在 Irrlicht 内使用子弹,但无济于事。我试图编写两组项目符号。我有一个“激光”和一个“火箭”。前者发射广告牌,后者发射网格。

我已经设法为前者创建了一个有效的广告牌,但我完全无法以任何方式改变它的位置。我不希望它从玩家的脸上产生,而是从武器(在屏幕右侧)产生。我试图将广告牌作为武器节点的父级,并且我尝试了大值和小值来测试任何值问题。两者都没有奏效。

我创建了一个 IMesh 节点供火箭使用。任何尝试用它拍摄时,我都会遇到大量的崩溃。在尝试触发网格时,我的输出会给我以下错误:

Loaded mesh: ../../media/rocketlauncher_shell.obj
First-chance exception at 0x00281a34 in 15.LoadIrrFile.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00281a34 in 15.LoadIrrFile.exe: 0xC0000005: Access violation reading location 0x00000000.
The program '[8092] 15.LoadIrrFile.exe: Native' has exited with code -1073741819 (0xc0000005).

我检查了超过一百万次,路径完全正确。Rocketlauncher_shell.obj 很高兴直接坐在 ../../media 中

这是我的代码:

void CDemo::shoot()
{
    scene::ISceneManager* sm = device->getSceneManager();
    scene::ICameraSceneNode* camera = sm->getActiveCamera();

    if (!camera)
        return;

    SParticleImpact imp;
    imp.when = 0;

    // get line of camera

    core::vector3df start = camera->getPosition();
    core::vector3df end = (camera->getTarget() - start);
    end.normalize();

    SBullet bullet;

    bullet.direction = end;
    start += end*8.0f;
    end = start + (end * camera->getFarValue());

    scene::ISceneNode* node = 0;

    if (shotgunactive)
    {
        // TEMPORARY CRASH PREVENTION

        node = sm->addBillboardSceneNode(0,
            core::dimension2d<f32>(25,25), start);

        bullet.node = node;
        node->setName("laserbullet");

        node->setMaterialFlag(video::EMF_LIGHTING, false);
        node->setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/fireball.bmp"));
        node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
    }

    if (laseractive)
    {
        // create fire ball

        node = sm->addBillboardSceneNode(0, core::dimension2d<f32>(25,25), core::vector3df(100.0f,0.1f,2.0f));

        bullet.node = node;
        node->setName("laserbullet");

        node->setMaterialFlag(video::EMF_LIGHTING, false);
        node->setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/fireball.bmp"));
        node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);

        cout << "LASER SHOT" << endl;
    }

    else if (rocketactive)
    {
        // Draw Rocket Shell
        scene::IMesh* nodemesh = smgr->getMesh("../../media/rocketlauncher_shell.obj");
        scene::IMeshSceneNode* node = smgr->addMeshSceneNode(nodemesh);
        node->setMaterialFlag(video::EMF_LIGHTING, false);
        node->setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/6fe78a94.tga"));
        node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
        bullet.node = node;
        node->setName("rocketbullet");
    }

    f32 length = (f32)(end - start).getLength();
    const f32 speed = 0.6f;
    u32 time = (u32)(length / speed);

    scene::ISceneNodeAnimator* anim = 0;

    // set flight line

    anim = sm->createFlyStraightAnimator(start, end, time);

    node->addAnimator(anim);
    anim->drop();

    // when it should disappear
    bullet.when = device->getTimer()->getTime() + (time - 100);
    Bullets.push_back(bullet);

    // play sound
#ifdef USE_IRRKLANG
    if (ballSound)
        irrKlang->play2D(ballSound);
#endif
#ifdef USE_SDL_MIXER
    if (ballSound)
        playSound(ballSound);
#endif


    return;
}

在所有情况下,布尔值都可以正常工作。除上述问题外,调试行将始终显示,并且一切都将完全正常运行。

请注意“laseractive”和“rocketactive”行中的内容。

我在“LoadIrrFile”默认项目#15 之上构建了这个程序。

以下是所需参考的完整代码:http: //pastie.org/pastes/8623503/text

(这不是最漂亮的代码 - 正在进行中,Irrlicht 的第一次尝试)

顺便说一句 - 在 Irrlicht 中是否有可能使用即时扫描武器?我想为我的霰弹枪武器编写这样的功能。

4

0 回答 0