PDA

View Full Version : OpenGL Undo/Redo



romzxlat
27th March 2015, 10:40
Hello,

I was creating sample application (3D Cad) and I need to add Redo and Undo functionality.

Any tips how to do that?

Thanks

stampede
27th March 2015, 11:01
It depends on your implementation, but typically you can have a data type to represent current "state" of the object (like list of all objects/points on the scene). On each state change (like adding new point, moving or resizing lines etc.) you can append new "state" to the "state list". Undo could simply move back one index in this list and display corresponding state. On redo just move the current index forward etc. Simple to implement, but can require a lot of memory if you would like to work on large scenes.
Another option is to store a some kind of "state change", so instead of storing full list of objects on each change, keep only the "description" of the change applied, like "added point x,y", "moved point p -> q", "deleted point x,y" etc. Now undo could simply apply the inverse of the last "state change" and move one index back in the "state change list". This solution will require to store less data, but can be more complicated to implement.
Sorry for the lack of details, but it really depends on the underlying data structures etc.
Hope this helps.