Problems moving camera in program

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
darthneo
Posts: 6
Joined: Mon Jan 01, 2007 6:35 pm
Location: A Box, USA

Problems moving camera in program

Post by darthneo »

Hi everyone,
Okay i am trying to make the camera move when you press W but when it runs as a program it comes up with that microsoft error crap and says it needs to be closed here is a few parts of my code

Code: Select all

class MyEventReceiver : public IEventReceiver
{
      public:	virtual bool OnEvent(SEvent event)	
      {
              if (event.KeyInput.Key) 
               {
                    if(event.KeyInput.Key == KEY_KEY_W)
                    {
                      camera->setPosition(core::vector3df(300,1000,-2100));
                    }
               } 
      }
};
now here is my camera settings:

Code: Select all


	scene::ICameraSceneNode* camera = 
		smgr->addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 0, false);
	camera->setPosition(core::vector3df(300,1000,-2100));
 	scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(30,50,30),
		core::vector3df(0,-1,0), 
		core::vector3df(0,0,0));
	camera->addAnimator(anim);
	anim->drop();
now here is the error i am getting from windows:
example.exe has encountered a problem and needs to close. we are sorry for the inconvenience.
i get that everytime i press W running my program

i have tried changing the code i have tried to repostition my camera and i still get the same thing if i leave it blank i dont get any error (but nothing heppens).

does any one see anything wrong with my code? or any other way i can get the camera to rotate?

--edit--
i forgot to say of course i am using irrlicht engine and Dev C++ compiler
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

First your camera is already a fps cam, so you can define the keymap to response on the "W" key (look at the docu for addCameraSceneNodeFPS for this)...

Second your camera is not global so the camera pointer in your event receiver is probably 0 (NULL) !!!
(I wonder that you don't get an "variable not defined" error while compiling the prog)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Another thing you might want to do is check that the event you are getting is actually a key input event. It might also be useful to check that the key is pressed down or released so you don't do the same thing twice when the key is pressed.

Travis
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Re: Problems moving camera in program

Post by sio2 »

darthneo wrote:Okay i am trying to make the camera move when you press W
This may or may not be of use to you, but here's what I use to specify which keys move my camera in simple demos:

Code: Select all

	SKeyMap keyMapArray[4] = {
		{EKA_MOVE_FORWARD,	KEY_KEY_W},
		{EKA_MOVE_BACKWARD,  KEY_KEY_S},
		{EKA_STRAFE_LEFT,	 KEY_KEY_A},
		{EKA_STRAFE_RIGHT,	KEY_KEY_D},
	};
	smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f, -1, &keyMapArray[0], 4);
Post Reply