Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program which uses the LWJGL library to draw a window of 640x480 (with a black background). The coordinate system should be centered

Write a Java program which uses the LWJGL library to draw a window of 640x480 (with a black background). The coordinate system should be centered in this window. Your program will read a file titled coordinates.txt and draw the corresponding filled polygon in this window using the scanline polygon fill algorithm. Each specified polygon should be filled in the color specified in the text file and then undergo the transformations specified in the input file before being drawn on the screen. Hence you will need to calculate the composition of the transformation matrices and then calculate the position of the polygon vertices and then apply the scan line fill algorithm. Use the glVertex2f() command to plot the pixel and glColor3f() to specify the color. Finally, your program should also use the input.Keyboard class to have the escape key quit your application.

The given coordinates.txt file will be in the following format:

P 0.5 0.6 0.3

30 300

80 150

160 400

200 150

250 300

T

r 45 0 0

s 0.5 1.5 0 0

t 200 150

r 90 0 0

P 0.2 0.4 0.7

-350 350

-350 350

350 350

350 350

T

r 90 0 0

t 100 100

s 0.5 0.5 0 0

The file coordinates.txt will contain an ordered set of vertices for the polygon. The polygon can be drawn by joining the first vertex to the second, the second to the third and so on, until the final vertex is joined to the first to close the polygon. It denotes the polygon vertices by using the symbol P and the transformations for that polygon by using the symbol T. The symbol P is followed by three-float numbers that signify the R, G and B values specifying the fill color of the polygon. The symbols r, s and t stand for rotation, scaling and translation respectively. The symbol r is followed by the rotation angle, and the coordinate for the pivot point. Similarly the symbol s is followed by the scaling factors in the x and y direction and the pivot point coordinates. The symbol t is followed by the translation coordinates in the x and y direction. The sample file shows two polygons and the transformations for each polygon.

File coordinates.txt:

P 1.0 0.0 0.0 80 10 80 30 230 37 280 30 280 10 T t 100 -75 r 30 0 0 s 0.5 1.5 0 0 P 0.1 0.8 0.3 10 10 10 80 80 60 210 10 210 80 150 10 T r 90 0 0 s 2.0 0.2 0 0 t 30 30 r -45 0 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Choose healthcare professionals who are members of your race?

Answered: 1 week ago