[Solved] CENG477 Assignment 1

Click And Check all our Assignments
Click Here and Upload you Assignment for Free!


100/100 Trustscore on scamadviser.com

10 USD $

Category: Tag:

1 Objectives

In this assignment, you are going to implement Modeling Transformation, Viewing Transformation, and Rasterization stages of the Forward Rendering Pipeline. Specifically, given a set of triangles and the position and the color attributes of all of their vertices, your goal is to render the scene as a two-dimensional (2D) image. The parameters of a perspective view camera will be specified similar to the first assignment. You will transform all of the vertices to the viewport and then use line drawing and triangle rasterization algorithms to display the triangles in wireframe or solid modes. You will implement a clipping algorithm of your choice (Cohen-Sutherland or Liang-Barsky) for wireframe mode only. You will also implement the backface culling (for both modes) for correct rendering of the scene. You will write your implementations in C++ language.

Keywords: forward rendering pipeline, modeling transformations, viewing transformations, line drawing, triangle rasterization, interpolation, clipping, backface culling

2 Specifications

  1. Name of the executable will be “rasterizer”.
  2. Your executable will take an input file name from command line. Input file names are not static, they can be anything.
  3. The scene will be composed of instances of meshes. A set of triangles will form a mesh with a sequence of several transformations (translation, rotation, scaling) you will be able to move, rotate, or resize a mesh (i.e., all of the triangles in the mesh). Transformations will be applied to the meshes in the order specified in the input file.
  4. You will not implement any lighting computations in this assignment. The color of each vertex will be provided as input and your goal will be to interpolate color along the edges and the surfaces of the triangles in wireframe and solid modes, respectively.
  5. You will implement two types of projection transformations: orthographic projection and perspective projection.
  6. Use the midpoint algorithm to draw triangle edges and use the barycentric coordinates based algorithm to rasterize triangle faces.
  7. In both wireframe and solid modes, triangles whose backface is facing the viewer will be culled. Backface culling should be enabled/disabled according to the setting in input file. You should calculate normal vectors for backface culling. Default value for backface culling setting is ’disabled’.
  8. You will also implement a clipping algorithm of your choice. For example, you can choose an algorithm among algorithms that you saw on the lectures. You will do clipping for wireframe mode only. For solid mode meshes, you can assume that the mesh is completely visible to the camera.
  9. There can be multiple camera configurations for each given scene.
  10. You will NOT deal with reading input files. Helper functions for reading inputs, helper functions for mathematical operations (e.g. normalization, matrix multiplication) are given to you in “Scene.cpp” and “Helpers.cpp” It is STRONGLY recommended to inspect types in header files and helper functions, which are given to you in homework stub code. You can modify these helper functions as you wish, or you can implement your own helper functions.
  11. Last important note: You will NOT implement depth buffer algorithm in this homework. Meshes will be given to you in back-to-front order. So, when you draw a mesh, you can assume that next mesh is closer to the camera than previous meshes.

3 Input File

You will not deal with reading input files, however, it is good for you to know what input file contains for testing purposes. Input files are in XML format and their structure is given below:


<BackgroundColor>R G B</BackgroundColor>

<Culling> enabled or disabled </Culling>


<Camera id=”#” type=”perspective or orthographic”>

<Position>X Y Z</Position>

<Gaze>X Y Z</Gaze>

<Up>X Y Z</Up>


Left Right Bottom Top Near Far HorRes VerRes


<OutputName> <image_name>.ppm </OutputName>


… more cameras …



<Vertex id=”1″ position=”X Y Z” color=”R G B” /> … more vertices …



<Translation id=”1″ value=”tx ty tz” /> … more translations …



<Scaling id=”1″ value=”sx sy sz” /> … more scalings …



<Rotation id=”1″ value=”angle ux uy uz” /> … more rotations …



<Mesh id=”#” type=”wireframe or solid”>


<Transformation> <transformation_type> <transformation_id> </Transformation> … more transformations …



<vertex_id_1_triangle_1> <vertex_id_2_triangle_1> <vertex_id_3_triangle_1>

<vertex_id_1_triangle_2> <vertex_id_2_triangle_2> <vertex_id_3_triangle_2> … more faces (triangles) …



… more meshes …



3.1 Input File Sections

3.1.1 Background color:

Specifies the R, G, B values of the background.

3.1.2 Backface Culling Setting:

Specifies whether culling is applied or not. If it is ’disabled’, there will be no culling, just draw all triangles. If it is ’enabled’, culling should be done when triangle’s backface is facing to the viewer.

3.1.3 Cameras:

  • Id specifies the camera id.
  • Type specifies which projection transformation is applied. If it is ’orthographic’, that means you need to apply orthographic projection, If it is ’perspective’, you should apply perspective projection.
  • Position specifies the X, Y, Z coordinates of the camera.
  • Gaze specifies the direction that the camera is looking at.
  • Up specifies the up vector of the camera. The up vector is not necessarily given as orthogonal to the gaze vector. Therefore the camera’s x-axis is found by a cross product of the gaze and up vectors, then the up vector is corrected by a cross product of gaze and x-axis vectors of the camera.
  • ImagePlane specifies the coordinates of the image plane in Left, Right, Bottom, Top parameters; distance of the image plane to the camera in Near and distance of the far plane to the camera in Far parameters, and the resolution of the final image in HorRes and VerRes All values are floats except HorRes and VerRes, which are integers.
  • OutputName is a string which is the name of the output image.

3.1.4 Vertices:

  • Id specifies the vertex id.
  • Position specifies the position of the vertex in X Y Z.
  • Color specifies the color of each vertex in R G B.

3.1.5 Translations:

  • Id specifies the translation id.
  • Value specifies tx, ty, and tz, which are the translation parameters, i.e., translation amounts along the major axes.

3.1.6 Scalings:

  • Id specifies the scaling id.
  • Value specifies sx, sy, and sz, which are the scaling parameters, i.e., scaling level in the corresponding coordinate axes.

3.1.7 Rotations:

  • Id specifies the rotation id.
  • Value specifies α, ux, uy, and uz, which are the rotation parameters, i.e., the object is rotated α degrees around the rotation axis which pass through points (ux,uy,uz) and (0,0,0). The positive angle of rotation is given as the counter-clockwise rotation along the direction (ux,uy,uz).

3.1.8 Meshes:

  • Id specifies the mesh id.
  • Type specifies the type of the mesh. ’wireframe’ for wireframe, ’solid’ for solid rendering.
  • Each transformation has transformation type and transformation id parameters. The ‘t’ indicates a translation transformation, ‘s’ indicates a scale transformation, and ‘r’ indicates a rotation transformation. The transformation id ranges from [1 …translation count] for type ‘t’ transformations, and similarly for the other type of transformations.
  • In Faces section you can find the triangles and each line represents a triangle. Each triangle is given as a list of vertex ids in counter clockwise order when faced from the front side. Vertex ids start from 1.

4 Sample input/output

A sample camera and a scene file are provided below:


<BackgroundColor>255 255 255</BackgroundColor>

<Culling>enabled</Culling> <——- backface culling is enabled <Cameras>

<Camera id=”1″ type=”perspective”> <——- perspective projection

<Position>-10 -40 -26</Position>

<Gaze>1 1 -0.2</Gaze>

<Up>0 1 0</Up>

<ImagePlane>-1 1 -1 1 2 1000 700 700</ImagePlane>



<Camera id=”2″ type=”perspective”> <——- perspective projection

<Position>-20 -28 -23</Position>

<Gaze>1 0.5 -0.2</Gaze>

<Up>0 1 0</Up>

<ImagePlane>-1 1 -1 1 2 1000 700 700</ImagePlane>





<Vertex id=”1″ position=”1.0 1.0 -1.0″ color=”100 100 100″ />

<Vertex id=”2″ position=”-1.0 1.0 -1.0″ color=”255 0 0″ />

<Vertex id=”3″ position=”-1.0 1.0 1.0″ color=”0 255 0″ />

<Vertex id=”4″ position=”1.0 1.0 1.0″ color=”0 0 255″ />

<Vertex id=”5″ position=”1.0 -1.0 -1.0″ color=”0 0 255″ />

<Vertex id=”6″ position=”-1.0 -1.0 -1.0″ color=”0 255 0″ />

<Vertex id=”7″ position=”-1.0 -1.0 1.0″ color=”255 0 0″ />

<Vertex id=”8″ position=”1.0 -1.0 1.0″ color=”100 100 100″ />



<Translation id=”1″ value=”0.0 10.0 0.0″ />

<Translation id=”2″ value=”3.0 -3.0 -6.0″ />



<Scaling id=”1″ value=”5.2 5.2 5.2″ />



<Rotation id=”1″ value=”45 0.0 1.0 0.0″ />

<Rotation id=”2″ value=”60 0.8 0.6 0.0″ />

<Rotation id=”3″ value=”20 1.0 0.0 0.0″ />



<Mesh id=”1″ type=”solid”> <——- mesh is drawn in solid mode <Transformations>

<Transformation>r 1</Transformation>

<Transformation>t 2</Transformation>

<Transformation>s 1</Transformation>



7 8 4

  • 4 3
  • 5 1

8 1 4

6 3 2

6 7 3

3 4 1

3 1 2

6 2 5

2 1 5

5 8 6

7 6 8





You can see outputs of this example in the next page.

(a) Solid-culling enabled (b) Solid-culling disabled

(c) Wireframe-culling enabled (d) Wireframe-culling disabled

Figure 1: Same mesh, different modes of rendering

5 Hints & Tips

  1. Start early!
  2. Note that in the wireframe mode only the edges of the triangle will be drawn.
  3. For debugging purposes, consider using simple scenes. Also it may be necessary to debug your code by tracing what happens for a single triangle (always simplify the problem when debugging).
  4. You can reach different inputs in “culling disabled inputs” and “culling enabled inputs” folders and desired images in “culling disabled outputs”, “culling enabled outputs” and “different projection type” You will see that different camera angles, output of different rendering modes are provided to you to understand 3d scene and rendering modes completely.

6 Regulations

  1. Programming Language: C++
  2. Late Submission: You can submit your codes up to 3 days late. Each late day will be deduced from the total 7 credits for the semester. However, if you fail to submit even after 3 days, you will get 0 regardless of how many late credits you may have left. If you submit late and still get zero, you cannot claim back your late days. You must e-mail your assistants if you want your submission to not be evaluated (and therefore preserve your late day credits).
  3. Cheating: We have zero tolerance policy for cheating. People involved in cheating will be punished according to the university regulations and will get 0. You can discuss algorithmic choices, but sharing code between each other or using third party code is strictly forbidden. To prevent cheating in this homework, we also compare your codes with online ray tracers and previous years’ student solutions. In case a match is found, this will also be considered as cheating. Even if you take a “part” of the code from somewhere/somebody else – this is also cheating. Please be aware that there are “very advanced tools” that detect if two codes are similar. So please do not think you can get away with by changing a code obtained from another source.
  4. Newsgroup: You must follow the announcements in OdtuClass (odtuclass.metu.edu.tr) for discussions and possible updates on a daily basis.


There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CENG477 Assignment 1
10 USD $