100% found this document useful (1 vote)
310 views40 pages

Coordinate Systems

There are different coordinate systems used in the graphics pipeline including local space, world space, view space, clip space, and screen space. Local space refers to the coordinates of an object. World space places objects relative to the game world scale. View space results from transforming world coordinates in front of the user's view. Clip space discards coordinates outside the clipping volume. Screen space is the final transformation to screen pixel coordinates. Functions like gluOrtho2D and glViewport are used to set up coordinate system transformations in OpenGL.

Uploaded by

getchew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
310 views40 pages

Coordinate Systems

There are different coordinate systems used in the graphics pipeline including local space, world space, view space, clip space, and screen space. Local space refers to the coordinates of an object. World space places objects relative to the game world scale. View space results from transforming world coordinates in front of the user's view. Clip space discards coordinates outside the clipping volume. Screen space is the final transformation to screen pixel coordinates. Functions like gluOrtho2D and glViewport are used to set up coordinate system transformations in OpenGL.

Uploaded by

getchew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Coordinate systems

In the graphics pipeline there are different


types of coordinate systems:

● Local space
● World space

● View space

● Clip space

● Screen space
Coordinate systems transform pipeline
Alternative representation of the Coordinate system
Transform Pipeline
Coordinate Systems

Local space
A coordinate space local to your object.
Measurement scale specific to the objects.

World space
A coordinate space where the vertices of your
objects will be placed relative to the scale in the
game world.
Object coordinates get transformed from local to
world space.
Coordinate Systems
View space (eye/camera space)
The result of transforming your world-space coordinates
to coordinates that are in front of the user’s view.

Clip space
Coordinates that end up clipped are discarded while the
rest become fragments. and the space local to your
object.
Transformation from view to clip space coordinates is
done via projection matrix.

Screen space
Transformation of the clip coordinates to screen
coordinates in a process call viewport transform
Coordinate Transform Pipeline

Model Transform

Previously we covered 2D and 3D model (object)


transformations(such as translation, rotation,
scaling etc.) .

In model transforms, we can go from object or


model space to world space (via homogeneous
coordinates)
Coordinate Transform Pipeline

View Transform

One simple 4x4 transform matrix is sufficient to


go from world space to camera or view space.
View Transform
View Transform
View Transform Matrix
View Transform Matrix
Projection Transform
Three dimensional graphics defines a 3D virtual
world; but display screens are 2D, hence the need
for projection.

Two types of Projections:

1. Perspective Projection
2. Orthographic Projection
Projection Transform
Perspective Projection Transform

How tall should


this bunny be?
Perspective Projection Transform
Geometry of Perspective
The z-axis is pointing in the negative direction — in OpenGL the center of projection is always
at the origin and pointing along the negative z-axis.

The projective plane is at a distance e in front of the center of projection. A point P = (p x , py , p z)


is projected onto (x, y , −e).

Figure A: Perspective Geometry, cross-section

By similar triangles we have:


y = −epy /pz .

If we imagine a similar diagram for x, we have:


x = −epx /pz .
And,
z = −e
OpenGL Frustum
The method glFrustum which is used to define a frustum of a pyramid
by OpenGL is used for perspective projection.
void glFrustum(GLdouble left, GLdouble
right,GLdouble bottom, GLdouble
top,GLdouble near,GLdouble far)

Figure B: Perspective view frustum volume defined by glFrustum

The 'e' in Figure A becomes 'n' in Figure B; consequently the simple raw projection eqns. for x
and y also become:
x = −npx /pz .
y = −npy /pz .
OpenGL Frustum
OpenGL maps the frustum given by l, r, b, t, n, f (abbreviating the six directions defined in
the glFrustum method) to the homogeneous clip space cube shown in below in Figure C, It
maps: l → −1, r → +1, b → −1, t → +1

Figure C: Perspective view frustum volume defined by glFrustum


Derivation of Perspective Transformation
We define the mapping formula as a scaling (a) plus a shift (b).

v = au + b , (1)

We have two pairs of points from which to derive a, b, namely, u0 → v0 ,


u1 → v1 (where '→' indicates mapping) from these we have two equations,

v0 = au0+ b and, (2)


v1 = au1+ b (3)
b = v0 − au0 (4)

Substituting eq.4 into eq.3:

v1 = au1 + v0 − au0 (5)

(6)
Derivation of Perspective Transformation
Substituting eq.6 to eq.4, we have:

(7)

Then eq.1 becomes:

(8)

Rearranging it, we get:

(9)
OpenGL Frustum

Recalling the previously generated formula (eq.9) maps u0→ v0 and u1→ v1 here:

In the present case x = l → x' = −1 and x = r → x' = +1 and likewise for y, y' .
For the x mapping, eq. 9 gives:
OpenGL Frustum
Finally substituting x and y respectively by:
x = −npx /pz .
y = −npy /pz .

We get: and

Rewritten:
OpenGL Frustum
Now pz has to be mapped; the problem here is that the rasterization stage needs the
reciprocal of pz (1/pz) rather than pz so that we need z = a(1/pz) + b. Eq.9 is still usable if we
define s = 1/pz and define the mappings s = −1/ n → z = −1 and s = −1/ f → z = +1, so eq. 9
gives:

Now we have got the coefficients of our projective transformation (-x'pz , -y'pz and -z'pz ).
OpenGL Frustum
From the projected 3D point p = (x , y , z ) (the mapped image of (p x , p y , p z )) we now
create the ‘homogeneous’ coordinates p = (-x'pz , -y'pz , -z'pz and -pz ); note the -pz in the w
component.

The whole projective transformation can now be written in terms of a matrix multiplication and
homogeneous coordinates
OpenGL Frustum
From the projected 3D point p = (x , y , z ) (the mapped image of (p x , p y , p z )) we now
create the ‘homogeneous’ coordinates p = (-x'pz , -y'pz , -z'pz and -pz ); note the -pz in the w
component.

The whole projective transformation can now be written in terms of a matrix multiplication and
homogeneous coordinates
Orthographic Projection Transform

Orthographic projection - projecting light rays


travel parallel to one another and to the viewing
direction

- Doesn't involve any perspective distortion


Orthographic Projection Transform
Coordinate transformations- all in one

.
World and Viewport Coordinate Systems

World Coordinate System (Object Space)


− Space in which the application model or object
geometry is defined.

World Window (Object Subspace)


− Rectangle defining the part of the world we
wish to display.
Viewport Transform
Screen Coordinate System (Image Space)
− Space in which the image is displayed; for
example 800x600 pixels.
− Space in which the object’s raster image is defined.

Interface Window (Image Subspace)


− Visual representation of the screen coordinate system for
windowed displays (coordinate system moves with the
interface window)
Window to Viewport Transformation
Refers to taking a window from a 2D picture in
world coordinates and transforming the points in
the window to viewport (screen coordinates).
Viewport (Image Subspace)
− A rectangle on the raster graphics screen (or interface
window) defining where the image will appear, usually the
entire screen or interface window.
− There might be more than one viewport inside an
interface window.
World to Viewport Transformation Mapping Steps
A three-step composition transformation matrix of world
coordinates(specifically in clip space) into viewport in screen
coordinates:
World to Viewport Composite Transformation Matrix
Proportionality in World to Viewport Transformation
Proportionality in World to Viewport Transformation

Ratios equality of the formula of coordinates as


shown below must be fulfilled for mapping an
object from world to viewpoint in undistorted
manner.
Example of World to Viewport Transformation
Summary
To transform the coordinates in one space
to the next coordinate space we use
several transformation matrices of which
the most important are the model, view
and projection matrix. Our vertex
coordinates first start in local space as local
coordinates and are then further processed
to world coordinates, view coordinates,
clip coordinates and eventually end up as
screen coordinates.
Pipeline of OpenGL Functions associated
with Coordinate System Transformation
Functions in OpenGL for world and viewport tasks
gluOrtho2D (left, right, bottom, top)
● Sets up a 2-D orthographic viewing region or world
window.

● Defined by two vertical clipping planes left and right and


two horizontal clipping planes bottom and top. The world
window by default is (-1, 1, -1, 1).

● Defines a 2-D orthographic projection matrix.

● Sets up the window-viewport mapping, being the


viewport defined by the following function:
Functions in OpenGL for world and viewport tasks
glViewport (x, y, width, height)

● Sets up the viewport in the interface window, where


x,y specify the lower left corner, and width, height
its dimensions.

● By default, it uses the whole graphics area of the


interface window.

● There may be various viewports inside the


interface window.

You might also like