code compiles without error but doesnt do anything

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
master123467
Posts: 60
Joined: Mon Jan 02, 2006 6:03 pm
Contact:

code compiles without error but doesnt do anything

Post by master123467 »

this code down there compiles without error but it doesnt do anything when i press the W key , when i press the W i want it to change the player_node's animation from STAND to RUN

in the "//begin key press" all the way down "//end key press" is the key press code

Code: Select all

#include <irrlicht.h>
#include <iostream>
#include <audiere.h>
#include <stdio.h>
#include <windows.h>
#include "newton.h"

static NewtonWorld* nWorld;
using namespace irr;
using namespace core;
using namespace scene;
using namespace audiere;
using namespace video;
using namespace io;
using namespace gui;
int main()
{
	
//begin	key press
        	class MyEventReceiver : public IEventReceiver
{
public:
	MyEventReceiver(scene::IAnimatedMeshSceneNode* player_node)
	{
		
		Player_node = player_node;
	}

	bool OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT &&
   event.KeyInput.Key == KEY_KEY_W &&
   event.KeyInput.PressedDown == false)
{
    Player_node->setMD2Animation(scene::EMAT_RUN);
}
return false;
}

private:
	scene::IAnimatedMeshSceneNode* Player_node;
};
//end key press
	
    //Init Audiere Audio
    AudioDevicePtr audiereDevice;
    OutputStreamPtr stream;

    audiereDevice = OpenDevice();
    if (!audiereDevice)
     return 1;

    stream = OpenSound(audiereDevice.get(), "data/music/track6.ogg", true);
    if (!stream)
     return 2;

    stream->setRepeat(true);
    stream->setVolume(1.0f); // 50% volume
    stream->play();
    //End Audiere Audio
    
    //Game
    nWorld = NewtonCreate (NULL, NULL);
    IrrlichtDevice *device =
    createDevice(EDT_OPENGL, core::dimension2d<s32>(1024, 768), 32,
     false, false, true, 0);
     
     if (device == 0)
     return 1;
     
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    //Player and Cam Create
	IAnimatedMesh* mesh = smgr->getMesh("data/models/cyborg/player.md2");
	IAnimatedMeshSceneNode* player_node = smgr->addAnimatedMeshSceneNode( mesh );
	if (player_node)
	{
		player_node->setMaterialFlag(EMF_LIGHTING, false);
		player_node->setMD2Animation ( scene::EMAT_STAND);
		player_node->setMaterialTexture( 0, driver->getTexture("data/models/cyborg/player.pcx") );
	}
	scene::ICameraSceneNode * camera;
    camera = smgr->addCameraSceneNode(0, vector3df(-70,50,0), vector3df(0,0,0));
    //End PLayer and Cam Create
    //wep
    mesh = smgr->getMesh("data/weapons/cyborg/w_bfg.md2");
     IAnimatedMeshSceneNode * gun_node = smgr->addAnimatedMeshSceneNode(mesh);
     if(gun_node)
     {
          gun_node->setParent(player_node);
          gun_node->setMD2Animation ( scene::EMAT_STAND);
          gun_node->setPosition(core::vector3df(0,-4,-2));
    //end wep      
    // map
        device->getFileSystem()->addZipFileArchive("data/maps/maps.pk3");

    
    scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
    scene::ISceneNode* q3node = 0;
    if (q3levelmesh)
    q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));smgr->addOctTreeSceneNode(smgr->getMesh("20kdm2.bsp"));
        scene::ITriangleSelector* selector = 0;
   
    if (q3node)
    {   
      q3node->setPosition(core::vector3df(-1370,-130,-1400));
      selector = smgr->createOctTreeTriangleSelector(q3levelmesh->getMesh(0), q3node, 128);
      q3node->setTriangleSelector(selector);
      selector->drop();
    }      
    //end map
                
    //Irrlicht Logo
    guienv->addImage(driver->getTexture("irrQUAKE.png"),
    core::position2d<s32>(5,5));
    //Irrlicht Logo End  
    
    int lastFPS = -1;
	while(device->run())
	if (device->isWindowActive())
	{
                        camera->setTarget(player_node->getPosition());
                        camera->updateAbsolutePosition();
 		driver->beginScene(true, true, SColor(255,100,101,140));

		smgr->drawAll();
		guienv->drawAll();
		driver->endScene();
		
				int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			core::stringw str = L"irrQuake: Quake irrlicht style [ FPS:";
			str += fps;
			str += "]";

			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
	}
	device->drop();

	return 0;
    }
}    
// End Game
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You are in _way_ over your head. You should really try to learn C/C++ with something more simple than a rendering engine. If you absolutely insist on failing miserably then...

1. You need to instantiate your event receiver.
2. You need to tell the Irrlicht device send events to your receiver.

Also, it might be a good idea to move the MyEventReceiver declaration outside of the main function. It is legal C++, but local classes are a rarely used feature of the language.

Travis
master123467
Posts: 60
Joined: Mon Jan 02, 2006 6:03 pm
Contact:

Post by master123467 »

look dont tell me to learn c++ yes i will learn it but dont say im way in over my head if u dont no what your talking about
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

He does know what he is talking about master. And you really need to take our advice and just learn C++. Just visit some websites even (http://www.cprogramming.com/tutorial.html) or get a C++ for dummies book, anything that will teach you the basics.

Would you want to go out and build a house just because you have a hammer and a few nails? Just because you can, dosen't mean you should.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Would you want to go out and build a house just because you have a hammer and a few nails? Just because you can, dosen't mean you should.
Exactly. Figure out how to use the hammer without smashing your thumb first.
master123467
Posts: 60
Joined: Mon Jan 02, 2006 6:03 pm
Contact:

Post by master123467 »

when i said he doesnt no what hes talking about i meant he doesnt no what all i no i no c
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Maybe you know C but this is C++ and it seems you don't know any about class handling...

You can define as many classes as you want to, but if you don't create any instances of them they are preatty useless !!!

Your problem is elementary and covert with example #02, #05, #06 and many others of the examples !!!
The examples are verry well documented and you should work through them first !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply