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....
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...
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...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing...
C PROGRAMMING – Steganography In this assignment, you will write an C program that includes processing input, using control structures, and bitwise operations. The input for your program will be a text file containing a large amount of English. Your program must extract the “secret message” from the input file. The message is hidden inside the file using the following scheme. The message is hidden in binary notation, as a sequence of 0’s and 1’s. Each block of 8-bits is...
a) Discuss the main components and utility of the responsibility assignment matrix in a software engineering organization
a) Discuss the main components and utility of the responsibility assignment matrix in a software engineering organizationb) As a software engineer, you are involved in developing a project intended to implement a set of business processes and a software solution for customer relationship management.The project involves a large number of organizations?a major corporation and many suppliers of different sizes. During the project, you observe effects of the differences between the companies’ corporate cultures, which leads to different expectations on how...
The purpose of this C++ programming assignment is to practice using an array. This problem is...
The purpose of this C++ programming assignment is to practice using an array. This problem is selected from the online contest problem archive, which is used mostly by college students worldwide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest. For your convenience, I copied the description of the problem below with my note on the I/O and a sample executable. Background The world-known gangster Vito Deadstone...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT