159.235 2023 S02 — Assignment 2
This assignment covers the topics: coordinates, transformations, 3d modelling, and visiblesurfaces.
Wireframe Data Viewer
Write a Java program that renders a 3 dimensional triangle wireframe surface data modeland allows one to rotate and scale the model so that it can be viewed from any direction.This could be thought of as a simple CAD program.Your application needs to be set up so that the figures rotate as the sliders are adjusting,they uniformly resize after clicking the appropriate button, and they get re-drawn whentoggling between anti-aliasing on/off.Use the simple viewing model where the “eye” point is on the positive z-axis looking downand the figures are drawn by orthographically projecting onto the xy-plane.You will need to decide how to transform the vertex coordinates in the wireframe data forthe given rotations and scalings. You can then draw each triangle on the Graphics2D canvaswith the transformed vertex positions.Your rendered wireframe figures should appear “solid”—the wireframe outlines should beclearly visible. You need to implement some procedure to remove hidden surfaces. Youshould at least implement the back face culling method. You should find that this willemove most hidden surfaces—but not all of them. Top marks will be earned by thoseprograms that are able to remove all hidden surfaces.Sample triangle mesh wireframe data files are provided on Stream. You program shouldwork smoothly with all of them.You do not need to implement the 2D viewport clipping procedures described in the lectures.You can let the Java AWT handle all that.You do not need to apply any lighting or shading to the surfaces—this will be dealt withlater on in the course.
Completing the assignment
A set of startup Java source files are on Stream that will function as skeleton code forthe assignment. Load these into a new IntelliJ project and start up Main.java—this is the“controller” part of your project. This features a number of JPanels with slider and buttonwidgets. Familiarize yourself with the various components in the project folder.To complete the assignment, provide implementations for the other components. Whendoing so you will need to make small adjustments to Main.java—mostly in the event handlermethod. Complete as follows:
- The Wireframe.java file contains a class that holds 代 写159.235 2023 S02 Wireframe Data Viewerall data for a given triangle meshfigure. Decide what data needs to be stored there. Provide an implementation inWireframeDataIO.java to read from a wireframe .tri file and create a new instance ofWireframe[2 marks]
- Complete the implementation of the rotation matrix utilities in Transform3d.java. Thepurpose of this utility is to be able to readily generate a full rotation matrix givenrotation angles in each of the 3 planes.[2 marks]
- Make appropriate modification to the Wireframe class so that these rotations, as wellas scaling, can be applied to the triangle mesh data.[3 marks]
- Provide an implementation in WireframeDrawer.java to draw the triangles on a JPanelusing the transformed vertex positions. This needs to happen directly in response toadjusting the sliders and clicking the buttons.[3 marks]
- Provide an implementation of back face culling. You will need to decide the appropriateplaces in your project to make the modifications.[4 marks]
- Further modify your project to implement the Painter’s Algorithm. Here you will needto decide on a suitable approach for defining the “depth” of your triangles and how tosort them.[4 marks]
- Implement the action following the anti-aliasing buttons, so that the lines will bedrawn with anti-aliasing either on or off. Decide how this will be actioned in the Maincontroller. For this part is enough to use the anti-aliasing tools built-in with the JavaAWT.
[2 marks]
Due date: 2024 September 20, 11:55pm.Please submit via the submission link on Stream.Total 20 marks (20% of your final grade).Coding hints
- To read and parse a text file (as in the wireframe data files), the JDK suppliedjava.util.Scanner class is a useful utility. Create a Scanner object and use the .nextLine()method to step through the file line-by-line. This method will give you a line in a file asa String. Note: to use this utility, you will need to handle the FileNotFoundException.
- There are situations where you will need to split a String into sub-strings according tosome delimiter (e.g. space, tab, comma, . . . ). Use the java.util.StringTokenizer forthis.
- To convert a String to a numeric value, use Integer.parseInt() or Double.parseDouble().
- It is suggested that you draw each triangle using something like:
// xDraw and yDraw are s i z e 3 arrays g iv ing the t r i angle ver tex pos i t ions
Polygon aTriangle = new Polygon(xDraw, yDraw, 3);
// . . . ass ign values to aTriangle . . .
// The implementation d e t a il s w i l l depend upon how you have
// designed your program
g2.setColor(Color.gray);
g2.fill(aTriangle);
// Colour in the t r i angle sur face
g2.setColor(Color.black);
g2.draw(aTriangle);
// Draw the t r i angle ou tl ine
Note that xDraw and yDraw are integer arrays.
标签:wireframe,java,Viewer,S02,Wireframe,will,marks,need,data From: https://www.cnblogs.com/WX-codinghelp/p/18418630