moving vehicle
moving vehicle
I have problem with my vehicle. I load it from 3ds file:
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
IAnimatedMesh* mesh = smgr->getMesh("../../media/truck.3ds");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation ( scene::EMAT_STAND );
}
smgr->addCameraSceneNode(0, vector3df(0,100,-100), vector3df(0,5,0));
scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(true);
But I can't make it move like in tutorial 4 ( using W and S keys). I can compile it but pressing keys does nothing. What should I change in code if my model is loaded as AnimatedMesh, not as ISceneNode
Please help!
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
IAnimatedMesh* mesh = smgr->getMesh("../../media/truck.3ds");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation ( scene::EMAT_STAND );
}
smgr->addCameraSceneNode(0, vector3df(0,100,-100), vector3df(0,5,0));
scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(true);
But I can't make it move like in tutorial 4 ( using W and S keys). I can compile it but pressing keys does nothing. What should I change in code if my model is loaded as AnimatedMesh, not as ISceneNode
Please help!
Here is code. Watch out node and node1:)
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
scene::IAnimatedMesh* mesh = 0;
scene::IAnimatedMeshSceneNode* node1 = 0;
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (node1 != 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 = node1->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node1->setPosition(v);
}
return true;
}
}
return false;
}
};
int main()
{device = createDevice( video::EDT_OPENGL, dimension2d<s32>(1024, 768), 16,false, false, false, 0);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
mesh = smgr->getMesh("../../media/truck.3ds");
scene::IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode( mesh );
node1->setPosition(core::vector3df(0,0,30));
node1->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(true);
int lastFPS = -1;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll();
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;
}
}
device->drop();
return 0;
}
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
scene::IAnimatedMesh* mesh = 0;
scene::IAnimatedMeshSceneNode* node1 = 0;
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (node1 != 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 = node1->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node1->setPosition(v);
}
return true;
}
}
return false;
}
};
int main()
{device = createDevice( video::EDT_OPENGL, dimension2d<s32>(1024, 768), 16,false, false, false, 0);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
mesh = smgr->getMesh("../../media/truck.3ds");
scene::IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode( mesh );
node1->setPosition(core::vector3df(0,0,30));
node1->setMaterialFlag(video::EMF_LIGHTING, false);
scene::ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(true);
int lastFPS = -1;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,113,113,133));
smgr->drawAll(); // draw the 3d scene
device->getGUIEnvironment()->drawAll();
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;
}
}
device->drop();
return 0;
}
You need to declare a MyEventReceiver object and pass it to the device :
Code: Select all
int main() {
MyEventReceiver receiver;
device = createDevice( video::EDT_OPENGL, dimension2d<s32>(1024, 768), 16,false, false, false, &receiver);
...
These line are in my code, so something is still wrong
video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
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::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Burning's Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 0;
}
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.
Ok, i think i've understood. You're declaring 2 IAnimatedMeshSceneNode* node1. The test in the event receiver might be done on the wrong one (i've seen someone that made the same error some time ago). So, in your main, change :
to :
I don't really understand why compilers allow this code to compile, since it looks like a double declaration.
Code: Select all
scene::IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode( mesh );
Code: Select all
node1 = smgr->addAnimatedMeshSceneNode( mesh );
-
- Posts: 14
- Joined: Tue Jun 05, 2007 8:04 am
- Location: INDIA,MAHARASHTRA
plzz help
porky can u help me out i just wanted a simple code to move an object
such as sydney.md2 plzz help
such as sydney.md2 plzz help
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
@prajay.shetty
Have a look at the examples that come with Irrlicht for help about how to move objects. Also search the forums or have a look at my reply to porki's question here
Have a look at the examples that come with Irrlicht for help about how to move objects. Also search the forums or have a look at my reply to porki's question here
Tell me what you cherish most. Give me the pleasure of taking it away.