computer graphics in java1 objects and viewers two basic entities (one object seen from two...

37
Computer Graphics in Java 1 Objects and Viewers Two basic entities (one object seen from two different positions) :

Upload: wilfred-ford

Post on 27-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Computer Graphics in Java 1

Objects and Viewers Two basic entities (one object seen from two different positions) :

Computer Graphics in Java 2

Lights & Images Others attributes:

light sources

Computer Graphics in Java 3

Colors Light is a form of

electromagnetic radiation Visible spectrum 350 – 780 nm

Computer Graphics in Java 4

Ray Tracing Ray tracing

building an imaging model by following light from a source

a ray is a semi-infinite line that emanates from a point and “travels” to infinity in a particular direction

portion of these infinite rays contributes to the image on the film plane of the camera

surfaces: diffusing reflecting refracting

Computer Graphics in Java 5

Ray Tracing

A different approach must be used:

for each pixel intensity must be computed

all contributions must be taken into account

a ray is “followed” in the opposite direction, when intersect a surface it is split into two rays

contribution from light sources and reflection from other resources are counted

Computer Graphics in Java 6

Pinhole Camera

Box with a small hole film plane z = - d

dzy

yp

dzx

xp

!!!yp,-d

Computer Graphics in Java 7

Pinhole Camera point (xp,yp,-d) –projection of the point (x,y,z)

angle of view or field of the camera – angle

ideal camera – infinite depth of field

dh

2arctan2

Computer Graphics in Java 8

Synthetic Camera Model computer-generated image

based on an optical system – Synthetic Camera Model

viewer behind the camera can move the back of the camera – change of the distance d i.e. additional flexibility

objects and viewer specifications are independent – different functions within a graphics library

Imaging system

Computer Graphics in Java 9

Synthetic Camera Model

a – situation with a camera

b – mathematical model – image plane moved in front of the camera

center of projection – center of the lens

projection plane – film plane

Computer Graphics in Java 10

Synthetic Camera Model

Imaging with the Synthetic Camera Model

film plane position in a camera projected scene to the

projection plane

Computer Graphics in Java 11

Synthetic Camera Model Not all objects can be seen

limit due to viewing angle

Solution:

Clipping rectangle or clipping window placed inn front of the camera

ad b shows the case when the clipping rectangle is shifted aside – only part of the the scene is projected

Computer Graphics in Java 12

Programmer’s Interface

Numerous ways for user interaction with a graphics system using input devices - pads, mouse, keyboards etc.

different orientation of coordinate systemscanvas

Computer Graphics in Java 13

Application Programmer’s Interface

API functionality should match the conceptual model

Synthetic Camera Model used for APIs likeJava3D, VRML etc.

Functionality needed in the API to specify:• Objects• Viewers• Light sources• Material properties

Computer Graphics in Java 14

Application Programmer’s Interface

Objects are defined by points or vertices, line segments, polygons etc. to represent complex objects

API primitives are displayed rapidly on the hardware

usual API primitives: points line segments polygons text

Computer Graphics in Java 15

Application Programmer’s Interface Camera specification in APIs: position – usually center of

lens orientation – camera

coordinate system in center of lens camera can rotate around those three axis

focal length of lens determines the size of the image on the filmactually viewing angle

film plane - camera has a height and a width

Computer Graphics in Java 16

Graphics Architectures

Early graphics systems – CRT had just basic capability to generate line segments connecting two points

vector based with refreshing – length of line segments limitedlight pen often used for manipulation

systems with memory CRT – the whole picture redrawn if changed

Computer Graphics in Java 17

Graphics Architectures

Display processors standard architecture with capabilities to display primitives composition made at the host memory – display list – contains primitives to be displayed.

Computer Graphics in Java 18

Pipeline Architectures

VLSI circuits enabled major advances in graphics architectures - simple arithmetic pipeline a + b * c - when addition of (b * c) and a is performing new b * c is

computed in parallel – pipelining enabled significant speed up

- similar approach can be used for processing of geometric primitives as well

Computer Graphics in Java 19

Pipeline Architectures

There are 4 major steps in the geometric pipeline: transformations – like scaling, rotations, translation,

mirroring, sheering etc. clipping – removal of those parts that are out of the

viewing field projection rasterizationhomogeneous coordinates and matrix operations geometric

transformations are used

Computer Graphics in Java 20

Clipping, Projection & Rasterization

Clipping is used to remove those parts of the world that cannot be seen.

Objects representation is “kept” in 3D as long as possible. After transformation and clipping must be projected to 2D somehow

projected objects or their parts must be displayed – and therefore rasterized.

All those steps are performed on your graphics cards in haerware nowadays.

Computer Graphics in Java 21

Where We’re Going Today’s lectures:

Mathematical FoundationsThe graphics pipeline: the big pictureRigid-body transformsHomogeneous coordinates

Computer Graphics in Java 22

Mathematical Foundations A brief, informal review of some of the

mathematical tools employed in graphicsGeometry (2D, 3D)TrigonometryVector and affine spaces

Points, vectors, and coordinates

Dot and cross productsLinear transforms and matrices

Computer Graphics in Java 25

3D Geometry To model, animate, and render 3D scenes,

we must specify: Location Displacement from arbitrary locations Orientation

We’ll look at two types of spaces: Vector spaces Affine spaces

The distinction is often sloppy or loose

Computer Graphics in Java 26

Vector Spaces Two types of elements:

Scalars (real numbers): … Vectors (n-tuples): u, v, w, …

Supports two operations: Addition operation u + v, with:

Identity 0 v + 0 = v Inverse - v + (-v) = 0

Scalar multiplication: Distributive rule:(u + v) = (u) + (v)

( + )u = u + u

Computer Graphics in Java 27

Vector Spaces A linear combination of vectors results in a

new vector:v = 1v1 + 2v2 + … + nvn

If the only set of scalars such that 1v1 + 2v2 + … + nvn = 0

is 1 = 2 = … = 3 = 0 then we say the vectors are linearly independent The dimension of a space is the greatest number of

linearly independent vectors possible in a vector set For a vector space of dimension n, any set of n

linearly independent vectors form a basis

Computer Graphics in Java 28

Vector Spaces: A Familiar Example Our common notion of vectors in a 2D plane

is (you guessed it) a vector space:Vectors are “arrows” rooted at the originScalar multiplication “streches” the arrow,

changing its length (magnitude) but not its direction

Addition uses the “trapezoid rule”: u+vy

xu

v

Computer Graphics in Java 30

Vectors And Point We commonly use vectors to represent:

Points in space (i.e., location) Displacements from point to point Direction (i.e., orientation)

But we want points and directions to behave differently Ex: To translate something means to move it

without changing its orientation Translation of a point = different point Translation of a direction = same direction

Computer Graphics in Java 31

Affine Spaces To be more rigorous, we need an explicit

notion of position Affine spaces add a third element to vector

spaces: points (P, Q, R, …) Points support these operations

Point-point subtraction: Q - P = v Result is a vector pointing from P to Q

Vector-point addition: P + v = Q Result is a new point

Note that the addition of two points is not definedP

Q

v

Computer Graphics in Java 32

Affine Spaces Points, like vectors, can be expressed in

coordinatesThe definition uses an affine combinationNet effect is same: expressing a point in terms

of a basis Thus the common practice of representing

points as vectors with coordinates

Computer Graphics in Java 34

Dot Product

The dot product or, more generally, inner product of two vectors is a scalar:

v1 • v2 = x1x2 + y1y2 + z1z2 (in 3D) Useful for many purposes

Computing the length of a vector: length(v) = sqrt(v • v)

Normalizing a vector, making it unit-length Computing the angle between two vectors:

u • v = |u| |v| cos(θ) Checking two vectors for orthogonality Projecting one vector onto another θ

u

v

Computer Graphics in Java 35

Cross Product The cross product or vector product of two

vectors is a vector:

The cross product of two vectors is orthogonal to both

Right-hand rule dictates direction of cross product

1221

1221

1221

21 )(

y x y x

z x z x

z y z y

vv

Use a determinate to compute the cross product

Computer Graphics in Java 36

Linear Transformations A linear transformation:

Maps one vector to anotherPreserves linear combinations

Thus behavior of linear transformation is completely determined by what it does to a basis

Turns out any linear transform can be represented by a matrix

Computer Graphics in Java 37

Matrices By convention, matrix element Mrc is

located at row r and column c:

By (OpenGL) convention, vectors are columns:

mnm2m1

2n2221

1n1211

MMM

MMM

MMM

M

3

2

v

v

v

v

1

Computer Graphics in Java 38

Matrices Matrix-vector multiplication applies a

linear transformation to a vector:

Recall how to do matrix multiplication

z

y

x

v

v

v

MMM

MMM

MMM

vM

333231

232221

131211

Computer Graphics in Java 39

Matrix Transformations A sequence or composition of linear

transformations corresponds to the product of the corresponding matricesNote: the matrices to the right affect vector

firstNote: order of matrices matters!

The identity matrix I has no effect in multiplication

Some (not all) matrices have an inverse: vvMM 1

Computer Graphics in Java 45

The Rendering Pipeline: 3-D

Transform

Illuminate

Transform

Clip

Project

Rasterize

Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay

Computer Graphics in Java 47

The Rendering Pipeline: 3-DScene graph

Object geometry

LightingCalculations

Clipping

ResultResult::

• All vertices of scene in shared 3-D “world” coordinate All vertices of scene in shared 3-D “world” coordinate systemsystem

• Vertices shaded according to lighting modelVertices shaded according to lighting model

• Scene vertices in 3-D “view” or “camera” coordinate Scene vertices in 3-D “view” or “camera” coordinate systemsystem

• Exactly those vertices & portions of polygons in view Exactly those vertices & portions of polygons in view frustumfrustum

• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped vertices

ModelingTransforms

ViewingTransform

ProjectionTransform