leadership discussion
February 23, 2020
Motor Development
February 23, 2020
Show all

Java JWJGL Library

USE ONLY NETBEANS 8.2 IDE, NO OTHER IDE’s ALLOWED!

Write a Java program which uses the LWJGL library to draw a window of 640×480 (with a black background).

THIS PROGRAM WILL NOT USE ANY OTHER GRAPHICS LIBRARIES BESIDES LWJGL!

To download and setup LWJGL with Netbeans 8.2 go here:
http://wiki.lwjgl.org/wiki/Setting_Up_LWJGL_with_NetBeans.html

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 ofthe 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.

When your program is evaluated, a different coordinates.txt file will be used to grade, so be sure your algorithm tests all cases, such as polygons with interior and exterior regions as well as self intersections.

There will be more than two polygons in the test file, so read till end of the file and not just two polygons.

Note: Please do not turn in anything that does not use Java with the LWJGL library.

I have attached a sample coordinates file and a picture with an example of what it should look like. When you are finished, the program should look like the example.png picture.

Leave a Reply

Your email address will not be published. Required fields are marked *