Save camera position and reload later (save/load)
Save camera position and reload later (save/load)
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?
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?
Re: Save camera position and reload later (save/load)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Re: Save camera position and reload later (save/load)
Hi, Can this IAttributes serialization structure be used to write binary files? Thanks for the info to look into CSceneManager!
Re: Save camera position and reload later (save/load)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Save camera position and reload later (save/load)
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?
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?
Re: Save camera position and reload later (save/load)
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
-
- Competition winner
- Posts: 189
- Joined: Tue Oct 16, 2007 3:53 am
- Location: Indonesia
- Contact:
Re: Save camera position and reload later (save/load)
this is not a good way, but you can brutally write in a file using
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.
Code: Select all
// documentation available
IFileSystem * filesystem = device->getFileSystem ();
IWriteFile* writer = filesystem->createAndWriteFile("my_save.sav", false);
writer->write("posx,",4);
....
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.
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
Re: Save camera position and reload later (save/load)
Thanks. I'll look into this. I've never done a binary data saver before, this will be helpful...
Re: Save camera position and reload later (save/load)
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...
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...
Re: Save camera position and reload later (save/load)
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.
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.
Re: Save camera position and reload later (save/load)
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 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.
Re: Save camera position and reload later (save/load)
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?
Re: Save camera position and reload later (save/load)
Yes...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?
Re: Save camera position and reload later (save/load)
I think this is the relevant code part, but this should work...
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->getCursorControl()->setVisible(true);
ICameraSceneNode* camera = device->getSceneManager()->getActiveCamera ();
if ( camera )
camera->setInputReceiverEnabled ( !camera->isInputReceiverEnabled() );
Code: Select all
device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(100, true)->remove();
camera->setInputReceiverEnabled ( !camera->isInputReceiverEnabled() );
device->getCursorControl()->setVisible(false);