Moving model

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
Guest

Moving model

Post by Guest »

I would like it to run when I move the "model" but when it does nothing, i would like to have the "stand up" animation How can i do that ?

Sam
hearsedriver
Posts: 81
Joined: Fri Aug 22, 2003 12:06 pm
Location: Germany
Contact:

Post by hearsedriver »

Simply use the setMD2Animation method for your MD2 scenenode with the EMAT_STAND enum as parameter for the standing animation, or EMAT_RUN for the running animation.

Cheers.
matthias gall, lead programmer at sechsta sinn - email matthias@sechsta-sinn.de
Guest

Post by Guest »

I added this piece of code :

scene::ISceneNode* noeud_perso = 0;


class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{

if (noeud_perso != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = noeud_perso->getRotation();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 20.0f : -20.0f;

noeud_perso->setRotation(v);
}

return true;


}
}


if (camera)
return camera->OnEvent(event);

return false;
}
};

But this don't affect the rotation of my model in this code :

scene::IAnimatedMeshSceneNode* noeud_perso = 0;
material.Texture1 = driver->getTexture("../../media/sydney.bmp");
material.Lighting = true;

scene::IAnimatedMesh* personnage2 = smgr->getMesh("../../media/sydney.md2");
if (personnage2)
{
noeud_perso = smgr->addAnimatedMeshSceneNode(personnage2);
noeud_perso->setPosition(core::vector3df(-40,-10,0));
noeud_perso->setAnimationSpeed(1);
noeud_perso->setMD2Animation(scene::EMAT_STAND);
noeud_perso->getMaterial(0) = material;
}

Have you got an solution ?

Sam.
hearsedriver
Posts: 81
Joined: Fri Aug 22, 2003 12:06 pm
Location: Germany
Contact:

Post by hearsedriver »

It worked for me perfectly. Note that due to the !event.KeyInput.PressedDown condition in the code, the rotation code is only executed when you RELEASE the W/S keys. Maybe that's the "problem"?

Cheers.
matthias gall, lead programmer at sechsta sinn - email matthias@sechsta-sinn.de
cyberbobjr
Posts: 64
Joined: Mon Sep 08, 2003 8:21 am
Location: Paris, France

Post by cyberbobjr »

In the case you want to keep keyboard down during moving, use this condition instead :

Code: Select all

if (node != 0 && event.EventType == EET_KEY_INPUT_EVENT)
Guest

Post by Guest »

I remove this code : !event.KeyInput.PressedDown
Always the same problem. Impossible to move the model.
hearsedriver
Posts: 81
Joined: Fri Aug 22, 2003 12:06 pm
Location: Germany
Contact:

Post by hearsedriver »

Err ... I guess this was some kind of misunderstanding. The code you showed in your first post obviously does, what I told you (?) about object rotation in another thread - it rotates the model around the Y axis. Rotation is not translation. To translate your object, simply add a vector to the node position, where direction and length of the vector define the change of the position.

Cheers.
matthias gall, lead programmer at sechsta sinn - email matthias@sechsta-sinn.de
Guest

Post by Guest »

But you re right ! :)

If i can move the model, i can rotate it.
The problem is : I can not rotate or move with the keyboard my model.
Guest

Post by Guest »

This is my solution :

scene::IAnimatedMeshSceneNode* model2 = 0;


public:
virtual bool OnEvent(SEvent event)
{

if (model2 != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT )
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
core::vector3df v = model2->getRotation();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 20.0f : -20.0f;

model2->setRotation(v);
}

return true;


}
}


if (camera)
return camera->OnEvent(event);

return false;
}
};


/////////////////////////

scene::IAnimatedMesh* mesh = 0;
mesh = smgr->getMesh("../../media/sydney.md2");
if (mesh)
{
model2 = smgr->addAnimatedMeshSceneNode(mesh);
if (model2)
{
model2->setPosition(core::vector3df(-70,-15,-60));
model2->setScale(core::vector3df(2,2,2));
model2->setMD2Animation(scene::EMAT_STAND);
model2->setAnimationSpeed(20);
model2->setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/sydney.bmp"));
model2->setMaterialFlag(video::EMF_LIGHTING, true);
model2->addShadowVolumeSceneNode();
}
}

/////////////////////////////
Post Reply