lecture 7: objects and interaction 1 principles of interactive graphics cmscd2012 dr david...

13
JMU Lecture 7: Objects and Interaction Lecture 7: Objects and Interaction 1 Principles of Interactive Graphics Principles of Interactive Graphics CMSCD2012 CMSCD2012 Dr David England, Room 718, ex 2271 [email protected] http://java.cms.livjm.ac.uk/homepage/staff/cmsden gl/Teaching/cmscd2012/ Web page includes: announcements, handouts, web links, reading hints, frequently asked questions

Upload: harry-townsend

Post on 25-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 1

Principles of Interactive GraphicsPrinciples of Interactive Graphics CMSCD2012CMSCD2012

Dr David England, Room 718, ex 2271 [email protected]

http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl/Teaching/cmscd2012/ Web page includes: announcements, handouts, web links,

reading hints, frequently asked questions

Page 2: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 2

Courseworks

Coursework 1 admin Hand in your design and code to the Campus Office Do your demo between 3 and 5pm today If you cannot do the demo just hand in what you have and ask me

about things you did not understand Coursework 2

Task will be to design and create a 2D controllers for a 3D object part 1: design and implement simple buttons to control the

attributes of the 3D object part 2: design and implement scrollbars to control the attributes Optional: Exploit OO techniques to manage design and code

Page 3: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 3

Today’s Lecture: 3D concepts

Object Oriented Design, (OOD) and Computer Graphics

How OOD has enabled the Graphical User Interface revolution

Designing your own objects in OOD

Background for coursework 2

Page 4: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 4

Object Oriented Design

In CY2001 you will have come across concepts such as Defining Classes and Objects Encapsulation (private variables and functions for classes) Polymorphism - functions with the same name but

different parameters Moving from OO design to OO Programming

Abstraction (to different levels) is the main technique of problem solving in Computer Science

OOD works by abstracting out the essential classes of objects in a problem, identifying their attributes and their functionality

Page 5: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 5

Object Oriented Design...

“… the hype surrounding OOSD looks more like reality and that adopting OOSD may indeed be worth the related time, effort and cost.” R Johnson CACM October 2000

OOD and OOP help control the complexity of larger systems development

In your own programs you will have seen the Display() function grow in size with the complexity of the graphical scene

How could you have use OOD and OOP to control and manage this growth?

(we’ll come back to this)

Page 6: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 6

OO Graphical User Interfaces - GUI

Smalltalk 80 was the first complete object-oriented programming environment.

http://www.cincom.com./smalltalk/downloads.html Everything in Smalltalk-80 is an object, from integers upwards The designers chose to split an application up into three parts

The View - the graphical part The Controller - the input handling part The Model - the logical part of the application (text handling,

database handling or whatever) Objects in the Controller (e.g. a menu handler) send messages

to the Model to do some calculation, which then sends a message to update the View.

Page 7: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 7

OO Graphical User Interfaces ….

The same model - MVC - can be seen in the design and implementation of current GUI toolkits Java Swing Microsoft Foundation Classes (MFC)

Swing and MFC put the Controller and View together MFC has a Document/View structure

Separating the Document and View parts of an application mean that different teams can work on the different parts

The GUI or View might require 50 to 90% of the development effort of a whole project!

Page 8: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 8

Designing your own Graphical Objects

OpenGL is designed around the idea of sending commands down a graphical pipeline

This maybe a good way of developing graphically intense programs such as games

While this reflects the underlying hardware it is not always the best way to program all graphical applications

In your coursework you may have split up the display() function to call other functions to draw the parts of the scene

For example, a dial() function which could draw a new dial in a different location

Page 9: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 9

Designing your own Graphical Objects ...

The dial() function could be extended to further parameters such as Colour of border and background Radius Range of dial readings Division of dial readings Colour and size of value indicator Font of dial readings and so on

Page 10: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 10

Designing your own Graphical Objects ...

Or we could take advantage of OOD and design a Dial Class comprising Private attribute of the attributes listed above An attribute for the current_pointer value Constructors to create a new Dial object A draw function (hiding the OpenGL implementation) An update function to change current_pointer and redraw

the pointer

The rest of the program would then only communicate with the dial via speed_dial.setCurrentPointer(int value);

Page 11: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 11

Designing your own Graphical Objects ...

Think for a moment of what other objects in your scene you could create classes for What would be their attributes? What methods would be needed? What attributes would be exposed to the rest of the

program to update your object? For example

Dials and other instruments, radar displays, indicator lamps, external scenery

Kitchen objects as part of a library for a kitchen design program

Page 12: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 12

Resources for Coursework 2

Use glutSolidCube(), or other GLUT convenience routines, to create a 3D object

The left mouse button generates the input events when over a button or scrollbar area - see the functions mouse() and motion() in inputevents.cpp

You have to manage the state between the different mouse events in a button or scrollbar

You could exploit OOD/OOP in reusing buttons and scrollbars

Page 13: Lecture 7: Objects and Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk

JMU Lecture 7: Objects and InteractionLecture 7: Objects and Interaction 13

Next Week

We will start to look in more detail at some of the principles of 3D graphics