1Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Review of COMPSCI 221
Chapters 1-11 in text User Interfaces will be addressed as a take-
home question
2Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Computer Graphics
Modeling: Creating a virtual world.
Rendering: Generating a visual image of a scene.
Rendering
Virtual world model Image of a scene
3Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Java2D
Graphics2D class manages the rendering Use a Panel to provide the Graphics context Use JApplet or JFrame as root container
4Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Graphics2D Class
Propertiesâ Foreground colorâ Fontâ Strokeâ Paint
Capabilitiesâ drawing and filling Shape objectsâ applying AffineTransforms
5Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
2D Objects
A 2D object consists of a set of points in a plane
Examplesâ pointâ lines, curvesâ shapes like rectangles, ellipses, arcs, polygonsâ text and images
6Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Parametric Equation
Parametric equation expresses each coordinate in terms of a parameterx = f(t)
y = g(t) The parametric equation for an ellipse is
x = x0 + a cos t
y = y0 + b sin t
7Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Custom Shapes
Area combines shapes to create more complex objects
Set-theoretic operationsâ Intersectâ Addâ Subtractâ Exclusive or
PathIterator interface allows Shape object to return an iterator to sub-parts
Path2D constructs an outline from a sequence of lines and curves â moveTo
â lineTo
â quadTo
â curveTo
â closePath
8Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Coloring Objects
Paint interface supports â Color - create a color by giving the amount od
red, green, blue to make the colorâ Gradients - interpolations between two different
colorsâ Texture - use an image to "color" an object
9Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Strokes The Stroke interface defines a method for
creating an outline from a shape BasicStroke class has the following
propertiesâ Widthâ End style (butt, round, square)â Join style (bevel, miter, round)â Miter limit (limits miters on small angle joins)â Dash pattern and phase
10Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Affine Transformation
Maps parallel lines to parallel lines Common affine transforms in both 2D and
3Dâ Translationâ Rotationâ Reflectionâ Scaleâ Shear
11Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Clipping Path
A rendered image may be clipped by a clipping path
12Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Text in Java2D
Text is treated as a special kind of geometric object
A Font defines the rendering shapes of all the characters
Geometry of a text string in a particular font is represented by a GlyphVector
Create a Shape from the GlyphVector
13Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
BufferedImage
A BufferedImage contains â Raster -- holds the pixel
valuesâ ColorModel -- specifies
how to interpret pixel values
BufferedImage has a createGraphics method which allows you to draw to the image
BufferedImageOpsâ RescaleOp - scale pixel
values linearly
â LookupOp - use a table to convert pixel values
â ConvolveOp - convolute pixel value with thos of neighbors
â ColorConvertOp - pixel-by-pixel color conversion
â AffineTransformOp - apply the specified transformation to each pixel
14Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Animation
You need a way to make something happen at regular intervalsâ Change some parameter used by the paintComponent
methodâ call repaint() or revalidate() to cause paintComponent
to be called Timer is a Swing Component
â delay can be setâ generates an ActionEvent after each delay periodâ register a Listener to respond to the event
15Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
3D Model and View
16Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Java 3D
High-level API Scene is represented
as a scene graph objectâ Content branch defines
the onjects in the scene
â View branch defines how the scene is viewed
VirtualUniverseâ SimpleUniverse
Locale Nodes
â Group nodesâ Leaf nodes
NodeComponentsâ attached to one or more
nodes
17Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Background and Bounds
Default background is black Create custom background with the Background node
â set the color
â use an image
â use a geometry
Environmental nodes need to be limited in extentâ e.g. lights, background
â limits amount of rendering to be done
Two ways:â Bounds, node component
â BoundingLeaf, a Node uses a Bounds object
18Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Points and Vectors
Point represents position Vector represents
direction Both can be represented as
a tuple An n-dimensional vector
is an n-tuple of numbersâ (x1, x2, âŚ, xn)
19Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Shapes in 3D
Use a Shape3D Node to represent visual objectsâ A Shape3D leaf node
usually references Geometry and Appearance node components
Geometry is abstract class with many subclassesâ GeometryArray
â IndexedGeometryArray
â Text3D
20Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
GeometryArray
Supports construction of objects using arrays of points, lines and polygons
Defines an array of vertices along with other properties that are associated with themâ normalsâ color (3 or 4 elements)â texture coordinates (2, 3 or 4 elements)
21Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Transform3D
A higher-level representation for transformations
Has constructors to create from both Matrix objects and from vectors
Also has set and get methods for the internal 4x4 matrix
Can also set a particular type of transformation
22Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Views
View Volumeâ represented by a
projection matrix
View positioningâ represented by a view
matrix
View Propertiesâ Projection type
â Field of view
â Limits to view distance
â Size of view plate
23Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Projections A projection maps a point in the virtual
world onto a view planeâ view plate is a finite window in the view planeâ also limit the depth that is rendered
Two types of projectionâ parallelâ perspective
24Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Types of Lights
Ambient lightâ uniform in all
directions and locations
Directional lightâ models a distant light
source whose rays are all parallel
Point lightâ light located at a
particular location which emits in all directions
â Intensity decreases with distance
Spot lightâ Like a point source
except the direction of the emission is restricted
25Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Geometry of Reflection For perfectly reflective surface
â angle of incidence = angle of reflection
â no loss of intensity
In reality surfaces aren't perfect â light gets scattered
â light can be absorbed
Phong modelI = Iaka + Ipkd cos + Ipkscosn
â ka, kd, ks are coefficients for ambient, diffuse and specular reflection for a particular material
â n is the shininess coefficient, also a property of the material
26Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Appearance
Node component which has components that control various aspects of the appearance of an object.â ColoringAttributes, RenderingAttributes,
TransparencyAttributes
â PointAttributes, LineAttributes, PolygonAttributes
â Material
â TextureAttributes, Texture, TexCoordGeneration, TextureUnitState
27Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Material Contains components to control the color
contributed by different kinds of lightingâ ambient, diffuse, specularâ can also contain an emissive color component
Shininess coefficient affects specular reflection
Color target for per-vertex colors
28Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Depth Cueing
Atmospheric attenuation effects can be simulated with depth cueing
Blend the objects with background color (or with arbitrary fog color)C = f C0 + (1 - f) Cf
Blending is an increasing function of the distanceâ linearâ exponentialâ gaussian
29Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Texture Mapping
Real surfaces often have a large amount of detail
Use a digital image to provide complex detail with minimal computational cost
Procedural textures use a function to calculate the color at any given point
30Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Behavior
Java3D uses behavior to facilitate dynamics in a scene graph
Behavior is a leaf nodeâ Defines actions to be taken when the behavior
is activated (waked-up)â Behavior is triggered by wakeup conditions
For interactions, triggers are user generated For animation, triggers are time-based
31Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Interpolators for Animation
Interpolator is an abstract subclass of Behaviorâ It has a number of predefined subclasses containing
typical behaviors needed for animation For example, Color, Switch, Transparency, Transform
The idea is to set two values for a particular attribute and interpolate values in between as a function of time
Alpha object is used to trigger the changes
32Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Alpha
A function of time â usually periodic
Has a range from 0.0 to 1.0
33Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
User Interfaces
Design principlesâ User should be in
control
â Reduce memory load for users
â Be consistent
Useability heuristicsâ Ease of learning and
remembering
â Efficiency of use
â Minimize errors Facilitate recovery from
errors