Help on "attaching" a Node (and its mesh) to an entity

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
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Help on "attaching" a Node (and its mesh) to an entity

Post by Gnasty Gnork »

Here is my class:

.h

Code: Select all

class CreatureClass : public scene::ISceneNode
 
{
    scene::IAnimatedMesh *mesh;
    core::aabbox3d<f32> Box;
    video::SMaterial Material;
 
public:
    CreatureClass(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);//  : scene::ISceneNode(parent, mgr, id){};
 
    virtual void OnRegisterSceneNode();
    virtual void render();
 
};
.cpp

Code: Select all

CreatureClass::CreatureClass(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id) 
        : scene::ISceneNode(parent, mgr, id)
    {   
        mesh = SceneManager->getMesh("../models/cowshooter.obj");
        Material.Lighting = true;
        Material.Wireframe = false;
        scene::ISceneNode::setAutomaticCulling(scene::EAC_OFF);
        //Box = CreatureClass.getTransformedBoundingBox();
    }
 
     void CreatureClass::OnRegisterSceneNode()
    {
        if (IsVisible)
        SceneManager->registerNodeForRendering(this);
        ISceneNode::OnRegisterSceneNode();
    }
 
     void CreatureClass::render()
    {
        video::IVideoDriver* driver = SceneManager->getVideoDriver();
 
        driver->setMaterial(Material);
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
    }
 
Same as the example 3, in my main i call the constructor:

Code: Select all

CreatureClass* soldier; 
    soldier = new CreatureClass(smgr->getRootSceneNode(),smgr,1);
The problem is that i get a compile error because apparently i cant create an abstract instance of CreatureClass.


Help me please, i feel like im missing something really dumb as always but cant figure out what...(im trying to learn :D )

Also i have no idea on how to get the bounding box.
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Help on "attaching" a Node (and its mesh) to an entity

Post by Gnasty Gnork »

I am reading right now about "composition" (basically storing pointers to nodes in classes, in this case)

But im not sure to understand how it would work.. i assume i will need to create functions for basically everything (movement and such).

Could someone please point me to the right way? Thank you
Gnasty Gnork
Posts: 18
Joined: Fri Jun 20, 2014 12:12 pm

Re: Help on "attaching" a Node (and its mesh) to an entity

Post by Gnasty Gnork »

yay i did it using the composition method. Im so proud right now XD even if its a pity achievement for most of you guys im happy :D
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Help on "attaching" a Node (and its mesh) to an entity

Post by christianclavet »

Interesting way of doing it. I did not used any parent class, and added the node directly for mesh reference only. I'm using the node ID for referencing the node.
AReichl
Posts: 270
Joined: Wed Jul 13, 2011 2:34 pm

Re: Help on "attaching" a Node (and its mesh) to an entity

Post by AReichl »

You need to program ALL functions of the Interface that end with "= 0;"
That is render() and getBoundingBox().

Maybe you should solve a problem step by step before musing over things like composition, specially because the next question would be how to add your "composition" to the scene manager.
Post Reply