how do i add "driver" in my class (solved)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

how do i add "driver" in my class (solved)

Post by noals »

hi

its kinda the follow up of this topic http://irrlicht.sourceforge.net/forum/v ... =1&t=47331

i use my class like that in my main.cpp:

Code: Select all

    //ragdoll test
    scene::ImyRagdollSceneNode*playerNode = new scene::ImyRagdollSceneNode(
        core::vector3df (0.0f,0.0f,0.0f),       //ragdoll position
        core::vector3df (0.0f,0.0f,0.0f),       //ragdoll rotation
        0,                                      //ragdoll state, animation
        0,                                      //ragdoll ID
        smgr,               //pointer
        0,                  //parent node
        -1);                    //ID
it work fine since it dont do anything at all actualy...
so i create a cube in my class.cpp constructor so when i use the class it render a cube in irrlicht.
i think it worked but i wasnt seeing anything so i just though about adding a texture to my cube so i can see if it work at all :

in myclass.cpp

Code: Select all

        //albator
        ImyRagdollSceneNode::ImyRagdollSceneNode
        (
            core::vector3df IragPosition,       //ragdoll position
            core::vector3df IragRotation,       //ragdoll rotation
            u32 IragState,                      //ragdoll state, animation
            u32 IragID,                         //ragdoll ID
            ISceneManager* smgr,            //pointer
            ISceneNode* parent,     //parent node
            s32 id                          //ID
        ): ISceneNode(smgr->getRootSceneNode(), smgr, id)
        {
            //init
            ragPosition=IragPosition;
            ragRotation=IragRotation;
            ragState=IragState;
            ragID=IragID;
 
            IMeshSceneNode*torso=smgr->addCubeSceneNode(30.0f,0,torsoID,torsoPos,torsoRot,core::vector3df(1.0f,1.0f,1.0f));
            torso->setMaterialTexture(0,driver->getTexture("texture/white.jpg"));  //driver is undefined
        }
but then i have this "//driver is undefined" problem so since i dont use int main() in my class file, i guess i have to use some kind of virtual void or something in myclass.h and myclass.cpp but i dont really know how.

could you tell me how to do that ?
Last edited by noals on Tue Oct 16, 2012 10:42 am, edited 1 time in total.
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: how do i add "driver" in my class

Post by zerochen »

generally you have to pass it like the smgr but in this case you already have the pointer to the videodriver

http://irrlicht.sourceforge.net/docu/cl ... 5b61e3745c
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

Re: how do i add "driver" in my class

Post by noals »

in this case you already have the pointer to the videodriver
yes, thats why i dont understand, im not sure how to be able to use it avoiding redefinition.
i forgot to put the code about it in my first post i think.

in my main.cpp usual stuff :

Code: Select all

 
    video::IVideoDriver*driver=device->getVideoDriver();
    scene::ISceneManager*smgr=device->getSceneManager();
 
in myclass.h i just have that about it

Code: Select all

 
            //render
            virtual void render();
and then in myclass.cpp i already have the fonction

Code: Select all

        //render ragdoll
        void ImyRagdollSceneNode::render()
        {
            video::IVideoDriver* driver = SceneManager->getVideoDriver();
            if (!driver) return;
        }
so how do i use it if i dont put it as an argument like smgr ?
im kinda lost here.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: how do i add "driver" in my class

Post by serengeor »

so how do i use it if i dont put it as an argument like smgr ?
You just "used" it in the code you wrote above :roll:

If you are worried which driver it's going to use, just change the name of the local/global pointer.
Working on game: Marrbles (Currently stopped).
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

Re: how do i add "driver" in my class

Post by noals »

see for yourself :
http://hpics.li/0324d53

if i use the fonction in my constructor, i encounter the same problem with "device"
so i need to redefine everything right ? but it dont work the same way because im in my class constructor, not in a int main{}.
i think i better try to init it like smgr, ive got errors if i put that :

Code: Select all

    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if(driverType==video::EDT_COUNT)
    return 1;
 
    SIrrlichtCreationParameters params;
    params.DriverType=driverType;
    params.WindowSize=core::dimension2d<u32>(800,600);
    IrrlichtDevice*device=createDeviceEx(params);
 
    if(device==0)
    return 1;
 
    video::IVideoDriver*driver=device->getVideoDriver();
dunno, this whole class thing confuse me.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: how do i add "driver" in my class

Post by serengeor »

noals wrote: dunno, this whole class thing confuse me.
That's why you should better spend some time to get better understanding of c++. Everything is confusing when you don't know how to use.
Your problems are hardly related to c++ usage, rather lack of c++ knowledge/experience.

What I was talking about was this function:

Code: Select all

            //render ragdoll
            void ImyRagdollSceneNode::render()
            {
                video::IVideoDriver* driver = SceneManager->getVideoDriver();
                if (!driver) return;
            }
You can do the same in the other function.
Working on game: Marrbles (Currently stopped).
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

Re: how do i add "driver" in my class

Post by noals »

What I was talking about was this function:
yes, thats why i said :
in myclass.cpp i already have the fonction
and then you say :
You can do the same in the other function.
and then i dont understand lol.
Everything is confusing when you don't know how to use.
generally you have to pass it like the smgr
i think i could do that, my class is working basicaly but i dont know how to use those void, virtual and the kind, i will check my book about it or some tuto and check others classes in the source.

its frustrating, its like i understand how everything works but i dont know how to mix them all well together within the class.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: how do i add "driver" in my class

Post by smso »

Since ImyRagdollSceneNode is a subclass of scene::ISceneNode, ImyRagdollSceneNode can access all the protected members of scene::ISceneNode, e.g.

Code: Select all

core::list<ISceneNodeAnimator*> Animators;
ISceneManager* SceneManager;
ITriangleSelector* TriangleSelector;
Look for "Protected Attributes" in the api doc of scene::ISceneNode.

In other words, you can do this in class ImyRagdollSceneNode:

Code: Select all

video::IVideoDriver* driver = SceneManager->getVideoDriver();
Regards,
smso
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: how do i add "driver" in my class

Post by serengeor »

noals wrote:but i dont know how to use those void, virtual and the kind
noals wrote:its frustrating, its like i understand how everything works but i dont know how to mix them all well together within the class.
Don't worry too much that you don't understand everything. Learning a programming language is not an easy task, especially if it's the first one.
Once you'll know what each of those "void", "virtual" does it will be a lot easier to decide what to use where. While reading book/tutorial try to focus and understand of what each thing does, how could you use it yourself (and ofc. try everything out).
Working on game: Marrbles (Currently stopped).
noals
Posts: 70
Joined: Sun May 18, 2008 2:59 pm

Re: how do i add "driver" in my class

Post by noals »

it compile with this code

Code: Select all

video::IVideoDriver* driver = SceneManager->getVideoDriver();
i didnt know i was able to use SceneManager instead of IrrlichtDevice kinda, its even more confusing lol
can access all the protected members of
i will keep that in mind but then i can just conclude that my class dont work at all because i cant see the cube. ><
Once you'll know what each of those "void", "virtual" does it will be a lot easier to decide what to use where. While reading book/tutorial try to focus and understand of what each thing does, how could you use it yourself (and ofc. try everything out).
basicaly, i just learn when i need it, especialy when i cant get something to work. the real problem is when i dont understand why it dont work like here kinda so i need to check exemples, try stuff, ask help, etc...

here is my project for now, compiled + source.
http://www.fileden.com/files/2006/6/21/ ... _III_2.zip
ZSQD to move E to jump (maybe WSAD for you since im french and i need to make the jump better later) camera for move and rotation + wheel zoom kinda
the terrain have some problem because of the LOD i changed i think but thats not my priority
in the source there is another playerNode commented with /* */ to display a little ninja, here i use ImyRagdollSceneNode*playerNode but it dont display my cube..
Post Reply