Movement HELP
Posted: Mon Mar 19, 2007 9:29 pm
Can someone create for me a sample source for player movement(camera follow player) my englisch ist no good and i cant understand tutorial in this site :/ HELP
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
Code: Select all
scenemgr->addCameraSceneNodeFPS();
Code: Select all
scenemgr->addCameraSceneNodeMaya()
Code: Select all
#define RUN_SPEED 10
void Controls::keyDown(int key, bool b)
{
keysDown[key] = b;
}
void Controls::movementUpdate(void)
{
vector3df moveLoc;
vector3df ax1;
vector3df ax2;
if(keysDown[KEY_KEY_W] && keysDown[KEY_KEY_D])
{
ax1 = vector3df(0, 0, 1 * RUN_SPEED);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
ax2 = vector3df(1 * RUN_SPEED, 0, 0);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax2);
moveLoc = vEngine->cam->getAbsolutePosition() + ax1 + ax2;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_W] && keysDown[KEY_KEY_A])
{
ax1 = vector3df(0, 0, 1 * RUN_SPEED);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
ax2 = vector3df(1 * RUN_SPEED, 0, 0);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax2);
moveLoc = vEngine->cam->getAbsolutePosition() + ax1 - ax2;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_S] && keysDown[KEY_KEY_D])
{
ax1 = vector3df(0, 0, 1 * RUN_SPEED);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
ax2 = vector3df(1 * RUN_SPEED, 0, 0);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax2);
moveLoc = vEngine->cam->getAbsolutePosition() - ax1 + ax2;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_S] && keysDown[KEY_KEY_A])
{
ax1 = vector3df(0, 0, 1 * RUN_SPEED);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
ax2 = vector3df(1 * RUN_SPEED, 0, 0);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax2);
moveLoc = vEngine->cam->getAbsolutePosition() - ax1 - ax2;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_W] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_S])
{
ax1 = vector3df(0, 0, 1 * RUN_SPEED);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
moveLoc += vEngine->cam->getAbsolutePosition() + ax1;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_W])
{
ax1 = vector3df(0, 0, 1 * RUN_SPEED);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
moveLoc += vEngine->cam->getAbsolutePosition() - ax1;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_W])
{
ax1 = vector3df(1 * RUN_SPEED, 0, 0);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
moveLoc += vEngine->cam->getAbsolutePosition() + ax1;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_D] && !keysDown[KEY_KEY_W])
{
ax1 = vector3df(1 * RUN_SPEED, 0, 0);
vEngine->cam->getAbsoluteTransformation().rotateVect(ax1);
moveLoc += vEngine->cam->getAbsolutePosition() - ax1;
moveLoc.Y = vEngine->cam->getAbsolutePosition().Y;
}
if(!keysDown[KEY_KEY_W] && !keysDown[KEY_KEY_S] && !keysDown[KEY_KEY_A] && !keysDown[KEY_KEY_D])
{
moveLoc = vEngine->cam->getAbsolutePosition();
}
vEngine->cam->setPosition(moveLoc);
}
bool Controls::OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT)
{
//Keyboard events here
if(event.KeyInput.PressedDown)
{
keyDown(event.KeyInput.Key, true);
movementUpdate();
}
else
{
for(int i = 0; i < 256; i++)
keyDown(i, false);
}
}
return true;
}
Code: Select all
#include <stdio.h>
#include <wchar.h>
#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
createDevice(EDT_SOFTWARE, dimension2d<s32>(600, 600), 16,
false, false, false, 0);
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",
rect<int>(10,30,200,44), true);
IAnimatedMesh* cam = smgr->getMesh("media/tris.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( cam );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setFrameLoop(0, 310);
node->setMaterialTexture( 0, driver->getTexture("media/alien.pcx") );
}
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll(); driver->endScene();
}
device->drop(); return 0;
}
Code: Select all
device->setEventReceiver();