Question

In: Computer Science

The main tasks of this C++ programming assignment include implementing a transformation matrix and a view/projection...

The main tasks of this C++ programming assignment include implementing a transformation matrix and a view/projection matrix. Giving three 3D points v0(2.0, 0.0, −2.0), v1(0.0, 2.0, −2.0), v2(−2.0, 0.0, −2.0),you are required to transform these points to the camera/view/monitor coordinates system, and draw a lined triangle based on them

get_projection_matrix(float eye_fov, float aspect_ratio, float zNear, float zFar): using the giving parameter, build a projection matrix, and return it.

Here is what I have so far.

Eigen::Matrix4f get_projection_matrix(float eye_fov, float aspect_ratio,
                                      float zNear, float zFar)
{
    // Students will implement this function

    Eigen::Matrix4f projection = Eigen::Matrix4f::Identity();

    // TODO: Implement this function
    // Create the projection matrix for the given parameters.
    // Then return it.

    return projection;
}

Solutions

Expert Solution

Transformation matrices
Introduction to matrices
Simply put, a matrix is ​​an array of numbers with a predefined number of rows and columns. For example, a 2x3 matrix might look like this:-

3D graphics we will mainly use 4x4 matrices. They will allow us to transform our (x, y, z, w) vertices. This is done by multiplying the vertex with a matrix:

Matrix x Vertex (in this order !!) = TransformedVertex

It's not as scary as it sounds. Place your left finger on a and your right finger on x. This is an ax. Move your left finger to the next number (b) and your right finger to the next number (y). You have passed. Once again: cz. Once again: dw. ax + by + cz + dw. You have a new x! Do the same for each line and you will get a new vector (x, y, z, w).

Now this is pretty boring to compute, and we will be doing this often, so let's ask the computer to do this instead.

In C ++ with GLM:

glm :: mat4 myMatrix;
glm :: vec4 myVector;
// fill in myMatrix and myVector somehow
glm :: vec4 transformedVector = myMatrix * myVector; // Again in this order! it is important.

In GLSL:

mat4 myMatrix;

vec4 myVector;

// fill in myMatrix and myVector somehow
vec4 transformedVector = myMatrix * myVector; // Yes, This Is Almost The Same As GLM
(did you cut, didn't paste this into your code? Go ahead, try it)

The View Matrix
To quote Futurama again:

The engines do not move the ship at all. The ship remains in place, and the engines move the universe around it.

​​​​​​

When you think about it, the same goes for cameras. If you want to see the mountain from a different angle, you can move the camera ... or move the mountain. Although impractical in real life, in computer graphics it is really simple and convenient.

So, initially your camera is located at the beginning of the World Space. To move the world, you simply enter another matrix. Let's say you want to move the camera 3 units to the right (+ X). This is equivalent to moving your entire world (including meshes) 3 units LEFT! (-X). While the brain is melting, let's do this:

// Use #include <glm / gtc / matrix_transform.hpp> and #include <glm / gtx / transform.hpp>
glm :: mat4 ViewMatrix = glm :: translate (glm :: mat4 (), glm :: vec3 (-3.0f, 0.0f, 0.0f));
Again, the image below illustrates this: we've gone from World Space (all vertices are relative to the center of the world, as we did in the previous section) to Camera Space (all vertices are relative to the camera).


Here is the required diagram:


Related Solutions

JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting. PROJECT GOAL: Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8....
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting. PROJECT GOAL: Create a program that simulates tossing a coin. This program should be titled flippingacoin.js and will require you...
C programming #include <stdio.h> #include <math.h> int main() { printf("============== Problem #1 =================\n"); printf("This should print...
C programming #include <stdio.h> #include <math.h> int main() { printf("============== Problem #1 =================\n"); printf("This should print down from 2 to 0 by 0.1 increments\n"); float f = 2.0; while (f != 0) { printf("%0.1f\n",f); f = f - 0.1; } printf("============== Problem #2 =================\n"); printf("This should find that the average is 5.5\n"); int total_score = 55; int total_grades = 10; double avg = total_score/total_grades; printf("Average: %0.2f\n",avg); printf("============== Problem #3 =================\n"); printf("If the population increases by 2.5 people per second, how...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the student will write a C++ program that implements a “fraction” object. When writing the object, the student will demonstrate mastery of implementing overloaded operators in a meaningful way for the object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Mathematical Modeling - Fractions · Operator Overloading – Binary Operators (Internal Overload) · Operator Overloading – Binary Operator (External...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace std; // class definition class Fraction {         // two data members         // one representing numerator         int numerator;         // other, representing denominator         int denominator;         public:                 void set (int numerator, int denominator);                 Fraction addedTo (Fraction f);                 Fraction subtract (Fraction f);                 Fraction multipliedBy (Fraction f);                 Fraction dividedBy (Fraction f);                 bool isEqualTo (Fraction f);                 void print (); }; void Fraction :: set (int numerator, int denominator) {         this...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
Thread Programming (C Programming) Objective Develop threads: thread and main. Functionality of Threads: The main program...
Thread Programming (C Programming) Objective Develop threads: thread and main. Functionality of Threads: The main program accepts inputs from the user from the console. The user can provide the following two types of input: add num1 num2 mult num1 num2 Here, num1 and num2 are two integer numbers. E.g., the user may input add 1 2. The threads receive the command along with the number, and performs the appropriate arithmetic operation and returns the results to main program. The main...
write a C++ Program for matrix operations which include: 1. constructor in the form-- matrix::matrix(int numRows,...
write a C++ Program for matrix operations which include: 1. constructor in the form-- matrix::matrix(int numRows, int numColumns) 2. Implement a setter method of the form: -- void matrix::setElement(int row, int col) 3 Implement a getter method of the form: -- float matrix::getElement(int row, int col) 4. Make a threaded version of the matrix/matrix addition method. 5. Make a threaded version of the matrix/scalar multiplication method. 6. Matrix/matrix addition methods of the form: -- matrix matrix::matrixAdd(matrix inMatrix) // non-threaded version...
Matrix Multiplication with Threads - C/C++ In this assignment you will use the Pthreads library to...
Matrix Multiplication with Threads - C/C++ In this assignment you will use the Pthreads library to write a program that multiplies two square arrays and compare the difference between the imperative and parallel implementations of this algorithm. Use the matrix mulltiplication algorithm. Write a program that contains three functions: (1) A function that has an integer as a parameter and returns a pointer to square array of integers (i.e. both dimensions should be equal). The function should allocate storage from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT