1 / 23

Comp 401 Animation: MVC

Comp 401 Animation: MVC. Instructor: Prasun Dewan. Prerequisite. Animation: Loops. Shuttle Animation. Basic Architecture. APlotted Shuttle. setShuttleX (Y)(). AShuttleAnimator. animateFromOrigin (). Main Class. main. AnimateFromOrigin.

joann
Download Presentation

Comp 401 Animation: MVC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Comp 401Animation: MVC Instructor: Prasun Dewan

  2. Prerequisite • Animation: Loops

  3. Shuttle Animation

  4. Basic Architecture APlotted Shuttle setShuttleX(Y)() AShuttleAnimator animateFromOrigin() Main Class main

  5. AnimateFromOrigin publicvoidanimateFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime) { intoriginalX = shuttle.getShuttleX(); intoriginalY = shuttle.getShuttleY(); intcurX = 0; intcurY = 0; shuttle.setShuttleX(curX); shuttle.setShuttleY(curY); animateYFromOrigin(shuttle, animationStep, animationPauseTime, curY, originalY); animateXFromOrigin(shuttle, animationStep, animationPauseTime, curX, originalX); }

  6. Animation in Y Direction protectedvoidanimateYFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime, intstartY, intendY) { // make sure we don’t go past final Y position while(startY < endY) { ThreadSupport.sleep(animationPauseTime); startY+= animationStep; shuttle.setShuttleY(startY); } // move to destination Y position shuttle.setShuttleY(endY); }

  7. Main Method publicstaticvoid main(String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(450, 450); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); shuttleAnimator.animateFromOrigin(aShuttle, 5, 100, anOEFrame); } No animation, nothing happens on the screen Using non observable version of plotted shuttle

  8. Manual Full Refresh protectedvoidanimateYFromOrigin(PlottedShuttle shuttle, intanimationStep, intanimationPauseTime, intstartY, intendY, OEFrame frame) { // make sure we don’t go past final Y position while(startY < endY) { ThreadSupport.sleep(animationPauseTime); startY+= animationStep; shuttle.setShuttleY(startY); frame.refresh(); } // move to destination Y position shuttle.setShuttleY(endY); }

  9. Manual Full Refresh publicclassShuttleAnimationDriver { publicstaticvoiddemoShuttleAnimation( ShuttleAnimatoraShuttleAnimator, PlottedShuttleaShuttle, OEFrameanOEFrame) { aShuttleAnimator.animateFromOrigin(aShuttle, 5, 100); aShuttleAnimator.animateFromOrigin(aShuttle, 5, 100, anOEFrame); } publicstaticvoid main(String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(450, 450); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); demoShuttleAnimation(shuttleAnimator, shuttle, oeFrame); } } Both animateFromOrigins take the same amount of time The refreshing one changes the display, the other one does not

  10. Refreshing Architecture Component APlotted Shuttle setShuttleX(Y)() repaint() paint() ObjectEditor refresh() AShuttleAnimator animateFromOrigin animateFromOrigin() Main Class main

  11. Problem with Full Refresh • The entire UI is refreshed, not just the part that changes • Multiple GUIs (views) may be displaying the same object • Should create animated objects as observables

  12. Using MVC publicstaticvoiddemoShuttleAnimation( ShuttleAnimatoraShuttleAnimator, PlottedShuttleaShuttle, OEFrameanOEFrame) { aShuttleAnimator.animateFromOrigin(aShuttle, 5, 100); aShuttleAnimator.animateFromOrigin(aShuttle, 5, 100, anOEFrame); } publicstaticvoid main(String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(450, 450); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); demoShuttleAnimation(shuttleAnimator, shuttle, oeFrame); } } publicclassObservableShuttleAnimationDriverextendsShuttleAnimationDriver { publicstaticvoid main(String[] args) { ObservablePlottedShuttleshuttle = newAnObservablePlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(400, 400); oeFrame.setLocation(400, 0); PropertyChangeListenerview = newAPlottedShuttleView(shuttle); shuttle.addPropertyChangeListener(view); JFrame frame = newJFrame("Plotted Shuttle"); frame.add((Component) view); frame.setSize(400, 400); frame.setVisible(true); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); demoShuttleAnimation(shuttleAnimator, shuttle, oeFrame); }

  13. Animation and MVC

  14. Non Observable Architecture Component APlotted Shuttle setShuttleX(Y)() repaint() paint() ObjectEditor refresh() AShuttleAnimator animateFromOrigin animateFromOrigin() Main Class main

  15. Observable Architecture Component APlotted Shuttle setShuttleX(Y)() repaint() paint() ObjectEditor refresh() AShuttleAnimator animateFromOrigin animateFromOrigin() Main Class main

  16. Incremental Updates • After each animation step, all displays of the animation must be updated • The refresh operation can be used to do ensure these updates are made. • Better, the observable-observer concept can be used to ensure these updates are made • for each graphical property changed by the animation, the class of the property should allow observers to be registered and the setter of the property informs the observers about the update • ObjectEditor requires the JavaBeans observer-observer approach based around the PropertyChangeListener interface

  17. Extra

  18. Main vs. Interactive Animation publicstaticvoid main(String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize(450, 450); ShuttleAnimatorshuttleAnimator = newAShuttleAnimator(); shuttleAnimator.animateFromOrigin(aShuttle, 5, 100); } publicstaticvoid main (String[] args) { PlottedShuttleshuttle = newAPlottedShuttle(50, 100); OEFrameoeFrame = ObjectEditor.edit(shuttle); oeFrame.hideMainPanel(); oeFrame.setSize (450, 450); FancyShuttleAnimatorshuttleAnimator = newAFancyShuttleAnimator(); ObjectEditor.edit(shuttleAnimator); }

  19. Fancy Animator publicclassAFancyShuttleAnimatorextendsAShuttleAnimator implementsFancyShuttleAnimator { intanimationStep = 5; intanimationPauseTime = 100; PlottedShuttleshuttle; publicAFancyShuttleAnimator(PlottedShuttletheShuttle) { shuttle= theShuttle; } publicintgetAnimationStep() { returnanimationStep; } publicvoidsetAnimationStep(intanimationStep) { this.animationStep= animationStep; } publicintgetAnimationPauseTime() { returnanimationPauseTime; } publicvoidsetAnimationPauseTime(intanimationPauseTime) { this.animationPauseTime= animationPauseTime; } publicvoidanimateShuttle() { animateFromOrigin(shuttle, animationStep, animationPauseTime); } }

  20. GUI

  21. Video

  22. UI vs Main Thread Problem is that the user interface both executes loop and does the redraws the screen Redrawing of screen done after loop is over In the main case, the man thread or activity, executes loop The UI thread or activity redraws the screen

  23. Asking ObjectEditorto Interactive Call in Separate Thread @SeparateThread(true) publicvoidanimateShuttle() { animateFromOrigin(shuttle, animationStep, animationPauseTime); }

More Related