Docsity

Project 2: Transformations - Computer Graphics | CS 3451, Study Guides, Projects, Research of Computer Graphics

Toggle sidebar
bg1
Project 2: transformations
1 Goal
Implement a toy OpenGL-like line drawing system.
2 Remarks (important - please read carefully!)
You are not allowed to use any external matrix manipulation library for this project. You have to
implement all matrix and vector operations yourself.
You can use the 2D version of the line command for line drawing (i.e. the one with four arguments).
Don’t use OpenGL, P3D or any other library for 3D rendering.
This is an Individual project. You can discuss high level or technical issues with others, but not the
actual code details. All the code you submit must be yours. Any case of collaboration beyond the
allowable limits will be reported as a violation of the Honor Code.
3 Input file
The input file will be named ’input.txt’ and will contain of a number of disjoint BeginShape...EndShape
blocks (called shape blocks later on). There will be no nested blocks. The only statements inside a shape
block block will be Vertex statements, that would specify a 3D vertex. A shape block will specify 3D
disconnected lines, a continuous 3D polygonal line or a 3D polygonal loop, depending on the parameter
of BeginShape.
Outside the shape blocks, we’ll be manipulating the modelview and pro jection matrices. These matrices
are going to be applied to all vertices (first, the modelview matrix and then the projection matrix) to
transform them into the screen coordinates. Note that the matrices can change between shape blocks,
so vertices in different blocks will generally be transformed differently. We’ll also have a matrix stack
available for quick saving and restoring the modelview matrix.
3.1 Shape block-related commands
Vertex x y z
Specifies a vertex with coordinates x,y and z. No other command will be present inside a shape block.
BeginShape type
Start a shape block. type can be Lines,LineStrip or LineLoop. If vertices specified inside the block are
v1, v2. . . vnthen the following lines should be drawn:
If type=Lines:v1v2, v3v4, . . . , v2bn/2c−1v2bn/2c
If type=LineStrip:v1v2, v2v3, v3v4, . . . , vn−1vn
If type=LineLoop: all lines that would be drawn for LineStrip plus vnv1(to close the loop)
EndShape
End a shape block.
3.2 Modelview matrix manipulation
At startup, the modelview matrix is assumed to be the identity and should be a 4×4 matrix in homogenous
coordinates. Any of the transformation calls discussed below multiplies the current modelview matrix by
the corresponding transformation on the right – just like in OpenGL.
1
pf2

Partial preview of the text

Download Project 2: Transformations - Computer Graphics | CS 3451 and more Study Guides, Projects, Research Computer Graphics in PDF only on Docsity!

Project 2: transformations

1 Goal

Implement a toy OpenGL-like line drawing system.

2 Remarks (important - please read carefully!)

You are not allowed to use any external matrix manipulation library for this project. You have to implement all matrix and vector operations yourself.

You can use the 2D version of the line command for line drawing (i.e. the one with four arguments). Don’t use OpenGL, P3D or any other library for 3D rendering.

This is an Individual project. You can discuss high level or technical issues with others, but not the actual code details. All the code you submit must be yours. Any case of collaboration beyond the allowable limits will be reported as a violation of the Honor Code.

3 Input file

The input file will be named ’input.txt’ and will contain of a number of disjoint BeginShape...EndShape blocks (called shape blocks later on). There will be no nested blocks. The only statements inside a shape block block will be Vertex statements, that would specify a 3D vertex. A shape block will specify 3D disconnected lines, a continuous 3D polygonal line or a 3D polygonal loop, depending on the parameter of BeginShape. Outside the shape blocks, we’ll be manipulating the modelview and projection matrices. These matrices are going to be applied to all vertices (first, the modelview matrix and then the projection matrix) to transform them into the screen coordinates. Note that the matrices can change between shape blocks, so vertices in different blocks will generally be transformed differently. We’ll also have a matrix stack available for quick saving and restoring the modelview matrix.

3.1 Shape block-related commands

Vertex x y z Specifies a vertex with coordinates x,y and z. No other command will be present inside a shape block.

BeginShape type Start a shape block. type can be Lines, LineStrip or LineLoop. If vertices specified inside the block are v 1 , v 2... vn then the following lines should be drawn: If type=Lines: v 1 v 2 , v 3 v 4 ,... , v 2 bn/ 2 c− 1 v 2 bn/ 2 c If type=LineStrip: v 1 v 2 , v 2 v 3 , v 3 v 4 ,... , vn− 1 vn If type=LineLoop: all lines that would be drawn for LineStrip plus vnv 1 (to close the loop)

EndShape End a shape block.

3.2 Modelview matrix manipulation

At startup, the modelview matrix is assumed to be the identity and should be a 4×4 matrix in homogenous coordinates. Any of the transformation calls discussed below multiplies the current modelview matrix by the corresponding transformation on the right – just like in OpenGL.

Rotate α x y z Rotate by α degrees (yes, degrees not radians!) around the axis passing through the origin and (x, y, z). The rotation should appear counterclockwise for someone at (x, y, z) and looking toward the origin for angles α between 0 and 180.

Translate x y z Translate by (x, y, z).

Scale a b c Apply scaling with scaling factors (along the x-, y- and z- axes) of a,b and c.

3.3 Matrix stack-related commands

The matrix stack is a stack containing modelview matrices.

PushMatrix Push a copy of the current modelview matrix on stack

PopMatrix Pop matrix from the stack; Put it into the modelview matrix

3.4 Projection

We’ll use perspective projection for rendering. The projection is specified as described below.

Projection α Use perspective projection with field of view α (specified in degrees). The viewpoint is assumed to be at the origin. The viewing direction is along the negative z-axis. The screen is assumed square, axis-oriented (edges are parallel to either x− or y− axes), perpendicular to and symmetric about the z-axis.

3.5 Subroutine call

Subroutines are called using the command

Call filename

where filename is the name of the file containing the subroutine. The result should be equivalent to cutting and pasting the file in the place of the Call command. In a file passed as an argument to Call statement there may be a Call statement to another file; however, there will be no recursion.

3.6 Printing out the modelview matrix

PrintModelviewMatrix Print out the current modelview matrix to the console. Print the first row (4 numbers; separate entries by spaces), then new line, then the second row etc.