Thanks Midnight.
I tried adding the "break;" and "else if" as well as the ";" at the end of the else block, but to no avail.
I'll throw in some prints to the console when the distance is hit, but in the meantime, here's the whole thing:
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
#pragma comment(lib, "Irrlicht.lib")
IrrlichtDevice* device = 0;
int main()
{
device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1024, 768),
16, false, false, false);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::IAnimatedMeshX* mesh = (scene::IAnimatedMeshX*)smgr->getMesh("media/Swing.X");
scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
scene::ITriangleSelector* selector = 0;
node->setPosition(core::vector3df(0,0,0));
selector = smgr->createOctTreeTriangleSelector(
mesh->getMesh(0), node, 0);
node->setTriangleSelector(selector);
node->setFrameLoop(0, 50);
selector->drop();
//wasd navigation
SKeyMap keyMap[8];
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;
// add FPS camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0, 40.0f, 40.0f, -1, keyMap, 8);
camera->setPosition(core::vector3df(0,50,-300));
// collision detection
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, camera, core::vector3df(30,50,30),
core::vector3df(0,0,0),
core::vector3df(0,50,0));
camera->addAnimator(anim);
anim->drop();
node->setDebugDataVisible( true);
// disable mouse cursor
device->getCursorControl()->setVisible(false);
// Add a light
smgr->addLightSceneNode(0, core::vector3df(-60,100,-400),
video::SColorf(1.0f,1.0f,1.0f,1.0f),
600.0f);
int lastFPS = -1;
while(device->run())
{
core::vector3df cameraPosition = camera->getPosition();
f32 distance = cameraPosition.getDistanceFrom(node->getPosition());
if (distance < 100.0f)
{
node->setAnimationSpeed(1000);
break;
}
else if (distance > 100.0f)
{
node->setAnimationSpeed(0);
};
camera->updateAbsolutePosition();
node->updateAbsolutePosition();
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
the file I'm loading is just a simple block (with bones, keyframes, etc.) that I'm using as a proxy until I get the real content created. It was created in 3dsMax with 50 frames of animation, used PandaX to export it, opened it in the DXSDK meshViewer, saved it from there as a *.x file, opened it in Irrlichts MeshViewer, and all is well. The animation works fine until I try and control it.
Thanks for having a look. I'll mention anything from the console.
EDIT::::
ok I saw something...the
core::vector3df cameraPosition = camera->getPosition();
f32 distance = cameraPosition.getDistanceFrom(node->getPosition());
lines were not in the while(device->run) bit. That made a difference.
I had it there the other day and it didn't work, now it does, so I'm gonna guess it was the "else if()" that did it.
Now as I aproach the scene node, it does indeed trigger the animation, and it keeps spinning about, and when I back away from that distance, it stops.
Now, how would i get it to do just the 50 frames once and stop?I tried using if(distance = 100.0f)
and
else if(distance != 100.0f)
but the animation is looping from the start and continues