

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Implement a toy OpenGL-like line drawing system.
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.
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.
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.
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.
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
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.
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.
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.