Microsoft Word - cse2383Program2.docx This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the...

Can you do this?


Microsoft Word - cse2383Program2.docx This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the honor code. Keep with the spirit of the assignment. CSE 2383 – Data Structures and Analysis of Algorithms Program 2 - Stacks Objectives:  Implement a basic Stack data structure  Implement matrix multiplication functions  Do something cool while improving your programming chops! Assignment: Picture it! Sicily, 2024. You have graduated from Mississippi State with a prestigious degree. You have just been hired by a new Italian-based computer graphics start-up called Grafica Veloce. With your background in data structures, you’ve been tasked with building a crucial component of their new 3D rendering pipeline – writing their transformation stack! You will be writing a program that will apply translations or rotations to 3D points. What is a transformation stack? In computer graphics, you frequently need to “transform” a 3D point (also known as a vertex). Transformations consist of either moving a vertex along an axis (called translation) or rotating a vertex around an axis (called rotation). Stacks are used to keep track of these transformations as well as the order that they need to be applied to a vertex. How are transformations stored? A transformation is usually represented as a 4x4 matrix. You’ll be implementing four kinds of transformation matrices: roll (z-rotate), pitch (x-rotate), yaw (y-rotate), and translate (moving along x,y,z directions). A vertex is transformed by multiplying it by each of the matrices in your stack. PROTIP: Feeling nervous about working with matrices? Don’t worry. Use the formulas given below, and let the computer do the actual math! Rotation Matrix. In the following, Ɵ represents the angle that you are rotating about the X, Y, or Z axes. There is a different matrix formulation for each axis. This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the honor code. Keep with the spirit of the assignment. Translation Matrix. In the following, Tx, Ty, and Tz are the distances along the X, Y, and Z axes, respectively, that you want to translate a vertex. C++ Classes. Your program must implement a stack that stores 4x4 transformation matrices. You will need to implement a Stack class and Node class similar to those discussed in class (see slides for sample code). Additionally, you will need to implement a Matrix class that stores a 4x4 matrix of floating-point values. Minimum requirements for Stack class. The Stack class should implement the following functionality: void push(Matrix data) Creates a new node and stores the matrix specified by data in that node and pushes in onto your stack. Otherwise, mimics functionality of code example in slides. bool pop() Removes the node from the top of the stack. Returns true if successful and returns false if not. Otherwise, mimics functionality of code example in slides. bool peek(Matrix &data) Copies the matrix from the node on top of the stack into data. Returns true if successful and returns false if not. Otherwise, mimics functionality of code example in slides. bool multiplyStack(Matrix &data) Creates a temporary identity matrix (tmp). Multiplies tmp by the matrix at the top of the stack, stores the result in tmp, pops the matrix at the top of the stack, and repeats until the stack is empty. Returns the matrix stored in tmp in data. The stack should be empty after this operation is completed. Minimum requirements for Matrix Class. The Matrix class must implement the following functionality: bool setValue(int index_x, int index_y, float value) This function sets the cell in in the matrix to value. index_x and index_y begin in the top left of the matrix, starting with <0, 0=""> and end in the bottom right corner with <3,3>. This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the honor code. Keep with the spirit of the assignment. The function returns true if requested indices are within the bounds of the matrix. Otherwise, the function returns false. Matrix multiply(Matrix input) This function multiplies the current matrix with the input matrix. The result of this multiplication is then returned by the function. Matrix operator*(const Matrix &right) HONORS SECTION STUDENTS ONLY (optional for others): You must also implement an overload operator for multiplying two matrices by each other using the * operator. Your multiply function must then specifically use this operator to perform multiplications. Minimum requirements for Node Class. See slides and modify according to assignment requirements. #adaptimproviseovercome Program Usage. Your program should prompt the user to enter a series of commands from the following list (see Tokenizer sample code for an example). You may recycle the code from the Tokenizer example to implement as much of these functions as necessary. HINT: Your program will ask you to enter your angles in degrees, but most math libraries expect angles to be in radians. You might want to consider a conversion in your code. Just saying. #beentheredonethat rotateX …where angle is a floating-point rotation in degrees applied to the x-axis. This command makes a x-axis rotation matrix and adds it to your stack. rotateY …where angle is a floating-point rotation in degrees applied to the y-axis. This command makes a y-axis rotation matrix and adds it to your stack. rotateZ …where angle is a floating-point rotation in degrees applied to the z-axis. This command makes a z-axis rotation matrix and adds it to your stack. translate …where x, y, and z are floating-point distances along the x, y, and z axes respectively. This command makes a translation rotation matrix and adds it to your stack. undo This command pops the most recent matrix from the stack. transformVertex This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the honor code. Keep with the spirit of the assignment. …where x, y, and z are their respective floating-point components of a 3D vertex. This command multiplies each matrix in the stack from top to bottom. Once each matrix has been multiplied, it should be popped from the stack. The final transformation matrix has been calculated it is them multiplied by the specified vertex. The resulting vertex should be displayed as “Final Vertex: ”. CLUE: Can you multiply a 3-component vector by a 4x4 matrix? No? Hmmm, what a conundrum. load Loads a plain text file specified by filename and then runs the commands written in the file. Your program should display each line and their subsequent output. See Example 4 below. exit Exits the program. Example Executions Example 1. Example of the commands and their output are shown below. User input is highlighted in green. Program output is highlighted in yellow. translate 0 2 0 rotateX -180 transformVertex 0 0 0 Final Vertex: 0.0 2.0 0.0 Example 2. Example of the commands and their output are shown below. User input is highlighted in green. Program output is highlighted in yellow. rotateX -45 rotateY 90 rotateZ 12.7 translate 4 2 1 transformVertex 3 0.5 1 Final Vertex: -2.0 -4.58 5.85 This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the honor code. Keep with the spirit of the assignment. Example 3. Example of the commands and their output are shown below. User input is highlighted in green. Program output is highlighted in yellow. rotateX -45 rotateY 90 rotateZ 12.7 undo undo undo translate 4 2 1 transformVertex 3 0.5 1 Final Vertex: 7 2.5 2 Example 4. Example of the commands and their output as show below. User input is highlighted in green. Program output is highlighted in yellow. load testinput.txt rotateX -45 rotateY 90 rotateZ 12.7 translate 4 2 1 transformVertex 3 0.5 1 Final Vertex: -2.0 -4.58 5.85 rotateX -45 rotateY 90 rotateZ 12.7 translate 4 2 1 transformVertex 3 0.5 1 Contents of testinput.txt This is an individual assignment. Seeking direct help from students, tutors, and websites such as chegg or stack overflow will be construed as a violation of the honor code. Keep with the spirit of the assignment. Grading Breakdown: There are 100 points available for this assignment. They are distributed as follows. A. Program Structure (12 points) a. Header comment with name, class, assignment
Sep 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here