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. If you are motivated enough, you may also add extra functional keys that would allow the user to change the colors of the polygon fills. These added functions should be clearly stated in your comments. 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.

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

Step: 3

blur-text-image

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions