CS297 Graphics with Java and OpenGL - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

CS297 Graphics with Java and OpenGL

Description:

Set up your tripod and pointing the camera at the scene (viewing transformation) ... Choose a camera lens or adjust the zoom (projection transformation) ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 36
Provided by: computing97
Category:
Tags: opengl | cs297 | graphics | java

less

Transcript and Presenter's Notes

Title: CS297 Graphics with Java and OpenGL


1
CS297 Graphics with Java and OpenGL
  • Viewing, the model view matrix

2
coordinates to pixel positions
  • A series computer operations convert an object's
    three-dimensional coordinates to pixel positions
    on the screen.
  • Transformations, which are represented by matrix
    multiplication, include
  • modeling,
  • viewing,
  • projection operations.
  • Such operations include
  • rotation,
  • translation,
  • scaling,
  • reflecting,
  • orthographic projection,
  • and perspective projection.

3
coordinates to pixel positions
  • Generally, you use a combination of several
    transformations to draw a scene.
  • Since the scene is rendered on a rectangular
    window, objects (or parts of objects) that lie
    outside the window must be clipped.
  • In three-dimensional computer graphics, clipping
    occurs by throwing out objects on one side of a
    clipping plane.
  • Finally, a correspondence must be established
    between the transformed coordinates and screen
    pixels.
  • This is known as a viewport transformation.

4
Overview The Camera Analogy
  • Set up your tripod and pointing the camera at the
    scene (viewing transformation).
  • Arrange the scene to be photographed into the
    desired composition (modeling transformation).
  • Choose a camera lens or adjust the zoom
    (projection transformation).
  • Determine how large you want the final photograph
    to be - for example, you might want it enlarged
    (viewport transformation).
  • After these steps are performed, the picture can
    be snapped or the scene can be drawn.

5
Overview The Camera Analogy
Set up your tripod to look at where the model
will be created
6
Overview The Camera Analogy
Position viewing model of world which will
contain final model
7
Overview The Camera Analogy
Create geometric objects for adding to viewing
model
8
Overview The Camera Analogy
Insert geometric model in viewing model, and
decide on perspective
9
Perspective choices
Difference of perspectivegiven by choice of
cameraangle, and no change in any other
parameters
glu.gluPerspective(100.0, (float) w / (float) h,
1.0, 20.0)
glu.gluPerspective(10.0, (float) w / (float) h,
1.0, 20.0)
10
Perspective choices
Difference of perspectivegiven by choice
aspect,and no change in any other parameters
glu.gluPerspective(50.0, 0.5f, 1.0, 20.0)
glu.gluPerspective(50.0, 10.0f, 1.0, 20.0)
11
Viewport
Choose which part of scene is shown on screen
gl.glViewport(40, 50, w 500, h 400)
gl.glViewport(0, 0, w, h)
12
Computer Vertex Transformations Pipeline
  • Note that these steps correspond to the order in
    which you specify the desired transformations in
    your program, not necessarily the order in which
    the relevant mathematical operations are
    performed on an object's vertices.
  • The viewing transformations must precede the
    modeling transformations in your code.
  • You can specify the projection and viewport
    transformations at any point before drawing
    occurs.

13
Vertex Transformations
normalised device coordinates
clip coordinates
eye coordinates
modelview matrix
projection matrix
perspective division
viewport transformation
window coordinates
object coordinate
14
modelview matrix
  • The viewing and modeling transformations you
    specify are combined to form the modelview
    matrix, which is applied to the incoming object
    coordinates to yield eye coordinates.
  • Next, if you've specified additional clipping
    planes to remove certain objects from the scene
    or to provide cutaway views of objects, these
    clipping planes are applied.

15
clip coordinates
  • After that, OpenGL applies the projection matrix
    to yield clip coordinates.
  • This transformation defines a viewing volume
    objects outside this volume are clipped so that
    they're not drawn in the final scene.
  • After this point, the perspective division is
    performed by dividing coordinate values by w (the
    forth coordinate in a vertex), to produce
    normalized device coordinates. (See Appendix F of
    the Redbook for more information.)
  • Finally, the transformed coordinates are
    converted to window coordinates by applying the
    viewport transformation.
  • You can manipulate the dimensions of the viewport
    to cause the final image to be enlarged, shrunk,
    or stretched.

16
Matrix transformations
  • To specify viewing, modeling, and projection
    transformations, you construct a 4 4 matrix A,
    which is then multiplied by the coordinates of
    each vertex v in the scene to accomplish the
    transformation.
  • Note that viewing and modeling transformations
    are automatically applied to surface normal
    vectors, in addition to vertices.

17
Matrix transformations, the formulae
Where ui a(i,1)v1 a(i,2)v2 a(i,3)v3
a(i,4)v4
18
Matrix transformations, the formulae
Where ui a(i,1)v1 a(i,2)v2 a(i,3)v3
a(i,4)v4
19
Matrix transformations, the formulae
Where ui a(i,1)v1 a(i,2)v2 a(i,3)v3
a(i,4)v4
20
Matrix transformations, the formulae
Where ui a(i,1)v1 a(i,2)v2 a(i,3)v3
a(i,4)v4
21
Matrix transformations, the formulae
Where ui a(i,1)v1 a(i,2)v2 a(i,3)v3
a(i,4)v4
22
Rotation by matrix multiplication
Rotation about the x-axis by ? degrees in a
counter-clockwise direction
23
Rotation by matrix multiplication
Rotation about the y-axis by ? degrees in a
counter-clockwise direction
-sin(?)
0,
cos(?),
0,
x0
x1
0,
0
1,
y0
y1
0,

0
cos(?),
sin(?),
0,
z0
z1
w0
w1
0,
1
0,
0,
24
Rotation by matrix multiplication
Rotation about the z-axis by ? degrees in a
counter-clockwise direction
25
Translation by matrix multiplication
Translation along the X, Y and Z axes by x, y,
and z respectively
ASSUMES that final value in vertex is 1, if not
then translation is scaled.
26
Matrix transformations, the formulae
c(i,j) a(i,1)b(1,j) a(i,2)b(2,j)
a(i,3)b(3,j) a(i,4)b(4,j)
27
Matrix transformations, the formulae
c(i,j) a(i,1)b(1,j) a(i,2)b(2,j)
a(i,3)b(3,j) a(i,4)b(4,j)
28
Matrix transformations, the formulae
  • To first apply a rotation (matrix R) and then a
    translation (matrix T) to a vertex v the matrix
    multiplication formula is
  • new_v T.R.v (T.R) v T (R.v)
  • This is not the same as R.T.v. The order of
    matrix multiplication is important.

29
A Simple Example Drawing a Cube
30
The code
  • public void display(GLAutoDrawable drawable)
  • GL gl drawable.getGL( )
  • GLU glu new GLU()
  • GLUT glut new GLUT()
  • gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f)
  • gl.glClear(GL.GL_COLOR_BUFFER_BIT)
  • gl.glColor3f(1.0f, 1.0f, 1.0f)
  • gl.glLineWidth(3.0f)
  • gl.glLoadIdentity ()
  • gl.glTranslatef
  • (0.0f, 0.0f, -3.0f)
  • gl.glRotatef
  • (30.0f,0.0f,1.0f,0.0f)
  • glut.glutWireCube(0.9f)

public void reshape( GLAutoDrawable
drawable, int x, int y, int width, int
height) GL gl drawable.getGL(
) GLU glu new GLU()
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(GL.GL_PROJECTION)
gl.glLoadIdentity ()
glu.gluPerspective(50.0, 1.0, 1.0, -5.0)
gl.glMatrixMode (GL.GL_MODELVIEW)
31
The matrix transformations
  • gl.glLoadIdentity ()
  • gl.glTranslatef(0.0f, 0.0f, -3.0f)
  • gl.glRotatef(30.0f,0.0f,1.0f,0.0f)

32
glLoadIdentity
  • In the particular context of the display method,
    this command will set the current model view
    matrix to the identity matrix Id

0,
0
0,
1,
0,
0
1,
0,
0
1,
0,
0,
0,
1
0,
0,
33
glTranslatef(x,y,z)
  • this command multiplies the current model view
    matrix M Id, by this

0,
x
0,
1,
0,
y
1,
0,
T
z
1,
0,
0,
0,
1
0,
0,
So that the model matrix is then M1 M.T Id.T
34
glRotatef(?, 0,1,0)
  • this command multiplies the current model view
    matrix M, by this

-sin(?)
0,
cos(?),
0,
0,
0
1,
0,
R
0
cos(?),
sin(?),
0,
0,
1
0,
0,
So that the model view matrix is then M1.R
M.T.R Id.T.R
35
glut.glutWireCube(0.9f)
  • When this line is now executed
  • each vertex v in the cube is created
  • then each vertex is multiplied by the current
    model view matrix M1
  • the new vertices M1.v are then used to create the
    geometric model.
Write a Comment
User Comments (0)
About PowerShow.com