stubborn sydney wont stop running!

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
focanafacos
Posts: 8
Joined: Wed Dec 20, 2006 4:20 pm

stubborn sydney wont stop running!

Post by focanafacos »

Hi everyone!!

ok guys I've got a little problem. I was using irrlicht 1.0, and with the code below everything worked fine and sydney stops running if the user doesn't press any of these keys: W, S, A, D.

code:

#include <stdio.h>
#include <irrlicht.h>
#include <math.h>

#define PI 3.1416

using namespace irr;

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

using namespace irr;
int sec =0;
float speed=28.0f;

/////////////////
int A=0;
int Last=0;
//////////////////

scene::IAnimatedMeshSceneNode* syd = 0;
IrrlichtDevice* device = 0;
int dist =70;

bool up = false;
bool down = false;
bool right = false;
bool left = false;
bool idle = false;

class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
up = event.KeyInput.PressedDown;
A=1;
break;

case KEY_KEY_S:
down = event.KeyInput.PressedDown;
A=2;
break;

case KEY_KEY_A:
left = event.KeyInput.PressedDown;
A=3;
break;

case KEY_KEY_D:
right = event.KeyInput.PressedDown;
A=4;
break;
}
return true;
}
return false;
}
};

//game
int main()
{

MyEventReceiver receiver;

// create device
device=createDevice(video::EDT_OPENGL,core::dimension2d<s32>(640, 480), 32,
true, false, false, &receiver);


video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0,core::vector3df(-1300,-144,-1249));

// setup scene
syd = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/sydney.md2"));
syd->setMaterialFlag(video::EMF_LIGHTING,false);
syd->setMaterialTexture(0,driver->getTexture("../../media/sydney.bmp"));
syd->setScale(core::vector3df(1.5,1.5,1.5));
syd->setPosition(core::vector3df(50,-45,50));
syd->setRotation(core::vector3df(0,0,0));
syd->setAnimationSpeed(60);
camera->setPosition(core::vector3df(50,45,-150));

device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
node->setPosition(core::vector3df(-1300,-144,-1249));

scene::ITriangleSelector* selector = selector = smgr->createOctTreeTriangleSelector(
mesh->getMesh(0), node, 128);
node->setTriangleSelector(selector);
selector->drop();

core::aabbox3d<f32> box = syd->getBoundingBox();
core::vector3df radius = box.MaxEdge - box.getCenter();
scene::ISceneNodeAnimator* anim =
smgr->createCollisionResponseAnimator(
selector, syd, radius,
core::vector3df(0,-10,0));

syd->addAnimator(anim);
anim->drop();

device->getCursorControl()->setVisible(false);

ITimer* timer = device->getTimer();

u32 then = timer->getRealTime();
while(device->run())
{
u32 now = timer->getRealTime();

// calculate the elapsed time in seconds
f32 elapsed = (now - then) / 200.f;
then = now;

if (device->isWindowActive())
{
// render the scene
if (driver->beginScene(true, true, video::SColor(0,200,200,200)))
{
smgr->drawAll();
driver->endScene();
}

core::vector3df pos = syd->getPosition();
core::vector3df rot = syd->getRotation();
if (up)
{
f32 roty_rad = (rot.Y * PI / 180); // convert to radians
pos.Z -= (speed * elapsed) * sin(roty_rad);
pos.X += (speed * elapsed) * cos(roty_rad);
if(A!=Last && A==1)
{
syd->setFrameLoop(321,366);
Last=A;
}

}
if (down)
{
speed=10.0f;
f32 roty_rad = (((rot.Y) * PI) / 180); // convert to radians
pos.Z += (speed * elapsed) * sin(roty_rad);
pos.X -= (speed * elapsed) * cos(roty_rad);
if(A!=Last && A==2)
{
syd->setFrameLoop(321,366);
Last=A;
}
speed=28.0f;

}
if (left)
{
rot.Y -= (1.3*speed * elapsed);
if(A!=Last && A==3)
{
syd->setFrameLoop(321,366);
Last=A;
}
}
if (right)
{
rot.Y += (1.3*speed * elapsed);
if(A!=Last && A==4)
{
syd->setFrameLoop(321,366);
Last=A;
}
}
if(!up && !down && !left && !right && A!=0 && Last!=0)
{
syd->setFrameLoop(0,320);
Last=A=0;
}

syd->setPosition(pos);
syd->setRotation(rot);

pos.Y+=50.f;

camera->setTarget(pos);

pos.Y-=37.f;

pos.X -= dist*cos(((rot.Y)*PI)/180);
pos.Z += dist*sin(((rot.Y)*PI)/180);
pos.Y += dist;

camera->setPosition(pos);

}
else
{
// clear keys when window goes out of focus
up = down = left = right = false;
}
}

device->drop();
return 0;
}


Well, I got irrlicht 1.2 and stubborn sydney wont stop running no matter what I do. Could you guys help me??? THNX in advance :D
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

this is a bug which is now fixed in svn.
try changing syd->setFrameLoop(0,320) to syd->setFrameLoop(1,320)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
focanafacos
Posts: 8
Joined: Wed Dec 20, 2006 4:20 pm

Thnx for the help man!

Post by focanafacos »

HEEYY it works!!!! thnks so much Dude :D !!!!
Oh, and also Happy Christmas and happy new year for u and all your relatives :D!
Post Reply