Language: Visual C++
API: GLUT, SOIL
Platform: Windows
Workload: 150 hours
Year/Semester: 2nd/1st
Module: Graphics Programming (2nd year)
​​Project made in Visual Studio 2015 and based on the framework provided by
the module tutor Dr Paul Robertson.
Follow @matzar Star Fork Download

Overview

In this project I have focused on procedurally generated shapes while utilising various OpenGL techniques like: lighting, transparency, planar shadows, stencil buffer, texturing and texture filtering. As well as 3 different cameras; FPP camera, which allows unrestricted movement, in any direction, around the scene with mouse and keyboard control, top down camera (GTA like) and fixed-security camera. All three cameras inherit from a virtual ‘Camera’ class which allows for a single camera call in the ‘Scene’ class and easy switching between them. Also, makes adding different types of cameras, easier.

Camera setting

// scene header file
Camera \*camera;
FreeCamera freeCamera;
SecurityCamera securityCamera;
TopDownCamera topDownCamera;

// user input
// if 1 pressed
camera = &freeCamera;
// if 2 pressed
camera = &securityCamera;
// if 3 pressed
camera = &topDownCamera;

// set the camera
gluLookAt(camera->getPositionX(), camera->getPositionY(), camera->getPositionZ(),
camera->getLookAtX(), camera->getLookAtY(), camera->getLookAtZ(),
camera->getUpX(), camera->getUpY(), camera->getUpZ());

Procedural Shape Generation

The ‘Shape’ class handles all procedural shape generation and rendering functions. All shapes in the scene are procedurally generated and textured using UV coordinates of one texture only for each shape. This proved some challenges especially when it came to UV texturing of a cylinder but in the end I was really pleased with the result and managed to map all shapes with one texture. And all shapes are rendered with triangle primitives. The ‘Shape’ class allows for a procedural generation of the following shapes: a sphere, a cylinder, a cone, a disk, a torus and a butterfly curve. Here’s an example of a shape building function call and its render function call.

Camera setting

Shape sphere;

sphere.buildSphere(GL_TRIANGLES, // primitive
0.5f, 5.0f, 5.0f, // radius, latitude, longitude
Vector3(0.0f, 2.0f, 0.0f), // translate x, translate y, translate z,
Vector3(1.0f, 1.0f, 1.0f), // scale x, scale y, scale z,
Vector4(0.0, 0.0, 1.0, 0.0), // rotation angle, rotation x, rotation y, rotation z
Vector4(1.0f, 1.0f, 1.0f, 1.0f), // red, green, blue, alpha colour
earth_tex); // texture
sphere.render();

This way of building shapes, which puts all vertices, normals and texture coordinates into separate vectors of floats allows for a single rendering function call which uses drawing arrays.

Features

6 lights - 5 controllable by the user and 1 animated

3 cameras

Procedurally generated shapes

Solar system and use of

More

Instructions

You will start with a free camera which allows you to freely explore the scene. Use WSAD and mouse to control the free camera. Press 1 whenever you want to choose this camera.

Press 2 to switch to an automatic security camera. You can control it with WSAD when it is in an automatic mode or not. Press ‘C’ to toggle between the automatic mode.

Press 3 to switch to a top down camera. Use WSAD to control it.

Press keys F1, F2, F3, F4, F5, F6 to toggle lights 0 - 5 on and off. Light number 6 is an animated point light with medium attenuation and blue colour. Use Arrow Keys to control the lights. Press G or Page Up to move in the positive direction on the z axis. Press T or Page Down to move in the negative direction on the z axis.

Keys F6 to F12 control texture filtering which is applied only to the quad above the scene with the grass texture. ​ F1 - Light 0 - spot light in -y direction and 45.0 degree cut off

F2 - Light 1 - directional light in positive x direction

F3 - Light 2 - low attenuation light

F4 - Light 3 - point light

F5 - Light 4 - point light - medium attenuation - red colour

F6 - Light 5 - point light - medium attenuation - green colour

F7 - Toggle Point Sampling

F8 - Toggle Bilinear Filtering

F9 - Toggle Mipmapping Filtering

F10 - Toggle Half Mipmapping Filtering

F11 - Toggle Half Trilinear Filtering

F12 - Toggle Trilinear Filtering

B - toggle blend mode ​ M - toggle wireframe mode​

D, E, V (press at the same time) - hide/show UI