a simple grid class

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

Thanks. The following code compiles but crashes at runtime.

Code: Select all

#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


#include "grid.h"



int main(int argc, char** argv)
{

    IrrlichtDevice *device =
        createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
            false, false, false, 0);

    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();

    device->setWindowCaption(L"IrrTest");

    ICameraSceneNode* 	camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);

    Grid* grid;

    while(device->run())
    {
        driver->beginScene(true, true, SColor(0,0,0,0));
        smgr->drawAll();
        grid->draw(smgr);
        guienv->drawAll();
        driver->endScene();
    }


    device->drop();

    return 0;
}

It's the...
IrrTest.exe has encoutered a problem and needs to close. We are sorry for the incovenience.
error message that I get.


Thanks for any help.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If you use pointers you need to initialize them. I see two choices, but both involve initializing the grid properly before using it.

Code: Select all

// you can put a grid on the stack.
Grid option1;

// or you can allocate one from the heap. notice i'm initializing the pointer
// to point to an actual grid instance.
Grid* option2 = new Grid;

//
while (device->run())
{
    if (driver->beginScene(...))
    {
        // if you have a reference to an instance, you would draw it like this.
        option1.draw(smgr);

        // if you have a pointer to the instance, you would draw it like this.
        option2->draw(smgr);

        // other stuff
        
        driver->endScene();
    }
}

delete option2;
Personally, I think this grid should be a scene node like everything else in Irrlicht.

Travis
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

oh bollocks... cheers vitek i didnt relise.
I feel stupid now :(
:lol:
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post by humbrol »

MasterGod wrote:
Virion wrote:Grid* grid;
Grid* whatever;
and..

Code: Select all

grid->draw();
whatever->draw();
Thank you very much, using irrlicht to round out my c++, its easier to learn when your trying to do something you like.
SwitchCase
Posts: 170
Joined: Sun Jul 01, 2007 11:41 pm
Location: Manchester, UK

Post by SwitchCase »

The grid works great! I'm using as part of a irrlicht project template in code blocks.

Image

Download test app: http://www.fileden.com/files/2007/11/21 ... rrTest.zip

Thanks for this mohaps.
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Shamelessly pimping my own Scenenode here:

I finally managed to convert this class into a scene node, while adding a few optional features. You can get it at this thread: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24938

Thanks mohaps for creating this base class!
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
mohaps
Posts: 248
Joined: Tue Jun 08, 2004 1:54 pm
Location: Shrewsbury MA
Contact:

Post by mohaps »

wow! returning after a long time to irrlicht forums... nice to see people using this... :P
---
Saurav Mohapatra
author, artist and bona fide geek

web: http://www.mohaps.com
email: mohaps AT gmail DOT com
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

mohaps wrote:wow! returning after a long time to irrlicht forums... nice to see people using this... :P
You're kidding? It's so damn good it should get into the lib (Dark_Kilauea's version of it as a scene node..) :wink: .
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

I did minor optimizations to your method, but my scenenode is very much the same internally. The next step in my mind is being able to either add LOD to the grid to save rendering time, or convert over to a dynamically textured quad for the grid itself. Unfortunately, I do not have the time to implement either of these approaches.
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Post Reply