Switching scene???

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
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Switching scene???

Post by natol »

Okay here's the question.

How do I go from the User Interface like screen to the game screen such as the movement one.

do I have to erase or hide the objects and then redraw the scene with new ones....

what I mean is when I press let say a "play" button it takes the screen from the user interface to a loading bar then the scene for the game.
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

This may help
http://www.skyesurfer.net/keless/IrrLicht/ICE/

Or you can have multiple cameras. One FPS and another that you could use to render your interface (could even be a 3D interface then)
Then setActiveCamera between them. I do that so I can roam in my world then when I press CTRL I can use the onscreen GUI to press buttons;)
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Check the Techdemo example source for a way to do this.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

thank you...

I will try this as soon as I can and let you know....
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

okay I like the idea of the multiple cameras.

Just wondering on when you switch them how do you define what goes on one camera and the other would you use an if statement...

if (camera1)
{
camera1objects
}

or would you use a case statement????
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

Ok what I'm trying to do is get it to where when I press the I key it will switch to the GUI Scene....
if (event.EventType == EET_KEY_INPUT_EVENT )
{


switch(event.EventType)
{
case KEY_KEY_I:
was wondering if this is the way to start the code???
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

Hold on to your but, heres my source :)
(g_ID is a global pointer to an IrrLichtDevice class, im lazy)
g_ID->GUIMode is a bool to store the current state

Code: Select all

The function to switch from FPS to GUI camera (has a "flickering" bug)
void setGUIMode(bool mode)
{
	if(mode)
	{
		if(!g_ID->GUIMode)
		{
			g_ID->GUICamera->setTarget(g_ID->Camera->getTarget());
			g_ID->GUICamera->setPosition(g_ID->Camera->getPosition());

		//	FIXME: Its flickering
			g_ID->Smgr->setActiveCamera(g_ID->GUICamera);

			g_ID->Device->getCursorControl()->setVisible(true);
		}
	}
	else if(g_ID->GUIMode)
	{
		g_ID->Camera->setPosition(g_ID->GUICamera->getPosition());

		g_ID->Smgr->setActiveCamera(g_ID->Camera);

		g_ID->Device->getCursorControl()->setVisible(false);
	}

	g_ID->GUIMode = mode;	//	New mode set
}
then in my even reciever:

Code: Select all

		if(event.EventType == irr::EET_KEY_INPUT_EVENT)
		{
			if(!event.KeyInput.PressedDown)
			{
				switch(event.KeyInput.Key)
				{
					case KEY_ESCAPE:
					{
						dropDevice();	//	HACK: I want recv to be in "IrrLichtDevice"
						return true;
					}
					case KEY_CONTROL:
					{
						setGUIMode(false);
						return true;
					}
				}
			}
			else
			{
				switch(event.KeyInput.Key)
				{
					case KEY_CONTROL:
					{
						setGUIMode(true);
						return true;
					}
				}
			}
		}
Anyway, hope this helps :)
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

I am so sorry , I didn't mean to double post....

Thanks for the code ...

I will try it out and you

I just needed some help with the event receiver....
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

natol wrote:I am so sorry , I didn't mean to double post....
I wouldnt worry too much, I dont think you can edit posts in this forum. My best is 3 in a row and no-one hit me :D

This is code from an early IrrLicht test project so you may need to fix some bits but I think its about what you asked for. (ignore the comments, mad ramblings)

Happy coding.
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

Ok since I am starting to feel like a major newb....

when I go and try to use this part of the code:::

void setGUIMode(bool mode)
{
if(mode)
{
if(!g_ID->GUIMode)
{
g_ID->GUICamera->setTarget(g_ID->Camera->getTarget());
g_ID->GUICamera->setPosition(g_ID->Camera->getPosition());

// FIXME: Its flickering
g_ID->Smgr->setActiveCamera(g_ID->GUICamera);

g_ID->Device->getCursorControl()->setVisible(true);
}
}
else if(g_ID->GUIMode)
{
g_ID->Camera->setPosition(g_ID->GUICamera->getPosition());

g_ID->Smgr->setActiveCamera(g_ID->Camera);

g_ID->Device->getCursorControl()->setVisible(false);
}

g_ID->GUIMode = mode; // New mode set


I get the g_ID not declared error upon compiling....

maybe I'm not sticking the code in the right places?

Thanks for all the help...
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

Like I said, g_ID is a lazy way for me to store global pointers. Im no coding god. Anyway, use this class too, if you like.
(NOTE: This just rigs-up IrrLicht and stores pointers thats all, it was an experiment)

Code: Select all

class IrrLichtDevice	//	Note the mispelling to avoid clashes
{
public:	
	IrrLichtDevice(EDriverType driveType, dimension2d<s32> resoloution)
	{
		Device	= createDevice(driveType, resoloution, 32, true, false, &EvtRecv);
		Driver	= Device->getVideoDriver();
		Smgr	= Device->getSceneManager();
		GUIEnv	= Device->getGUIEnvironment();

		GUICamera = Smgr->addCameraSceneNode(0);
		GUIMode = false;	//	FIXED: 
//		GUICamera->setFarValue(2000);

	//	Dual WSAD CURSOR camera control (FPS style)
		SKeyMap keyMap[8];
		keyMap[0].Action	= EKA_MOVE_FORWARD;
		keyMap[0].KeyCode	= KEY_UP;
		keyMap[1].Action	= EKA_MOVE_FORWARD;
		keyMap[1].KeyCode	= KEY_KEY_W;

		keyMap[2].Action	= EKA_MOVE_BACKWARD;
		keyMap[2].KeyCode	= KEY_DOWN;
		keyMap[3].Action	= EKA_MOVE_BACKWARD;
		keyMap[3].KeyCode	= KEY_KEY_S;

		keyMap[4].Action	= EKA_STRAFE_LEFT;
		keyMap[4].KeyCode	= KEY_LEFT;
		keyMap[5].Action	= EKA_STRAFE_LEFT;
		keyMap[5].KeyCode	= KEY_KEY_A;

		keyMap[6].Action	= EKA_STRAFE_RIGHT;
		keyMap[6].KeyCode	= KEY_RIGHT;
		keyMap[7].Action	= EKA_STRAFE_RIGHT;
		keyMap[7].KeyCode	= KEY_KEY_D;

	//	Create this one last (for now)
		Camera = Smgr->addCameraSceneNodeFPS(0, 100, 1000, -1, keyMap, 8);
		Camera->setPosition(vector3df(2500,500,2500));

		Camera->setFOV(PI/2.5f);
//		Camera->setFarValue(2000);
	};

	~IrrLichtDevice(void)
	{
		Device->drop();
	};

	IrrlichtDevice		*Device;
	IVideoDriver		*Driver;
	ISceneManager		*Smgr;

//	Not so important?
	ICameraSceneNode	*Camera, *GUICamera;
	MyEventReceiver		EvtRecv;
	IGUIEnvironment		*GUIEnv;

	bool				GUIMode;
};
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

Then in my main():

Code: Select all

	IrrLichtDevice	ID(EDT_DIRECTX9, dimension2d<s32>(800, 600));
	g_ID = &ID;	//	Store global pointer for other functions
Like I said, im no coding god but I hope it helps!
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
Oz
Posts: 81
Joined: Tue Aug 31, 2004 3:34 pm

Post by Oz »

Damn. Look ive posted 3 times in a row again sorry.

But at filescope (not in a function) I put this

IrrLichtDevice *g_ID;

And that is why your getting compilation errors. It was just my class, I hope your following cuz im bonkers. ;)
"When we looked at the relics of the precursors, we saw what heights civilization can attain.
When we looked at their ruins, we marked the danger of that height." -Keeper Annals
(Thief2: The Metal Age)
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

LOL.....

Thanks for the help I will go through all your code and learn from it...

some of the API is a little over my head still....
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

natol wrote:LOL.....

Thanks for the help I will go through all your code and learn from it...

some of the API is a little over my head still....
No, it isn't :). The explanations and the syntax of the API doc is a bit weird though, but once you know how it works you can understand most of it :). And keep on asking if you don't know how something works.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Post Reply