camera->setTarget problems...

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
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

camera->setTarget problems...

Post by [dx/x]=HUNT3R »

Has anyone else experienced this problem? I've implemented a pause game function and so of course the player needs to be looking at the same target when resuming the game as he was when pausing the game. But my pause game goes to the main menu and the mouse is used in the main menu so it still reads all that mouse input and then updates the game when it goes back to the game and the player is facing a completely different direction. I'm declaring this globally:

Code: Select all

core::vector3df playerTargetWhenPausing(0, 0, 0);
Then I save the position with this:

Code: Select all

playerTargetWhenPausing = camera->getTarget();
And then when returning to the game I restore like this:

Code: Select all

camera->setTarget(playerTargetWhenPausing);
It seems simple enough and should work but it nevers does, sometimes it seems to be returning to a really strange camera position, other times it doesn't seem like it tried to restore the original position...
Sfin
Posts: 13
Joined: Wed Oct 15, 2003 9:13 pm

Post by Sfin »

I don't know how the above code is located in your program, but maybe

Code: Select all

playerTargetWhenPausing = camera->getTarget();


Is becing called after you click the button to pause the game. Maybe if you post how you have this in your even reciever, it will be easier to debug.

Also hve you tried something like this:

Code: Select all

bool NotPaused = true;

class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{ 
         if (event.EventType == irr::EET_KEY_INPUT_EVENT&&
			!event.KeyInput.PressedDown)
         {
		switch(event.KeyInput.Key)
		{
		case KEY_KEY_P:
                    if(NotPaused)
                    {
                         NotPaused = false;
                    }else{
                         NotPaused = true;
                    }                   

	            return true;
		}
        }
         
        if (device->camera && NotPaused)
           return camera->OnEvent(event);
         
        return false;
        }
};


I am not sure if the above the code will work, but I think that is another way of doing pausing.
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

You're right it is called after pressing the ESC button to pause, but that should not matter. It should still get the current target. The pause game works by simply going to the main menu state where my Run_Game() function is not called. Run_Game() currently just calls a smgr-drawAll() so the scene manager is not updated while in the main menu, thereby pausing the game action. But I would think that the getTarget would still get the target and save it and then when the user selects the GUI button to return to the game, it calls setTarget and goes back into the run_game state. I tried adding another smgr->drawAll() after calling getTarget just to update it again but it did not affect anything.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

You could try to do a
camera->setInputReceiverEnabled(false);
when switching to the menu and
camera->setInputReceiverEnabled(true);
when in the game again, maybe this helps.
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

I tried it... strange, but it doesn't work. It sounded like a good idea. :wink:
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

I think I will have to use a flag like Sfin suggested. Just didn't want to have to add in more conditional checking to slow everything down...
[dx/x]=HUNT3R
Posts: 271
Joined: Sat Aug 23, 2003 5:52 pm
Location: Hurricane Central, Florida

Post by [dx/x]=HUNT3R »

Nevermind, I forgot I'm already checking a flag... it's too early in the morning. I have macro defined game states like GAME_RUNNING and MAIN_MENU etc. and it only returns mouse input to the camera when in the GAME_RUNNING state. But it's like it records all mouse input made while in the MAIN_MENU state and plays it all back real quick when it gets back to the GAME_RUNNING state so the player is facing a different direction. I don't understand why the setTarget won't work??? Or why the setInputRecevierEnabled won't work either??? Any other suggestions... anyone?
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Hm.. I think setTarget doesn't work with the FPS camera currently. Or at least, if it does something, it is a little buggy, I think. :roll:
DarkWhoppy
Posts: 386
Joined: Thu Sep 25, 2003 12:43 pm
Contact:

Post by DarkWhoppy »

I've got a ordinary ICameraNode that follows my player around... but the "setTarget(node->getPosition);" is "bumpy". How would I make this 'smooth' so that its target is the model even when moving around?

(instead of posting on a new thread I thought it would be better to ask here)
Post Reply