Graphics by ewghwehws

VIEWS: 4 PAGES: 18

• pg 1
```									    159.235 Graphics & Graphical
Programming
Lecture 19 - Introduction to 3D
Graphics

159.235                Graphics             1
3D Intro - Outline
•   2D Viewing
•   Parametric Equations
•   3D Models
•   Projective Geometry
•   3d Graphics Rendering and Voxels
•   Movies, games, and Virtual Reality
•   Polygons and scenegraphs
159.235               Graphics           2
2D Viewing
• Our “model” so far has been entirely 2-dimensional
• Model uses x,y Cartesian coordinates
• Simple mapping to pixel space coordinates for our
“rendering”
• Cropping (what to do if model is outside our
renderable window)
• Not trivial but details hidden from us by the graphics
library
• Scaling and other Affine Transforms possible
• Colours, text, drawing primitives such as line,
rectangle, filled shapes …
159.235                 Graphics                   3
Details of Drawing Shapes and
Clipping Them
• Graphics library (in our case the java Swing
Library) does all this.
• Some interesting algorithms in fact needed
for this
• Shapes drawn parametrically
• Clipping regions calculated rather than just
implemented naively
• Important for speed and Performance
159.235              Graphics                4
Parametric Equation for a Circle
• x = R cos(theta)
• y = R sin(theta)
• R = sqrt( x^2 + y^2 )
• R is radius (a constant for a particular circle)
• theta is a parameter of the equation (radians angle - 2Pi
-> 1 full rotation or 360 degrees)
• Implement as:
– for( theta = 0; theta < 2Pi; theta += increment )

159.235                      Graphics                 5
Circle Equation is Basis for
Polar Coordinates
• (r,theta) <--> (x,y)
• given a particular origin (x_0,y_0)

• We have affine transform utility:
– g2.translate( x-amount, y-amount);

159.235                  Graphics           6
• What do we do if we want to render something
in 3D?
• Our model has (x,y,z) cartesian coordinates
• How do we translate this into a rendered view?
• We use some projective geometry:
• Project what you would see as a flat image or
picture if you looked at a real world 3D object
from a particular viewpoint
159.235              Graphics                 7
Projective Geometry
• We need transformations to project the model
coordinates to a view plane coordinate space (what we
or a camera “sees”)
• But we see a distorted view - things further away
look different from things that are closer
• So also apply a perspective transformation - to distort
what a viewer would see from a particular point in
model space
• So a lot more computation needed to make all this
work - luckily modern libraries will do a lot of the
work for us
159.235                 Graphics                    8
Geometry Implementation
• If we needed to build a library we would
need to go into details of the Mathematical
formulations of the projection transforms
• Typically write a a matrix that operates on
a world coordinate space to a viewing one
• World might be (x,y,z)
• View might be (u,v) - like normal (x,y)
but in the plane of the view
159.235             Graphics                9
3D Graphics Implementation
• Generally your application maintains a
world model
• This is mapped to the 3D internal
representation
• A projection computes what would be seen
in a 2D view space
• A rendering turns the 2D view into pixels

159.235            Graphics               10
Rendering Pipeline
• This sequence of getting from model world to
pixels is often called the rendering pipeline
• Sometimes have special hardware to help the
various stages - eg polygon calculations
• Our world model might be based on a wire-frame
model built from polygonal shapes and with surface
textures or images that we paste on top of them
– Together this information constitutes the “scene-graph”

159.235                   Graphics                       11
Voxels
• We sometimes imagine a voxelated model
• Voxel = volume element
• Pixel = picture element
• But until recently we did not have
hardware that could “render” voxels
directly
• Polymer prototyping machines come close
• The scene-graph model is more useful
159.235            Graphics             12
3D Graphics is the basis of VR
• Virtual Reality (VR) is when we try to fool
our human senses into thinking we are
interacting with a model world that need
never actually exist in reality
• It is entirely simulated in our program
• We render it into displays that we can
surround ourselves with and total immersion
VR goes further and simulates other sensory
information such as sounds or movements
159.235            Graphics               13
3D Graphics used in Movies &
Games
• Recent examples - Shrek and Gollum
• Wire-frame models that are updated according to
some approximate physics calculations (not yet in
real-time!)
• Superpose texture maps (colours etc) onto the
surfaces defined by the wire-frames
• Render and image - becomes still frame in a movie or
game.
• Around 25 frames-per-second fools the human vision
system into thinking we see continuous motion
159.235                Graphics                  14
3D Practicalities
• How do we represent the world model?
• Wireframe model is set of polygons
• Possibly a very large set if the world
object has smooth rounded surfaces
• A cube could be modeled with just 6
polygons (6 squares in fact)
• Each might have a separate texture and
colour
159.235            Graphics                15
Polygons
• A polygon - many sided shape will have a set of
vertices and edges
• A Graphics library may provide a Polygon class
• There are various file formats for storing polygon
information
• A growing set of proprietary and some free tools that
let us design things - create the polygon information
• We can then store/exchange/combine these files
• Often our own applications generate the polygons
from some “physics” (rules about our model world)
159.235                 Graphics                   16
Generating World “Objects”
• We can develop and combine algorithms to
generate shapes
• A cube is 6 squares
• A sphere could be generated parametrically from
parametric spherical trigonometrical equation
• We can approximate a sphere by a surface made
up of lots of polygons, with an opaque colour

159.235               Graphics                  17
Summary
• 3D Graphics allows us to render a real world
model into a projected view
• The view can be rendered as per normal
graphically
• All the information in a “scene-graph” together
with the viewpoint and lighting model etc tells
us what we would see if the model were “real”
• Uses in Movies, Games and VR systems
• Computationally very expensive -
supercomputers needed

159.235                Graphics                     18

```
To top