Irrlicth has a scale animator?

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
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

Irrlicth has a scale animator?

Post 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
Last edited by Tranen on Sun Mar 28, 2010 4:25 pm, edited 2 times in total.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post 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;
Do you like VODKA???
Image
Image
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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);
}
"Whoops..."
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post 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;
};
Last edited by sudi on Tue Mar 23, 2010 7:45 pm, edited 1 time in total.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

Post by Tranen »

Thanks! :)
Tranen
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

IIRC, a scale animator was added to irrExt project.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post 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)))
Do you like VODKA???
Image
Image
SG57
Posts: 66
Joined: Fri May 18, 2007 5:51 am

Post 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.
Bear_130278
Posts: 237
Joined: Mon Jan 16, 2006 1:18 pm
Location: Odessa,Russian Federation

Post by Bear_130278 »

SG57, oh cmon 8))
I know what is "this" for.... i just wondered, why randomMesh used it in the case....
Do you like VODKA???
Image
Image
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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.
"Whoops..."
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

Post 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
Tranen
Posts: 34
Joined: Mon May 05, 2008 5:43 pm

Post 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
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post 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.
"Whoops..."
Post Reply