Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Chapter 5: MVC Architecture.

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Advertisements

OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
6/13/20151 CS 160: Lecture 13 Professor John Canny Fall 2004.
1 Model View Controller. 2 Outline Review Definitions of MVC Why do we need it? Administiriva Changing the display Event flow Dragging at interactive.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
System Architecture Lecture 3 CSE 111 Spring /22/20151Copyright William E. Howden.
Chapter 10: Coordinate Systems Chapter 10.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Intro and Chapter 1 Goals Give student some idea.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 12 Chapter 12: Making the Applications Interesting.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 7 Chapter 7: Graphical Primitives.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 3 Chapter 3: Simple Graphics Program.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 11 Chapter 11: Hierarchical Modeling.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 2 Chapter 2: GUI API.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 4 Chapter 4: Working with Graphics APIs.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Stanford hci group / cs376 research topics in human-computer interaction UI Software Tools Scott Klemmer 27 October 2005.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 8 Chapter 8: Transformation Operators.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Graphical User Interfaces in Haskell Koen Lindström Claessen.
Introduction to Java Swing “We are the sultans of swing” – Mark Knopfler.
Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 
Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6.
MVC pattern and implementation in java
Java Beans.
Microsoft Visual Basic 2005: Reloaded Second Edition
MVC and MVP. References enter.html enter.html
An Introduction to Software Architecture
Model-View-Controller Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
OpenGl Graphics Programming. Introduction OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of geomteric.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
SIMPLE PROBLEM SOLVING in Java: a Problem Set Framework Viera K. Proulx Richard Rasala Jason Jay Rodrigues CCSCNE 2002 Conference.
Chapter 6 – Architectural Design CSE-411, Dr. Shamim H Ripon.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
CPSC 372 John D. McGregor Module 3 Session 1 Architecture.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 15 Chapter 15: Working with the Camera.
Model View Controller MVC Web Software Architecture.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
ANDROID AND MODEL / VIEW / CONTROLLER. Slide 2 Design Patters Common solutions to programming problems are called design patterns Design patterns are.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 9 Chapter 9: Combining Transformation Operators.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
High degree of user interaction Interactive Systems: Model View Controller Presentation-abstraction-control.
1 Visual Basic: An Object Oriented Approach 7 – The User interface.
CSC 222: Object-Oriented Programming
Goals Give student some idea what this class is about
Lecture 28 Concurrent, Responsive GUIs
Understand Windows Forms Applications and Console-based Applications
Chap 7. Building Java Graphical User Interfaces
Chapter 2: GUI API Chapter 2.
Chapter 5: MVC Architecture Chapter 5.
Hands-on Introduction to Visual Basic .NET
Hierarchical Modeling
An Introduction to Software Architecture
Professor John Canny Spring 2004 March 5
Model, View, Controller design pattern
Professor John Canny Spring 2003 March 12
CMPE 135: Object-Oriented Analysis and Design March 14 Class Meeting
Presentation transcript:

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Chapter 5: MVC Architecture

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 We will … Learn MVC software architecture Describe MVC-based solution for ball shooting Examine Expendability of MVC solutions Develop software library support for MVC framework: UWBGL

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 In a nutshell … So far … Programming model: event driven GUI API: elements and event registrations Graphics API: GHC initialization and drawing with RC This chapter: MVC Architecture: consolidate all of the above!

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 The MVC Architecture

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Model-View-Controller Model Application state The persistent variables View Draws the application state Graphics API support Controller Accepts input from user to change the model GUI API support

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Model of Ball shooting program

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Model: Application State: All persistent variables Support: State Inquiries State Changes Timer event support (Simulation update) State Visualization

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 View of Ball shooting program

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Controller of Ball shooting program

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Expanding Ball shooting program

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Implement 2 views …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Notes on MVC … Simplicity: Model: usually most complex MVC: allow design of Model to be independent from user interaction and from drawing Portability: E.g., Change of controller ports Model to a different GUI platform Expendability: As we have seen: adding new view/controller pairs is straightforward

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 MVC: component interactions User change application state: Via controllers Application changes its own state Via timer events All controllers and views must present consistent state GUI element must be correct: e.g., slider bar reflecting the falling hero ball position Drawing must be update to date Classic MVC architecture Elaborate protocol to ensure all states are consistent …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 MVC with real-time simulation … Real-time simulation Every 25 milliseconds: timer fires! Application state likely to change MUST redraw all views!! During Timer event … ALWAYS Poll/update all controllers Update Application state Update all views Simple update protocol

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 2-View ball shooting component interaction

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 View/Controller Abstraction

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 GUI Support: Normal GUI support Main application window GUI elements: buttons, slider bars, etc. Graphics Drawing: UIWindow class: To display GHC frame buffer “drawing area” that can receive mouse events Capable of placing itself into application window

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 WindowHandler class A View/Controller pair abstraction Reference to View (GraphicsSystem class) The Rendering Context (RC) In D3D case: DIRECT3DDEVICE(9) In OGL case: HGLRC Reference to Controller The GUI drawing area UWBMFC_UIWindow class Activates View and draw to UI drawing area RC draw to UIWindow Receives mouse events from UIWindow Application can poll the mouse events

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tutorial 5.1: UWBGL libraries The same square drawing program MFC_Lib1 MFC_UIWindow UWBGL_Lib1 WindowHandler GraphcsSystem

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWB_MFC_LIB1 Our GUI wrapper Wrap over GUI API to “simplify” programming with GUI Library files (9 files): uwbgl_MFCDefines.h: MFC compilation parameter We will not change this uwbgl_MFC_Lib1.h: Include file for developers (us) Being included in the Stdafx.h of the project uwbgl_MFCUtility.h/.cpp ReplaceDialogControl implementation uwbgl_MFCSliderCtrlWithEcho1.h/.cpp Slider bard with echo uwbgl_MFCUIWindow1.h/.cpp UI drawing area designed to be referenced by WindowHandler Accepts Graphics drawing results Able to forward mouse events (to our application) Will _use_ this library (calling functions) Will not change this library (will not modify any of the functions)

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 MFC_Lib1 Classes:

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_D3D_Lib1 First attempt at wrapping over Graphics API Facilitate support for implementing MVC Library files: (14 files) in three folders Common Files Graphics API independent programming code D3D Files Direct3D specific support Header Files Header files for programmer (our programs) math3d++ Math support (from public domain) not developed at UWB, mainly, we will only use this library.

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_D3D_Lib1: files

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib1: WindowHandler + GraphicsSystem

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib1: Geometry and Math

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib1: Common files ( uwbgl_ )Common.h: Defines Constants (PI) Macros E.g., degree-to-radian conversion Compilation parameters We will not change this file

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib1: WindowHandler IWindowHandler: In Common/WindowHandler folder View/Controller pair abstraction

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Lib1: WindowHandler1.h/cpp In Common/WindowHandler folder API independent implementation of IWindowHandler abstraction Designed to be subclass by Graphics API specific classes E.g.,: D3DWindowHandler or E.g.,: OGLWindowHandler

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Lib1: Header Files Folder 2.h files D3DDefines.h All compilation parameters (uwbgl_)D3D_Lib1.h: this is the “.h” file meant to be included by programmers Being included in the Stdafx.h of the project

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Lib1: D3D Files Folder 8 files D3DCircleGeom/D3DRectangGeom (h/cpp) In D3D/D3D_Geoms folder Circle and rectangle drawing D3DGraphicsSystem.h/.cpp In D3D/D3D_GraphicsSystem folder D3DWindowHandler.h/.cpp D3D/D3D_WindowHandler folder Supports: BeginDraw() EndDrawAndShow

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 WindowHandler Hierarchy: IWindowHandler Pure abstract WindowHandler Reference to UIWindow D3D_WindowHandler D3D RC reference Application handler E.g. DrawOnlyHandler Must define UIWindow Refer to next slider …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Recall … View/Controller pair …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tutorial 5.1: Project The CModel class: Contains application state and support Rectangle and circle + Manipulation functions Knows how to draw itself

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 DrawOnlyHandler class Concrete WindowHandler class Only handles output drawing …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 DrawOnlyHandler::DrawGraphics()

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tutorial 5.1: GUI Main Window CTutorialDlg : subclass from CDialog

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 TutorialDlg::OnInitDlg() Recall, this is GUI, SystemInitialization! Must create Graphics API GHC Create/initialize GUI elements. Etc. …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 CTutorial::OnTimer()

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tutorial 5.1: Summary Model: is the CModel class. Very simple. Controllers: Two controllers: CTutorialDlg (application container window) CCircleRadiusControls View/Controller Pair: One DrawOnlyHandler: works via UIWindow Collaborations: CTutorialDlg contains all other components Components are not aware of each other CTutorialDlg polls/updates component states and triggers all redraws Because components are not aware of each other, we can insert/delete components from CTutorialDlg. Inconsistent state: May occur in between OnTimer events! However, the inconsistency will only last 25 mSec! Redraw/Paint Performed at the end of 25 mSec! Notice: we do not service the onPaint event! Our redraw occurs at fixed intervals of once every 25 mSec.

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tutorial 5.2: Mouse Events Left mouse click/drag to define circle The Model:

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.2: The Controller Design: Implementation (declaration)

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.2: Controller implementation

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Inconsistent State Mouse events – serviced immediately! Via call backs Until next redraw Internal circle radius is different from what is drawn on the screen Inconsistency lasts at most 25 mSec Typical user cannot see the inconsistency

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib2 WindowHandler::HardwareToDevice() Origin from upper left to lower left UWB_EchoToStatusArea(echoString) Output echoString to IDC_STATUS element … we must define a static textbox and name it IDC_STATUS at GUI building time If element not defined, echoString is not shown At initialization, sets UWB_hEchoWindow UWB_hEchoWindow defined in Lib2:Common Files/Utilities/uwbgl_Utility1.cpp

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.3: Real-time simulation ball … drops continuously

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.3: The Model

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.3: The simulation …

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.3: OnTimer service … During OnTimer (once every 25 mSec) Simply call UpdateSimulation() And Redraws everything (DrawGraphics()).

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Tut 5.4: Two views Multiple View/Controller pairs Requires: 2 Rendering Contexts (RC) or RC connecting to separate GHC buffers GraphicsSystem class improvements

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Drawing to multiple buffers OGL: Each RC connects to unique buffer Need multiple RC (HGLRC) D3D: RC (DIRECT3DDEVICE) capable of driving multiple buffers SwapChain

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib3: WindowHandler + Supports

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 D3D: Using SwapChain GraphicsSystem class WindowHandler class ( using SwapChain )

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib3: Utilities In Common files/

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 UWBGL_Lib3: Utilities

Essentials of Interactive Computer Graphics: Concepts and Implementation K. Sung, P. Shirley, S. Baer Chapter 5 Inter-Ball Collision