For todays lab your team will be taking your environment from last time and adding in a collidable, movable character. There will be three primary goals for this lab:
Sample code my be downloaded from here. You may work with your team.
Instructions for completing the first requirement can be found at end of lab 2.
To complete the second and third requirement you will need to use the Bullet SDK. Bullet is both a physics and collision detection library. Since this lab focuses only on detecting collisions, we will only need to utilize the collision detection portion of the library. The manual , API reference and demo source code should provide you with enough information to begin hacking away with Bullet. Also, to help get your up to speed, the starter code will outline each of the functions you will need use.
For the second portion of the lab you will need to allow your character to walk up inclines like ramps and other meshes that would appear climbable. To do this you will create a ray using Bullet. This ray should originate from the center of the character and shoot directly downwards. Bullet will then return to you the closest point of contact with the world geometry. Using this information you should then translate your character up or down so that he is now resting atop the geometry properly.
While this will work for most situations convincingly there is a still a problem. This algorithm will not ensure that our character only goes atop objects which appear climbable. We will fix this by checking if the closest intersection point is much higher or lower than the intersection point recorded last frame. If the difference is too large you should not allow your character to make the move.
The second requirement will guarantee that you character is able to climb geometry which appears climbable, however, it does not guarantee that the character will not pass through walls. We will remedy this by bounding the character with a cylinder about its mid section. To ensure that this volume does not interfere with the ground we will center it about the characters waist and keep its height about a quarter that of our characters total height. You can use the entities axis-aligned bounding box to determine where the middle is.
Once we have our cylinder collision object set up, we will simply check it each frame to determine if it is colliding with any world geometry. If the cylinder is colliding with any of the world meshes we will go ahead and move the character back to it's precolliding state (just like how we did it in part 2).
It really is that simple.