CPSC362A
Video Game Development

Project Part 5

Collisions

Add collision detection to the game object classes.

Details

The GameObject class should be updated so that it:

  1. has protected member data to represent a bounding box that is axis-aligned in the game object’s local coordinate space:

    1. glm::vec3 bounding_box_min the minimum x, y, and z values, in local coordinate space, of the game object’s bounding box

    2. glm::vec3 bounding_box_max the maximum x, y, and z values, in local coordinate space, of the game object’s bouding box.

  2. defines the method void SetBoundingBox(glm::vec3 minimum, glm::vec3:: maximum) that sets the game object’s bounding box to the specified minimum and maximum values in the game object’s local coordinate space.

  3. defines the method bool Intersects(glm::vec3 point) const that returns whether the specified point, in the global coordinate space, itersects with the game object’s bounding box. A point intersects with a box if it is touching the box or inside the box.

The RigidBody class’s constructor should be updated so that it sets its bounding box to the smallest axis-aligned bounding box that fits its model.

The Camera class’s constructor should be updated so that it sets its bounding box a bounding box with no volume, at the origin.

Your code can use any library in the C++ Standard Library and the OpenGL Mathematics Library.

Your code should be clean, readable, and efficient. Follow the Google C++ Style Guide for help with style. Use the cpplint tool to help check your code.

All classes should be declared inside of a namespace called engine.

Your project should have the following directory structure:

project
├──data
|  ├──model1.obj
|  ├──model2.obj
|  ├──model3.obj
|  └──...
├──makefile
├──lib
|  └──glm
|     ├──gtc
|     ├──gtx
|     └──vec3.hpp
|     └──...
├──src
|  └──engine
|     ├──camera.cc
|     ├──camera.h
|     ├──game_object.cc
|     ├──game_object.h
|     ├──light.cc
|     ├──light.h
|     ├──model.cc
|     ├──model.h
|     ├──rigid_body.cc
|     └──rigid_body.h
└──test
   ├──test1.cc
   ├──test2.cc
   ├──test3.cc
   └──...

Your project should compile and run with this makefile.

Example

#include <iostream>
#include <cassert>

#include "engine/model.h"
#include "engine/rigid_body.h"

int main() {
  engine::Model model("data/model.obj");
  engine::RigidBody rigidBody(&model);
  glm::vec3 point_in_model(0.0f, 0.0f, 0.0f);
  glm::vec3 point_not_in_model(0.0f, 0.0f, 100.0f);
  assert(rigidBody.Intersects(point_in_model));
  assert(!rigidBody.Intersects(point_not_in_model));
  std::cout << "All assertions passed!" << std::endl;
  exit(EXIT_SUCCESS);
}

Grading

The functionality of your code will be graded according to the following point scale:

1 game object intersect method is correct for an untransformed game object 50 points
2 game object intersect method is correct for a translated game object 15 points
3 game object intersect method is correct for a rotated game object 15 points
4 game object intersect method is correct for a rotated and translated game object 15 points
5 game object intersect method is correct for a set bounding box 5 points


The final grade for this part of the project will be computed as:

const double final_score = fmin(fmax(functionality_score - (days_late / 7.0 * 100.0), 0.0), 125.0);

Submission

Submit a .zip file with the following structure and contents:

username
├──camera.cc
├──camera.h
├──game_object.cc
├──game_object.h
├──light.cc
├──light.h
├──model.cc
├──model.h
├──rigid_body.cc
└──rigid_body.h

where username is your cpsc user name.

Submit your .zip file on Inquire on Friday, April 17th.