Save camera position and reload later (save/load)

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
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Save camera position and reload later (save/load)

Post by ibax »

Hi

I would like to save my camera position with all the related info, and reload it later, as a simple save/load function in games.
For example, if my character (camera) is under a tree, watching a car (camera position, angle, focus, etc...), this info is stored somehow/somewhere and later reloaded (somehow).

What is the best solution in irrlicht for this?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Save camera position and reload later (save/load)

Post by CuteAlien »

Use serializeAttributes to write in an IAttributes structure. IAttributes has a read/write functions for XML. Unfortunately there doesn't seem to be an example for that yet in Irrlicht examples. But if you take a look in CSceneManager.cpp you can see how it's used.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Save camera position and reload later (save/load)

Post by christianclavet »

Hi, Can this IAttributes serialization structure be used to write binary files? Thanks for the info to look into CSceneManager!
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Save camera position and reload later (save/load)

Post by CuteAlien »

You could probably write a binary writer for it, but it's not guaranteed to work in the long run. Because we might change the order of attributes (as in xml the order does not matter) and are not saving version numbers, so that could be hard to find out.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Save camera position and reload later (save/load)

Post by ibax »

Hi.
I'm just trying to use the easiest way, camera->getTarget and camera->setTarget, because this is the most important for me...
unfortunately does not working :(
isn't it enough?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Save camera position and reload later (save/load)

Post by CuteAlien »

You will at least also need the position.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Re: Save camera position and reload later (save/load)

Post by kornwaretm »

this is not a good way, but you can brutally write in a file using

Code: Select all

 
// documentation available
IFileSystem * filesystem = device->getFileSystem ();
IWriteFile* writer = filesystem->createAndWriteFile("my_save.sav", false); 
writer->write("posx,",4); 
....
 
just put attributes you need to write and separate them using special token like space or coma (,) as long as the writing sequence are consistent reading the file back will not hard.

also please do check what cuteAlien suggested. and one more thing ISceneManager class has this saveScene() function, not sure if it saves cameras. never use it before.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: Save camera position and reload later (save/load)

Post by christianclavet »

Thanks. I'll look into this. I've never done a binary data saver before, this will be helpful...
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Save camera position and reload later (save/load)

Post by ibax »

hi,

my problem is a bit different, so I decided to show you a real example...

https://youtu.be/cMPfwCuIeeY

on the youtube video, you can see, that when I click a specified button (in this case it is 'F'), a message window appears with an object... I close this window by clicking on the top-right 'man-exiting-house' icon, so "I move the mouse pointer to that icon".
and the problem appears here: the window closes, but my original mouse pointer in the scene (a red-blue figure) also repeats this movement, so there is an unwanted behaviour.

I don't know, why the mouse movement also appears in the background, which is my scene itself... Please help...
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Save camera position and reload later (save/load)

Post by thanhle »

Hi,
I think it is a bug on how you process the events.
It looks to me that you saved the coordinate of the mouse when the dialog appear. Then on click on the door icon on the dialog the new mouse position is saved.
I think somehow the change in the positions between the mouse coordinates causes this rotation.
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Save camera position and reload later (save/load)

Post by ibax »

thanhle wrote:It looks to me that you saved the coordinate of the mouse when the dialog appear. Then on click on the door icon on the dialog the new mouse position is saved.
No, I do nothing with the mouse coordinates. Just simply put an image when clicking the 'F' key, drawing buttons, text, etc. When clicking on Exit, I drop the gui image, so I would like to continue my game, when I stopped earlier...
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Save camera position and reload later (save/load)

Post by thanhle »

So do you switch between fps camera by first disable fps camera when you show the image, then enable fps camera when you close the image?
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Save camera position and reload later (save/load)

Post by ibax »

thanhle wrote:So do you switch between fps camera by first disable fps camera when you show the image, then enable fps camera when you close the image?
Yes...
ibax
Posts: 193
Joined: Thu Jun 21, 2007 8:56 am
Location: hungary
Contact:

Re: Save camera position and reload later (save/load)

Post by ibax »

I think this is the relevant code part, but this should work...

Code: Select all

device->getCursorControl()->setVisible(true);
ICameraSceneNode* camera = device->getSceneManager()->getActiveCamera ();
if ( camera )
    camera->setInputReceiverEnabled ( !camera->isInputReceiverEnabled() );
When I click on the 'F' button, I am 'freezing' the scene, I show up a GUI window with buttons, and when I close this window ( id = 100 ), I 'unfreeze' the scene to continue...

Code: Select all

device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(100, true)->remove();
camera->setInputReceiverEnabled ( !camera->isInputReceiverEnabled() );
device->getCursorControl()->setVisible(false);
Post Reply