Hey, I tried this resource with my code...It compiles fine, but when I press any of the buttons when running, nothing happens - the camera points at the object just fine. It looks like I've done everything the same as you have, but something must be wrong somewhere. I did get 12 warnings though.
I've looked it over, but my C++ and Irrlicht knowledge is quite up to scratch so I didn't see anything wrong with it, if anyone could quickly check over and see what's stopping me from using the input I would be most grateful (Running VC++ 2005 Exp, Irrlicht 1.3)
Code: Select all
/*
This Tutorial shows how to set up the IDE for using the
Irrlicht Engine and how to write a simple HelloWorld
program with it. The program will show how to use the
basics of the VideoDriver, the GUIEnvironment and the
SceneManager.
Microsoft Visual C++ 6.0 and .NET is used as
example IDE, but you will also be able to understand everything
if you are using a different one or even another operating
system than windows.
To use the engine, we will have to include the header file
irrlicht.h, which can be found in the Irrlicht Engine SDK
directory \include.
To let the compiler find this header file, the directory where
it is located should be specified somewhere. This is different
for every IDE and compiler you use. I explain shortly how to
do this in Microsift Visual Studio C++ 6.0 and .NET:
- If you use Version 6.0, select the Menu Extras -> Options.
Select the directories tab, and select the 'Include' Item in the combo box.
Add the \include directory of the irrlicht engine folder to the list of directories.
Now the compiler will find the Irrlicht.h header file. We also
need the irrlicht.lib to be found, so stay
in that dialog, select 'Libraries' in the combo box and add the
\lib\VisualStudio directory.
- If your IDE is Visual Studio .NET, select Tools -> Options.
Select the projects entry and then select VC++ directories.
Select 'show directories for include files' in the combo box, and
add the \include directory of the irrlicht engine folder to the list of directories.
Now the compiler will find the Irrlicht.h header file. We also
need the irrlicht.lib to be found, so stay
in that dialog, select 'show directories for Library files' and add the
\lib\VisualStudio directory.
That's it, with your IDE set up like this, you will now be able to
develop applications with the Irrlicht Engine.
*/
#include <irrlicht.h>
#include <iostream>
/*
In the Irrlicht Engine, everything can be found in the namespace
'irr'. So if you want to use a class of the engine, you have to
write an irr:: before the name of the class. For example to use
the IrrlichtDevice write: irr::IrrlichtDevice. To get rid of the
irr:: in front of the name of every class, we tell the compiler
that we use that namespace from now on, and we will not have to
write that 'irr::'.
*/
using namespace irr;
/*
There are 5 sub namespaces in the Irrlicht Engine. Take a look
at them, you can read a detailed description of them in the
documentation by clicking on the top menu item 'Namespace List'
or using this link: http://irrlicht.sourceforge.net/docu/namespaces.html.
Like the irr Namespace, we do not want these 5 sub namespaces now,
to keep this example simple. Hence we tell the compiler again
that we do not want always to write their names:
*/
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
/*
To be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but
to make it easy, we use a pragma comment lib:
*/
//Set up booleans
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
bool up = false;
bool down = false;
bool right = false;
bool left = false;
int speed =5;
//Make an event Class
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;
break;
case KEY_KEY_S:
down = event.KeyInput.PressedDown;
break;
case KEY_KEY_A:
left = event.KeyInput.PressedDown;
break;
case KEY_KEY_D:
right = event.KeyInput.PressedDown;
break;
}
//return true;
}
return false;
}
};
/*
This is the main method. We can use int main() on every platform.
On Windows platforms, we could also use the WinMain method
if we would want to get rid of the console window, which pops up when
starting a program with main(), but to keep this example simple,
we use main().
*/
int main(int argc, char** argv)
{
//=====================================\\
//
//==========SETUP======================\\
//
//=====================================\\
//Event Class
MyEventReceiver receiver;
//Setup the Irrlicht display device
IrrlichtDevice *device =
createDevice( video::EDT_OPENGL, dimension2d<s32>(1024, 768), 32,
false, false, false, 0);
//This sets the Window Caption
//device->setWindowCaption(L"RPG Engine By Seppuku Arts");
//Setup Devices
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
//=====================================\\
//
//==========LOAD SCENE======================\\
//
//=====================================\\
//setup Fog
driver->setFog(video::SColor(0,138,125,81), true, 250, 1000, 0, true);
// set a nicer font
//ADD TEXT
guienv->addStaticText(L"Stuff...",
rect<int>(10,10,260,62), true);
//==========MAP=========\\
device->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
scene::IAnimatedMesh* Level_Mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* Level_Node = 0;
if (Level_Mesh)
Level_Node = smgr->addOctTreeSceneNode (Level_Mesh->getMesh(0));
if (Level_Node)
Level_Node->setPosition(core::vector3df(-1300,-144,-1249));
//========DWARF MODEL=======\\
//Load the object to a node
IAnimatedMesh* dwarfMesh= smgr->getMesh("media/dwarf.x");
IAnimatedMeshSceneNode* dwarf = smgr->addAnimatedMeshSceneNode( dwarfMesh );
//scene::ISceneNode* node = 0;
//Apply settings to this node - animation, lighting and texture
if (dwarf)
{
//smgr->getMeshManipulator()->makePlanarTextureMapping(
// mesh->getMesh(0), 0.003f);
// video::ITexture* colorMap = driver->getTexture("media/dwarf.jpg");
// video::ITexture* normalMap = driver->getTexture("media/dwarf bump.jpg");
// scene::IMesh* tangentMesh = smgr->getMeshManipulator()->createMeshWithTangents(
// mesh->getMesh(0));
// node= smgr->addMeshSceneNode(tangentMesh);
// node->setMaterialTexture(0, colorMap);
// node->setMaterialTexture(1, normalMap);
// node->getMaterial(0).EmissiveColor.set(0,0,0,0);
// node->setMaterialFlag(video::EMF_FOG_ENABLE, true);
// node->setMaterialType(video::EMT_PARALLAX_MAP_SOLID);
// node->getMaterial(0).MaterialTypeParam = 0.02f; //Adjust height for effect
//drop mesh because we create it was a create call
// tangentMesh->drop();
dwarf->setMaterialFlag(EMF_LIGHTING, false);
dwarf->setMD2Animation ( scene::EMAT_STAND );
dwarf->setMaterialTexture( 0, driver->getTexture("media/dwarf.jpg") );
}
/*
To look at the mesh, we place a camera into 3d space at the position
(0, 30, -40). The camera looks from there to (0,5,0).
*/
//smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
//Setting up a user controlled camera:
//smgr->addCameraSceneNodeFPS();
ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
//Lets hide the mouse Cursor
device->getCursorControl()->setVisible(false);
/*
Ok, now we have set up the scene, lets draw everything:
We run the device in a while() loop, until the device does not
want to run any more. This would be when the user closed the window
or pressed ALT+F4 in windows.
*/
//An Integer for the the frame rate:
int lastFPS = -1;
while(device->run())
{
/*
Anything can be drawn between a beginScene() and an endScene()
call. The beginScene clears the screen with a color and also the
depth buffer if wanted. Then we let the Scene Manager and the
GUI Environment draw their content. With the endScene() call
everything is presented on the screen.
*/
core::vector3df pos = dwarf->getPosition();
core::vector3df rot = dwarf->getRotation();
float diry = ((rot.Y+90)*3.14)/180;
if (up)
{
pos.X += speed * cos((rot.Y) * 3.14/ 180);
pos.Z -= speed * sin((rot.Y) * 3.14/180);
}
if (down)
{
pos.X -= speed * cos((rot.Y) * 3.14/180);
pos.Z += speed * sin((rot.Y) * 3.14/180);
}
if (left)
{
rot.Y -= 0.1;
}
if (right)
{
rot.Y += 0.1;
}
dwarf->setRotation(rot);
int xf = (pos.X-sin(diry)*125);
int yf = (pos.Z-cos(diry)*125);
int zf = 100;
dwarf->setPosition(pos);
camera->setTarget(pos);
pos.Y += 200.f;
pos.Z -= 150.f;
camera->setPosition(vector3df(xf,zf,yf));
//RENDER
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
//Grab frame rate
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Test Demo|";
str += driver->getName();
str += "|Frame Rate = ";
str += fps;
device->setWindowCaption (str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
Cheers.