CS 491 -- Fall Quarter 2022

Project #2: Using GLM to Manipulate Matrices and Transformations

Due: October 10

80 Points


This page was last updated: October 4, 2022


Requirements

You are to create a GLM-based C++ program that allows you to manipulate 4x4 matrices.

Here is a short GLM primer

Your Functions

To prove that you know how to use GLM to accomplish useful matrix functionality, you will create the following functions:
  1. glm::mat4 Multiply( glm::mat4 a, glm::mat4 b )
  2. glm::vec3 Multiply( glm::mat4 a, glm::vec3 b )
  3. glm::vec3 ScalePointAroundAnotherPoint( glm::vec3 inputPoint, glm::vec3 centerPoint, glm::vec3 scale )
  4. glm::vec3 RotatePointAroundAnotherPoint( glm::vec3 inputPoint, glm::vec3 centerPoint, glm::mat4 first, glm::mat4 second, glm::mat4 third )
  5. void WhoAmI( std::string &yourName, std::string &yourEmailAddress )

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:

  1. glm::vec3 relativePoint = inputPoint - centerPoint;
  2. Do whatever operation needs to be done on relativePoint, producing glm::vec3 resultPoint
  3. return resultPoint + centerPoint;

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.

A Program Template

matrixtemplate.cpp

Grading

In a file called functions.cpp, turn in only these functions! Do not turn in any:

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.

Warnings!

  1. This is exactly how I am going to compile your assignment. If your functions do not compile and link, then I will know that you didn't take advantage of this information, and your grade will be a zero.
  2. Don't just assume that your code works without testing it.
  3. Don't just assume that your code works without testing it.
  4. Don't just assume that your code works without testing it.
  5. Turn in just your functions.
  6. Don't give me any main program, #includes, #defines, or print statements.
  7. Use GLM to handle all your matrix and transformation work. Don't write your own matrix multiply function, for example.
  8. Don't be concerned with how GLM stores the matrices internally. Just use GLM to get the information in and get the information out.

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!

How to Reassure Yourself That You Will Get Full Credit

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):

g++ proj02.cpp test02.o -o proj02
./proj02

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++.)
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.

Turn-In

  1. Your electronic turnin will be done at http://engr.oregonstate.edu/teach and will consist of:
  2. Your source file consisting of just your functions.
This is due at 23:59:59 on the listed due date.

Grading

If your code does not compile, then your grade for this project is a zero!

FeaturePoints
Multiply ( mat4*mat4 )20
Multiply( mat4*vec3 )20
ScalePointAroundAnotherPoint20
RotatePoint20
TOTAL80