Motion problem

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
MG

Motion problem

Post by MG »

I made program which opens .3ds file (circle) and display it. Keys W and S are for object rotation.
But motion isn't fluent. So i want soft motion of that object just like with
createFlyCircleAnimator function. How to do that?

Thanks a lot

Code: Select all

#include <irrlicht.h>

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

#pragma comment(lib, "Irrlicht.lib")

ICameraSceneNode* camera = 0;
IrrlichtDevice *device;
ISceneNode* node = 0;
ISceneNode* node_light = 0;
IVideoDriver* driver;
ISceneManager* smgr;
ISceneNodeAnimator* anim = 0; 

core::vector3df v;
core::vector3df r;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		switch(event.KeyInput.Key)
			{
			case KEY_KEY_W:
			case KEY_KEY_S:
				{
					v = node->getRotation();
					v.Z += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
					node->setRotation(v);
				} return true;

			case KEY_ESCAPE:
				if (event.KeyInput.PressedDown) {
					device->closeDevice();
					return true;
				} return true;
			} 
		return true;
	}
};


int main()
{
	MyEventReceiver receiver;

	device = createDevice(video::DT_DIRECTX8,
		core::dimension2d<s32>(800, 600),16, false, true, &receiver);

	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	
	IAnimatedMesh* mesh = smgr->getMesh("scenes/brana.3ds");
	//node = smgr->addAnimatedMeshSceneNode(mesh);
	//anim = smgr->createFlyCircleAnimator (core::vector3df(0,0,0),-20.0f);
	//node->addAnimator(anim);
	//anim->drop(); 

	v = node->getPosition();
	r = node->getRotation();

	v.Z=1;
	v.Y=0;
	v.X=0;

	r.X=90;

	node->setRotation(r);
	node->setPosition(v);

	node_light = smgr->addLightSceneNode(0, core::vector3df(0,0,0), 
		video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 600.0f);

	node_light = smgr->addLightSceneNode(0, core::vector3df(0,100,-100), 
		video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 600.0f);

	smgr->addCameraSceneNode(0, vector3df(0,0,-60), vector3df(0,0,0));

	int lastFPS = -1;

	while(device->run())
	{
		driver->beginScene(true, true, 0);

		smgr->drawAll();

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			wchar_t tmp[1024];
			swprintf(tmp, 1024, L"SpecialFX example - Irrlicht Engine"\
				L"(fps:%d) Triangles:%d", fps,
				driver->getPrimitiveCountDrawn());

			device->setWindowCaption(tmp);
			lastFPS = fps;
		}
	}

	device->drop();
	return 0;
}
MG

Rotate and move

Post by MG »

Realy anybody dont know, how to make smooth rotate and move objekt??? When i inc and dec. v.Z object moving object isn't smooth. I need result as is in 'prueba2_irr'. Its possible make this with matrix transformation or how to do that?

Thanks a help
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

I'm tryin got figure this one out myself... I tried using "while(something >= something_else) " but i'm still trying another way right 'now'.
t

Post by t »

Store a rotation velocity and update the rotation of the object in the main loop, not in the keypress event.
Gonosz
Posts: 24
Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)

Post by Gonosz »

... and you should get the elapsed time since the last frame and multiply the velocity with it, and then add it to the position or whatever you're changing. This way your object won't move faster on better machines.
MG

Post by MG »

Already am it solved. In OnEvent is only
if(event.KeyInput.Key == KEY_KEY_W) rot_left=true;

and in mail loop is procedure updatescene(), in which is getRotation();

Thanks
Post Reply