Reputation: 123
I am developing an android app which distort the image.I am using opengl translate and scale function to distort the image.The image is distorting fine.Now I want to implement undo feature.But unable to implement the functionality.Any one can help how to implement undo functionality in opengl .Any suggestion or code will be helpful. Thanks in advance .
Upvotes: 5
Views: 471
Reputation: 38300
I suspect that the command pattern is not enough for your situation. This is based on my assumption that is is not easy to reverse the image distortion even when you know what distortion was applied.
Instead, you will probably need to push the image onto the stack just before applying the distortion. Then, the undo implementation will replace the current image with the image on the stack. This will lead to potentially interesting issues resulting from the combination of redo and undo.
You can optimize this be storing command objects for changes that are easily reversable and storing images for changes that are not easily reversable.
Upvotes: 2
Reputation: 1692
Ray Tayek is right. Use the command pattern. That is, for every action the user performs, you push that action (command) and any data related to that action on the Undo stack.
Let's look at a paint program for simplicity. The process is directly applicable to your OpenGL app. The user draws a line from x1, y1 to x2, y2. The command could be represented something like this:
command = DrawLine
data = x1, y1, x2, y2
You'd probably need at least two classes for the Undo data, but they'd be small and easily implemented. When the user wants to undo, just pop the top object off the Undo stack, look at it, and carry-out the associated undo action (specific to each type of command). Or, you could even include the undo action in each command object itself. Then push the undone command on the Redo stack.
This should be enough to get you started. HTH
Upvotes: 0