hi i was trying to play with the movement example,i removed all the squares and spheres,i included my own animated mesh human character,this character is in ms3d format with 15 frames of animation...my program works as follows,if i move my mouse up or down,the character's left hand will rotate(this works fine),when i press 'w' key i want to play frames 1-10,when i press 's' key i want to play frames 10-15...the last two steps are not working(i mean,the 'w' and 's' key stuffs)....the animation stands still....here's my code
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
#pragma comment(lib, "Irrlicht.lib")
class MyEventReceiver : public IEventReceiver
{
public:
int x,y;
bool mousemoved;
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
if(event.EventType==irr::EET_MOUSE_INPUT_EVENT)
{
if(event.MouseInput.Y!=y)
{
y=event.MouseInput.Y;
mousemoved=true;
}
}
return false;
}
virtual int isMouseMoved()
{
if(!mousemoved)
return -1;
else
{
return y;
}
}
virtual void swapflag()
{
mousemoved=false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
int main()
{
// let user select driver type
video::E_DRIVER_TYPE driverType = EDT_OPENGL;
// create device
MyEventReceiver receiver;
IrrlichtDevice* device = createDevice( driverType, core::dimension2d<s32>(640, 480),
16, false, false, false, &receiver);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::IAnimatedMeshSceneNode* node=smgr->addAnimatedMeshSceneNode(smgr->getMesh("human.ms3d"));
//IAnimatedMeshSceneNode* node2=smgr->addAnimatedMeshSceneNode(smgr->getMesh("human.ms3d"));
//node2->setParent(node);
//node2->setPosition(vector3df(20,0,0));
node->setMaterialFlag(video::EMF_LIGHTING, false);
//node2->setMaterialFlag(video::EMF_LIGHTING, false);
node->setPosition(vector3df(0,0,0));
//node2->setJointMode(EJUOR_CONTROL);
//node->animateJoints(true);
node->setJointMode(EJUOR_CONTROL);
IBoneSceneNode *rshoulder=node->getJointNode("r_shoulder");
/*
To be able to look at and move around in this scene, we create a first
person shooter style camera and make the mouse cursor invisible.
*/
scene::ICameraSceneNode * cam = smgr->addCameraSceneNode(0, vector3df(-300,40,50),vector3df(0,0,0),0);
device->getCursorControl()->setVisible(false);
/*
Add a colorful irrlicht logo
*/
/*
We have done everything, so lets draw it. We also write the current
frames per second and the name of the driver to the caption of the
window.
*/
int lastFPS = -1;
int last=0,current=0,movement=0;
while(device->run())
{
/* Check if key W or key S is being held down, and move the
sphere node up or down respectively.
*/
if(receiver.IsKeyDown(irr::KEY_KEY_W))
{
core::vector3df v = node->getPosition();
v.Z += 0.5f;
node->setPosition(v);
node->setLoopMode(true);
node->setAnimationSpeed(15);
node->setFrameLoop(1,10);
node->animateJoints(true);
printf("w frame:%d\n",node->getFrameNr());
//node2->animateJoints(true);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_S))
{
core::vector3df v = node->getPosition();
v.Z -= 0.5f;
node->setPosition(v);
node->setLoopMode(true);
node->setAnimationSpeed(15);
node->setFrameLoop(10,15);
node->animateJoints(true);
printf("s frame:%d\n",node->getFrameNr());
}
else if(receiver.IsKeyDown(irr::KEY_KEY_A))
{
core::vector3df v = node->getPosition();
v.X -= 0.5f;
node->setPosition(v);
}
else if(receiver.IsKeyDown(irr::KEY_KEY_D))
{
core::vector3df v = node->getPosition();
v.X += 0.5f;
node->setPosition(v);
}
if(receiver.isMouseMoved()!=-1)
{int i;
//node->setCurrentFrame(node->getFrameNr());
//node->setRenderFromIdentity(true);
node->setDebugDataVisible(4);
current=receiver.isMouseMoved();
receiver.swapflag();
if(last<current)
{
for(int i=current;i>last&&movement<90;i--)
movement++;i=-1;
}
else
{
for(int i=current;i<last&&movement>-90;i++)
movement--;i=1;
}
matrix4 m;
m.setRotationDegrees(rshoulder->getRotation());
matrix4 n;
n.setRotationDegrees(vector3df(i,0,0));
m*=n;
rshoulder->setRotation(m.getRotationDegrees());
//rshoulder->setRotation(vector3df(movement,0,0));
last=current;
}
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw tmp(L"Movement Example - Irrlicht Engine [");
tmp += driver->getName();
tmp += L"] fps: ";
tmp += fps;
device->setWindowCaption(tmp.c_str());
lastFPS = fps;
}
}
/*
In the end, delete the Irrlicht device.
*/
device->drop();
return 0;
}
inside the while loop,
in the part handling 'w' key,the animation shows just the frame 1
in the part handling 's' key,the animation shows just the frame 10
the rest is working fine,
please do help me....
this is just a test application before i begin anything big....
[the code works when i remove the set frame loop,but it plays all the 15 frames together.i want it to play only the selected frames.further the printf statement in the while loop returns really huge negative numbers when the program works without the setframeloop]