help for fps

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
prajay.shetty
Posts: 14
Joined: Tue Jun 05, 2007 8:04 am
Location: INDIA,MAHARASHTRA

help for fps

Post by prajay.shetty »

Hello guys plzz help me out in correcting the code



Code: Select all


//I AM NEW TO THE GAME PROGRAMMING LANGUAGE I KNOW TURBO C++ BUT I DONT KNOW ANY GAME PROGRAMMING LANGUAGE

//PLZZ LET THE OBJECT BE SYDNEY.MD2 OR ANY BUILT IN OBJECT THAT COMES WITH IRRLICHT GAME ENGINE I DONT HAVE ANY DOWNLOADED OBJECT

//PLZ HELP THE NEW BIES IT WONT BE A TOUGH JOB FOR YOU GUYS I WOULD BE VERY THANKS TO U

//USE OF MASTEVENT RECEIVER CLASS OR YOUR OWN ANY CLASS IS APPRECIATED

//SUGGESTION ARE APPRECIATED

// THANKS A LOT IN ADVANCE

// I AM VERY WEAK IN THIS RECEIVER CLASS PLZZZ HELP OUT

#include <iostream.h>


#include "Irrlicht.h"

using namespace irr;

using namespace core;

using namespace gui;

using namespace video;

using namespace scene;

using namespace io;

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


ISceneNode *node = 0;

IrrlichtDevice *device = 0;

// some change required here problem in this class require "W" to move forward and "S" to move backwarnd and "A" to move right and "D" to move left

class MyReceiver:public IEventReceiver
{
public: virtual bool OnEvent(SEvent event)	
		
		{ 

           if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			   event.KeyInput.PressedDown)
		   {
               
			   switch(event.KeyInput.Key)
			   {
			   case KEY_KEY_S:
				   {
				    
					   core::vector3df v = node->getPosition();				
			           v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;				
			           node->setPosition(v);
                      
					   
				         
				   }
                   
			      return true;
			   case KEY_KEY_W:

			   {
                       core::vector3df v = node->getPosition();				
			           v.X += event.KeyInput.Key == KEY_KEY_S ? -2.0f : 2.0f;				
			           node->setPosition(v);
                       
   				       break;
			   }
                 return true;
			  
			   
			   case KEY_KEY_A:
				   {
				   
				   //code required here to move LEFT

				   }
			   
			   case KEY_KEY_D:

			   {
				   //CODE  REQUIRED TO MOVE SYDNEY.MD2 RIGHT
			   }
		   return false;
		   }

		   }
		}
	


		};


 int main()
 
{
	 
	 class MyReceiver receiver;

	 IrrlichtDevice  *device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<s32>(640,480),16,false,false,false,&receiver);

	 video::IVideoDriver* driver  =  device->getVideoDriver();
	 
	 scene::ISceneManager* smgr = device->getSceneManager();

	 gui::IGUIEnvironment* guienv = device->getGUIEnvironment();

	 // load map

	 device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");


     scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");

	 ISceneNode *node = 0;

	 if(mesh)
	 {
		 node= smgr->addOctTreeSceneNode(mesh->getMesh(0));
	 }

	 if(node)
//I AM NEW TO THE GAME PROGRAMMING LANGUAGE I KNOW TURBO C++ BUT I DONT KNOW ANY GAME PROGRAMMING LANGUAGE

//PLZZ LET THE OBJECT BE SYDNEY.MD2 OR ANY BUILT IN OBJECT THAT COMES WITH IRRLICHT GAME ENGINE I DONT HAVE ANY DOWNLOADED OBJECT

//PLZ HELP THE NEW BIES IT WONT BE A TOUGH JOB FOR YOU GUYS I WOULD BE VERY THANKS TO U

//USE OF MASTEVENT RECEIVER CLASS OR YOUR OWN ANY CLASS IS APPRECIATED

//SUGGESTION ARE APPRECIATED

// THANKS A LOT IN ADVANCE

// I AM VERY WEAK IN THIS RECEIVER CLASS PLZZZ HELP OUT

#include <iostream.h>


#include "Irrlicht.h"

using namespace irr;

using namespace core;

using namespace gui;

using namespace video;

using namespace scene;

using namespace io;

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


ISceneNode *node = 0;

IrrlichtDevice *device = 0;

// some change required here problem in this class require "W" to move forward and "S" to move backwarnd and "A" to move right and "D" to move left

class MyReceiver:public IEventReceiver
{
public: virtual bool OnEvent(SEvent event)	
		
		{ 

           if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
			   event.KeyInput.PressedDown)
		   {
               
			   switch(event.KeyInput.Key)
			   {
			   case KEY_KEY_S:
				   {
				    
					   core::vector3df v = node->getPosition();				
			           v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;				
			           node->setPosition(v);
                      
					   
				         
				   }
                   
			      return true;
			   case KEY_KEY_W:

			   {
                       core::vector3df v = node->getPosition();				
			           v.X += event.KeyInput.Key == KEY_KEY_S ? -2.0f : 2.0f;				
			           node->setPosition(v);
                       
   				       break;
			   }
                 return true;
			  
			   
			   case KEY_KEY_A:
				   {
				   
				   //code required here to move LEFT

				   }
			   
			   case KEY_KEY_D:

			   {
				   //CODE  REQUIRED TO MOVE SYDNEY.MD2 RIGHT
			   }
		   return false;
		   }

		   }
		}
	


		};


 int main()
 
{
	 
	 class MyReceiver receiver;

	 IrrlichtDevice  *device = createDevice(video::EDT_DIRECT3D9,core::dimension2d<s32>(640,480),16,false,false,false,&receiver);

	 video::IVideoDriver* driver  =  device->getVideoDriver();
	 
	 scene::ISceneManager* smgr = device->getSceneManager();

	 gui::IGUIEnvironment* guienv = device->getGUIEnvironment();

	 // load map

	 device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");


     scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");

	 ISceneNode *node = 0;

	 if(mesh)
	 {
		 node= smgr->addOctTreeSceneNode(mesh->getMesh(0));
	 }

	 if(node)
	 {
         node->setPosition(core::vector3df(-1300,-144,-1249));
	 }

	 //loadobjects

	 
      scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(	
		  
		  
	smgr->getMesh("../../media/sydney.md2"));

    // GOT PROBLEM IN IF LOOP PLZZZZZ HELP
if (anms)	
{
	   
	   
       anms->setAnimationSpeed(30);   
	   
	   anms->setRotation(core::vector3df(0,180.0f,0));   
	   
	   anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}


     smgr->addCameraSceneNodeFPS(0, 1);
	 
	 device->getCursorControl()->setVisible(false); 



	while(device->run())
		
	
		
		{
              
               driver->beginScene(true, true, video::SColor(255,90,90,156));
               
			   smgr->drawAll();
              
			   driver->endScene();
        }
		
		
			
return 0;
			

			
 }			
			
			
		
//AT THE LAST AGAIN THANKS FOR ANY HELP GIVERN


	 {
         node->setPosition(core::vector3df(-1300,-144,-1249));
	 }

	 //loadobjects

	 
scene::IAnimatedMeshSceneNode* ansmgr>addAnimatedMeshSceneNode(	
		  
		  
	smgr->getMesh("../../media/sydney.md2"));

    // GOT PROBLEM IN IF LOOP PLZZZZZ HELP
if (anms)	
{
	   
	   
       anms->setAnimationSpeed(30);   
	   
	   anms->setRotation(core::vector3df(0,180.0f,0));   
	   
	   anms->setMaterialTexture(0, driver->getText("../../media/sydney.bmp"));
}


     smgr->addCameraSceneNodeFPS(0, 1);
	 
	 device->getCursorControl()->setVisible(false); 



	while(device->run())
		
	
		
		{
              
               driver->beginScene(true, true, video::SColor(255,90,90,156));
               
			   smgr->drawAll();
              
			   driver->endScene();
        }
		
		
			
return 0;
			

			
 }			
			
			
		
//AT THE LAST AGAIN THANKS FOR ANY HELP GIVERN

plzz explain me some thing about event reciver class  i dont understand even after reading 4th tuitorial

what are the following lines for

core::vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;

plz explain me about that a bit and about this lines especially that 2.0f and v.x 


and following lines in main and tell me how to connect and initialize that node

if (anms)	
{
	   
	   
       anms->setAnimationSpeed(30);   
	   
	   anms->setRotation(core::vector3df(0,180.0f,0));   
	   
	   anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}


     smgr->addCameraSceneNodeFPS(0, 1);
	 
	 device->getCursorControl()->setVisible(false); 

And again in advance thanks a lot for any help granted



prajay.shetty
Posts: 14
Joined: Tue Jun 05, 2007 8:04 am
Location: INDIA,MAHARASHTRA

info

Post by prajay.shetty »

plzz tell me something about evenreciver and those nodes
spooky_paul
Posts: 16
Joined: Sun Nov 26, 2006 5:12 pm
Location: Romania

Post by spooky_paul »

when you are creating a piece of software you realize that you spend more on debugging the code than actually writing it. the best thing that you can do now is to learn proper debugging. posting an industrial-sized code snippet and asking other people to do your work wont get you anywhere.
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

spooky_paul wrote:an industrial-sized code snippet.
I actually don't think that is very large. I have many c++ files that are 500 lines or more.. they get somewhat hard to navigate, though.

That being said I agree his snippet is long enough no one will bother to read it.

I do like the teminology, though XD
spooky_paul
Posts: 16
Joined: Sun Nov 26, 2006 5:12 pm
Location: Romania

Post by spooky_paul »

thanks, but all i was trying to do is to point him in the right direction :)
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

v.X += event.KeyInput.Key == KEY_KEY_W ? -2.0f : 2.0f;

plz explain me about that a bit and about this lines especially that 2.0f and v.x
it's called a "ternary if" or "conditional operator", it allows an if statement as an expression. use it like this:
condition ? result_if_condition_is_true : result_if_condition_is_false

for example, in english:
increase x by ( -1 if c is true, or +1 if c is false )

in c:

Code: Select all

x += (c == true) ? -1 : 1;
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
GameDude
Posts: 498
Joined: Thu May 24, 2007 12:24 am

Post by GameDude »

Dosen't negative move it left and positive move it right?
Post Reply