This page was last updated: October 4, 2022
You are to create a GLM-based C++ program that allows you to manipulate 4x4 matrices.
The glm::vec3 version of Multiply( a, b ) needs to promote b to a glm::vec4 with 1.0 as the fourth element, do the multiply, and then demote the result to a glm::vec3 for the return value.
ScalePointAroundAnotherPoint( inputPoint, centerPoint, scale ) is to create a scaling matrix and apply it, returning the resulting point. Be sure to apply the scaling matrix around the centerPoint, however, not about the origin. (See below.)
RotatePointAroundAnotherPoint( inputPoint, centerPoint, first, second, third )
rotates the inputPoint by multiplying it by first, then
multiplying it by second, then multiplying it by third.
Be sure to apply the matrix multiplies around the centerPoint, however, not about the origin.
(See below.)
first, second, and third are already rotation matrices.
You need to apply them in the correct order.
Be sure to apply the matrix multiplies around the centerPoint, however, not about the origin.
(See below.)
For both ScalePointAroundAnotherPoint and RotatePointAroundAnotherPoint, you need to see what the relative position of inputPoint is with respect to centerPoint, and then operate on that. Basically, the process is:
In the glm::scale function arguments, there is a glm::mat4, like this:
glm::mat4 glm::scale( glm::mat4, glm::vec3 );
GLM automatically multiplies the scaling matrix that it produces by that mat4 in the argument list.
Because I am always worried about getting the matrix multiply order wrong, I just set that matrix in the argument list to identity:
glm::mat4 identity = glm::mat4( 1. );
glm::mat4 scaleMatrixByItself = glm::scale( identity, scaleVector );
and do any matrix multiplies with the * operator.
I will link your functions to my own main program which will use some values I provide. This will automatically compute your score.
It is recommended that you test your functions before submitting them.
The easiest way to compile and test your functions is on a Linux system, such as flip.
The commands to compile and run are:
g++ -o proj02 proj02.cpp
./proj02
Make up some good examples, hand-calculate them, and see if your code produces the right answers.
This is exactly how I am going to compile your assignment. If your functions do not compile, then I will know that you didn't take advantage of this information, and your grade will be a zero.
I will give you a .o file to test with. It will be similar to the grading program I will use. But, it will only tell you your final score. If you don't get full credit, it will not tell you what you are getting wrong. It is meant to reassure, not to replace your own testing!
Click here to get the test02.o file to test with. It is just like the grading program I will use, but it will only tell you your final score. If you don't get full credit, it will not tell you what you are getting wrong. It is meant to reassure, not to replace your own testing and debugging!
Use it like this (assuming the file you are planning to turn in is called proj02.cpp):
For those of you using your own Linux system and getting "PIE" error messages, try this version of the .o file:
Click here to get the test02B.o file to test with.
(It was compiled with a newer version of g++.)
g++ proj02.cpp test02.o -o proj02
./proj02
Use it like this (assuming the file you are planning to turn in is called proj02.cpp):
g++ proj02.cpp test02B.o -o proj02
./proj02
Because you are compiling separate from my code, you will need the following lines up at the top:
#include <stdio.h>
#include <string>
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#ifndef GLM_FORCE_RADIANS
#define GLM_FORCE_RADIANS
#endif
#include "glm/vec2.hpp"
#include "glm/vec3.hpp"
#include "glm/mat4x4.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/matrix_inverse.hpp"
You will not need these lines in your final turnin .cpp file.
Note that when you run your own tests, you will need a main( ) program. You must not have a main( ) program when you run with test02.o or when you turn in your .cpp file. In those two cases, I am providing the main( ) program.
If your code does not compile, then your grade for this project is a zero!
Feature | Points |
---|---|
Multiply ( mat4*mat4 ) | 20 |
Multiply( mat4*vec3 ) | 20 |
ScalePointAroundAnotherPoint | 20 |
RotatePoint | 20 |
TOTAL | 80 |