Modeling 101

22
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded by line segments Any face can be triangulated (broken into triangles)

description

Modeling 101. For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded by line segments Any face can be triangulated (broken into triangles). Modeling and OpenGL. - PowerPoint PPT Presentation

Transcript of Modeling 101

Page 1: Modeling 101

Modeling 101

• For the moment assume that all geometry consists of points, lines and faces

• Line: A segment between two endpoints• Face: A planar area bounded by line segments

– Any face can be triangulated (broken into triangles)

Page 2: Modeling 101

Modeling and OpenGL

• In OpenGL, all geometry is specified by stating which type of object and then giving the vertices that define it

• glBegin(…) …glEnd()• glVertex[34][fdv]

– Three or four components (regular or homogeneous)

– Float, double or vector (eg float[3])

• Chapter 2 of the red book

Page 3: Modeling 101

Rendering

• Determine where each object should go in the image

• Determine which object is in front at each pixel• Determine what color it is

Page 4: Modeling 101

Graphics Pipeline Watt Ch 5 and 6

• Graphics hardware employs a sequence of coordinate systems– The movement of geometry through these spaces is

considered a pipeline

Local Coordinate Space

World Coordinate Space

View Space 3D Screen Space

Display Space

Page 5: Modeling 101

Local Coordinate Space

• It is easiest to define individual objects in a local coordinate system– For instance, a cube is easiest to define with faces

parallel to the coordinate axis

• Key idea: Object instantiation– Define an object in a local coordinate system

– Use it multiple times by copying it and transforming it into the global system

Page 6: Modeling 101

Global Coordinate System

• All the objects in the world are transformed into one coordinate system - the global coordinate system

• Lighting is defined in this space• The camera is defined with respect to this space• Some higher level operations, such as advanced

visibility computations, can be done here

Page 7: Modeling 101

View Space

• Associate a set of axes with the image plane– One normal to the image plane

– One up in the image plane

– One right in the image plane

• Some camera parameters are easiest to define in this space– Focal length, image size

Page 8: Modeling 101

3D Screen Space

• Transform view space into a cube– Parallel sides make things easier

• Task to do:– Rasterization - decide which pixels are covered

– Hidden surface removal - decide what is in front

– Shading - decide what color things are

Page 9: Modeling 101

Display Space

• Convert the virtual screen into real screen coordinates– Drop the depth coordinates and translate

• The windowing system takes care of this

Page 10: Modeling 101

OpenGL and Transformations

• OpenGL combines all the transformations up to view space into the MODELVIEW matrix

• View space to Screen Space is done with the PROJECTION matrix

• Matrix calls multiple some matrix M onto the current matrix C: CM– Set view transformation first, then set transformations

from local to world space

Page 11: Modeling 101

Defining View Space

• View space is defined by location of three mutually perpendicular axes in world space– Translation, rotation and scaling can take points in world space to

points in view space

• Typically defined by:– Center of the image plane in world space: View Reference Point

(VRP)

– The normal to the image plane: View Plane Normal (VPN)

– A vector in world space that should be “up” in view space (VUP)

Page 12: Modeling 101

x y

z

World coordinates

View plane normal

View referencepoint

Up vector

u

v

n

View reference pointand view plane normalspecify film plane.

Up vector gives an “up”direction in the film plane.vector v is projection of up vector into film plane= (n x vup) x n

u is chosen so that (u, v, n) is a right handed coordinatesystem; i.e. it is possible torotate (x->u, y->v, z->n) (and we’ll do this shortly).

VRP, VPN, VUP must be inworld coords

Page 13: Modeling 101

World to View Space

• Translate by subtracting VRP

• Rotate by amount that aligns camera axes with world axes:

• All done for you in OpenGL:– gluLookAt takes the VRP, a point along the VPN, and VUP

– Multiplies the required transformation onto the current transformation (normally the identity)

n

v

u

Page 14: Modeling 101

Default OpenGL Camera

• The default OpenGL image plane has u aligned with the x axis, v aligned with y, and n aligned with z– Means the default camera looks along the negative z

axis

– Makes it easy to do 2D drawing (no need for any view transformation)

Page 15: Modeling 101

Left vs Right Handed View Space

• You can define u as right, v as up, and n as toward the viewer: a right handed system uv=n– Advantage: Standard mathematical way of doing things

• You can also define u as right, v as up and n as into the scene: a left handed system vu=n– Advantage: Bigger n values mean points are further

away

• OpenGL is right handed

Page 16: Modeling 101

Projection

• The conversion from view space to screen space is called projection

• Two general classes:– Orthographic, or parallel, projection

– Perspective projection

Page 17: Modeling 101

Orthographic Projection

• Points project along rays perpendicular to the image plane

• Just drop the n coordinate, and maybe scale and translate

• OpenGL: glOrtho(…)– Sets the appropriate projection matrix

Page 18: Modeling 101

Orthographic projection

Page 19: Modeling 101

Perspective Projection

• Abstract camera model - box with a small hole in it

• Pinhole cameras work in practice - camera obscura, etc

Page 20: Modeling 101

Distant Objects Are Smaller

Page 21: Modeling 101

Parallel lines meetcommon to draw film planein front of the focal point

Page 22: Modeling 101

Vanishing points• Each set of parallel lines (=direction) meets at a different

point: The vanishing point for this direction

• Sets of parallel lines on the same plane lead to collinear vanishing points: the horizon for that plane

• Easy examples – corridor

– higher = further away

• Good way to spot faked images