# 计算机图形学代写 | COMP3811: Computer Graphics Coursework 1

COMP3811: Computer Graphics
Coursework 1

Drawing lines
Unpack the tar file. Run qmake and make as you have been taught in the tutorial. Run the resulting
pixelate application. The application window shows a rasterized screen with a single red pixel.
The PixelWidget.cpp contains a method DefinePixelValues
v oi d Pi x elWi d g et : : D e f i n e P i x e l V a l u e s ( ) {
S e t P i x e l ( 1 9 , 9 , RGBVal ( 2 5 5 , 0 , 0 ) ) ;
}
It is clear that by adding SetPixel calls it is possible to construct larger primitives, made up from
pixels. We use this widget to make the effects of rasterization more visible.
1
Assigment 1: First make sure that you are able to set arbitrary pixels (within the widget) to arbitrary
RGB values. Adopt the following convention: a pair of floats define a pixel on the screen. The first
gives the horizontal distance in number of pixels from the top left corner, the second the vertical
distance. Add a method call DrawLine to the PixelWidget class that is able to take four floating
point values, the first two defining the starting point, and the second two the end point, and that
draws a line of white pixels between them. Use the parameterised version of a line to calculate the
pixels that will be hit between the two points. This entails choosing steps that are small enough to
ensure you hit every pixels, but large enough to be not overly wasteful. Motivate your choice for
a step size. Make sure that this method is called in paintEvent, so that a line is drawn. Add a
screenshot to the report and explain whether the result is as expected.
[3 marks]
Assignment 2: Adapt the method you have just created so that it is able to accept an RGB value (use
struct RGBVal) for starting point, another one for end point and interpolate the colour along the line.
[4 marks]
Assignment 3: Create a method that accepts three points and associated RGB values. Use barycentric
coordinates to interpolate pixels that are part of the triangle.
[4 marks]
Assignment 4: Implement the half plane test for determining whether a point is inside or outside
the triangle. Create a function called IsInside that takes as arguments the three vertices (each one
specified by two floats), defining the triangle and a point in pixel coordinates. Apply this function
to all pixels in your image. Produce a file which lists the barycentric coordinates of each pixel and
the result of your function. Perform a comparison between the results of your function and the
barycentric coordinates (you can do this in a separate script if you like). In your report describe the
method, and comment on whether the results are as expected.

E-mail: vipdue@outlook.com  微信号:vipnxx