# 计算机图形学代写 | 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.