CS 491 -- Fall Quarter 2022

Project #1: Using GLM to manipulate 3D Vectors

60 Points

Due: October 4


This page was last updated: September 29, 2022


Requirements

As we discussed in class, GLM is a set of math functions to manipulate 3D vectors and matrices. You are to create a GLM-based C++ program that allows you to perform certain operations on 3-element vectors (vec3).

Here is a short GLM primer

Start by downloading the file glm.zip if you are using Windows, or glm.tar if you are using Linux. Un-zip or un-tar ("tar xvf glm.tar") this file in whatever folder you are using to develop the project in. It will create a sub-folder called glm.

Then, write a main program that you will use to test your functions. Place these #includes and #defines at the top of it.


#include <stdio.h>
#include <string>
#define _USE_MATH_DEFINES
#include <cmath>

#define GLM_FORCE_RADIANS
#include "glm/vec2.hpp"
#include "glm/vec3.hpp"
#include "glm/mat4x4.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/matrix_inverse.hpp"

Your Functions

To prove that you know how to use GLM to accomplish useful vector functionality, you will create the following functions:

  1. glm::vec3 WhatPartOfALivesInBDir( glm::vec3 a, glm::vec3 b )
  2. glm::vec3 WhatPartOfALivesPerpToB( glm::vec3 a, glm::vec3 b )
  3. glm::vec3 UnitSurfaceNormal( glm::vec3 q, glm::vec3 r, glm::vec3 s )
  4. float Area( glm::vec3 q, glm::vec3 r, glm::vec3 s )
  5. bool IsPointInTriangle( glm::vec3 q, glm::vec3 r, glm::vec3 s, glm::vec3 p )
  6. float DistanceFromPointToPlane( glm::vec3 q, glm::vec3 r, glm::vec3 s, glm::vec3 p )
  7. void WhoAmI( std::string &yourName, std::string &yourEmailAddress )

Telling Me Who You Are

In order for me to find out who submitted this project, I will rely on you telling me. Create your WhoAmI( ) function exactly like this:

void
WhoAmI( std::string &yourName, std::string &yourEmailAddress )
{
        yourName = "Joe Graphics";
        yourEmailAddress = "jgraphics@oregonstate.edu" ;
}
except use your name and ONID login.

A Program Template

vectortemplate.cpp

A Visual Studio Solution

VectorProject.zip

Un-zip and double-click on the .sln file, then select Build→Clean Solution, then select Build→Build VectorProject, then select Debug→Start Without Debugging

A Linux Solution

VectorProject.tar

Un-tar this folder by saying tar xvf VectorProject.tar, then cd VectorProject, then type make, then type ./vectortemplate

Grading

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

I will link your functions with my own main program which will use some input values that 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.engr.oregonstate.edu. The commands to compile and run are:

g++  -o proj01   proj01.cpp 
./proj01

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 vector work. Don't write your own dot product function, for example.
  8. Don't be concerned with how GLM stores the vector internally. Just use GLM to get the information in and get the information out.

How to Reassure Yourself That You Will Get Full Credit

Click here to get the test01.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 proj01.cpp):

g++ proj01.cpp test01.o -o proj01
./proj01

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 test01B.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 proj01.cpp):

g++ proj01.cpp test01B.o -o proj01
./proj01

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 must not have 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 test01.o or when you turn in your .cpp file. In those two cases, I am providing the main( ) program.

Turn-In

Your electronic turnin will be done at http://engr.oregonstate.edu/teach and will consist of:

  1. Your source consisting of just your functions in a single .cpp file

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
WhatPartOfALivesInBDir10
WhatPartOfALivesPerpToB10
UnitSurfaceNormal10
Area10
IsPointInTriangle10
DistanceFromPointToPlane10
TOTAL60