Page 1 of 1

Irrlicth has a scale animator?

Posted: Tue Mar 23, 2010 10:02 am
by Tranen
There is something like:
scenemanager->createScaleAnimator(...) that makes my object bigger or smaller while time is passing?

I've searched in scenemanager documentation but i haven't found it.

If I need to create it can you gave me some advice? Where I can start?

Thanks
Tranen

Posted: Tue Mar 23, 2010 10:41 am
by Bear_130278
Pseudo

Code: Select all

f32 TimeDelta=Irrtime-lastTime;TimeDelta/=100;
Node->setScale(vector3df(1.0f*TimeDelta,1.0f*TimeDelta,1.0f*TimeDelta)); lastTime=Irrtime;

Posted: Tue Mar 23, 2010 11:09 am
by randomMesh
My boids do it like this:

Code: Select all

void BoidSceneNode::OnAnimate(u32 timeMs)
{
	if (this->firstUpdate)
	{
		this->lastAnimationTime = timeMs;
		this->firstUpdate = false;
	}

	const f32 elapsed = (timeMs - this->lastAnimationTime)*0.001;
	this->lastAnimationTime = timeMs;

	if (this->perching) //if on ground
	{
		if (this->forward)
		{
			this->RelativeScale += irr::core::vector3df(1.0f, 1.0f, 1.0f)*elapsed;

			if (this->RelativeScale.X > 2.0f)
				this->forward = false;
		}
		else
		{
			this->RelativeScale -= irr::core::vector3df(1.0f, 1.0f, 1.0f)*elapsed;

			if (this->RelativeScale.X < 1.0f)
				this->forward = true;
		}
	}

	ISceneNode::OnAnimate(timeMs);
}

Posted: Tue Mar 23, 2010 11:58 am
by sudi

Code: Select all

class CScaleAnimator : public irr::scene::ISceneNodeAnimator
{
public:
    CScaleAnimator(irr::core::vector3df scalePerSec)
    {
        LastTime = 0;
    }
    
    void animateNode(irr::scene::ISceneNode* node, irr::u32 timeMs)
    {
        if (LastTime == 0)
            LastTime = timeMs;
            
        irr::f32 diff = (timeMs-LastTime) / 1000.0f;
        
        node->setScale(node->getScale()+ScalePerSec*diff);
        
        LastTime = timeMs;
    }
    
    irr::scene::ISceneNodeAnimator* createClone(irr::scene::ISceneNode* node, irr::scene::ISceneManager* newManager=0)
    {
        return new CScaleAnimator(ScalePerSec);
    }
protected:
    irr::u32 LastTime;
    irr::core::vector3df ScalePerSec;
};

Posted: Tue Mar 23, 2010 1:07 pm
by Tranen
Thanks! :)
Tranen

Posted: Tue Mar 23, 2010 1:35 pm
by hybrid
IIRC, a scale animator was added to irrExt project.

Posted: Tue Mar 23, 2010 2:27 pm
by Bear_130278
Random 8))) I got question....
What is a reason you use "this" like

Code: Select all

this->forward
I do not understand.... 8)))

Posted: Tue Mar 23, 2010 4:16 pm
by SG57
'this' is a pointer to the current class object instance. It isn't required to access members within the class like that person did, though it can be used like in the way that person did it. Probably for improved understanding when reading it (so you know where that variable or function is located that is being called).

The 'this' pointer is useful in that it allows a class to 'delete' itself. Irrlicht's reference counter (IUnknown) does this explicitly.

Posted: Wed Mar 24, 2010 6:34 am
by Bear_130278
SG57, oh cmon 8))
I know what is "this" for.... i just wondered, why randomMesh used it in the case....

Posted: Wed Mar 24, 2010 7:05 am
by randomMesh
Bear_130278 wrote:i just wondered, why randomMesh used it in the case....
I used it because i use it for all member variables and methods of a class.
So when reading my code, i know at once it's a member of the class, not an argument.

Posted: Sun Mar 28, 2010 4:25 pm
by Tranen
Hi, i'm trying to use Sudi code, here is what I do:

Code: Select all

IMeshSceneNode* s = smgr->addSphereSceneNode(10);
s->setPosition(core::vector3df(0,0,0));
    
CScaleAnimator sa(core::vector3df(4,4,4));
s->addAnimator(&sa);
before the render loop.
Nothing happens it seems that the animatedNode function is never called by the engine, so what else I must do? I need to register in some way this animator with the engine?

Thanks!
Tranen

Posted: Sun Mar 28, 2010 4:33 pm
by Tranen
Sorry I see that with this works:

Code: Select all

    
CScaleAnimator* sa2 = new CScaleAnimator(core::vector3df(4,4,4));
s->addAnimator(sa2);
Since I don't have launched a create* function a I don't need to drop the object right?

Thanks

Posted: Sun Mar 28, 2010 4:56 pm
by randomMesh
Tranen wrote:Since I don't have launched a create* function a I don't need to drop the object right?
Wrong. If you allocate memory on the heap, you have to delete it to prevent memory leaks.

Irrlichts create* methods use new too.