3

I have been attempting to utilise bullets within Irrlicht to no avail. I have attempted to code two sets of bullets. I have a "laser" and a "rocket". The former fires a billboard, the latter fires a mesh.

I have managed to create a working billboard for the former, but I am completely unable to change the position of it by any means. I don't want it to spawn from the player's face, but rather the weapon (on the right of the screen). I have attempted to parent the billboard to the weapon node and I have tried large and small values to test any value issues. Neither has worked.

I have created an IMesh node for use of the rocket. I am getting crashes galore at any attempt to shoot with it. My output will give me the following errors upon attempting to fire a mesh:

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).

I have checked over a million times and the pathing is entirely correct. rocketlauncher_shell.obj is happily sitting there directly within ../../media

Here is my code:

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;
}

The bools in all cases are working perfectly. debug lines will always show and everything will work entirely as it should other than the aforementioned issues.

Please focus attention on the stuff within "laseractive" and "rocketactive" lines.

I have built this program on top of the "LoadIrrFile" default project, #15.

Here is the full code for any references required: http://pastie.org/pastes/8623503/text

(it's not the prettiest code - work in progress, first attempt at Irrlicht ever)

On a side note - are hitscan weapons a possibility within Irrlicht? I would like to code my shotgun weapon with such functionality.

Rellac
  • 63
  • 6
  • lol XD irrlicht. have you attempted to hit something else beside a blankscene? that could be a irrlicht bug related to irr.scenes. – CoffeDeveloper Jan 11 '14 at 13:18
  • yes.. Irrlicht, university assignments... sigh.. The "blankscene" isn't actually what you might think. It was merely a scene that I created with less load than my actual scene for testing purposes. – Rellac Jan 11 '14 at 13:21
  • use ogre, and rename the DLL to Irrlicht.dll :P.. jokes apart. you need to see first WHERE it crash (line number) – CoffeDeveloper Jan 11 '14 at 13:23
  • you are not dropping "canim" but that should not be your problem for now. it is just a memory leak of few bytes – CoffeDeveloper Jan 11 '14 at 13:27
  • I never presumed blankscene.irr was empty, just try with something else (anything that is not insdie a *.irr file) and most important you must know where it crash (adding debuggin symbols to irrlicht.dll should help a lot!) the DLL with debug symbols is the one that is several MBs bigger of course XD – CoffeDeveloper Jan 11 '14 at 13:33
  • I'm not sure how to code without irr files. This would be my first taste of high level 3D programming, I am scraping my heels along here – Rellac Jan 11 '14 at 13:58

0 Answers0