1 review of compsci 221 chapters 1-11 in text user interfaces will be addressed as a take- home...
TRANSCRIPT
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