Animation in Graphics - Introduction

Download code base

Download any of these archive containing all the necessary codes
Notes on the requirements

Introductory scene

Information on the library (only general information, no exercise)

CGP library provides a set of functionalities to ease 3D graphics programming such as
Structures and functions of the library are accessible in the namespace cgp::

Use of the code library

First observe the file main.cpp. You should recognize the general organization of the program, in particular the setup stage, and the animation loop stage. Note where the two main methods scene.initialize() and scene.display_frame() are called, and their implementation in the file scene.cpp.
In the following you will only modify code in the file scene.cpp (and scene.hpp).

Adding a sphere

In this first part we display a new sphere to the scene.
cgp::mesh_drawable sphere; 
mesh sphere_mesh = mesh_primitive_sphere(0.5f);
sphere.initialize_data_on_gpu(sphere_mesh);
  • (or variant: simply in one line without explicitely storing the mesh variable)
sphere.initialize_data_on_gpu(mesh_primitive_sphere(0.5f));
draw(sphere, environment);
sphere.material.color = vec3(1+std::cos(time), 1+std::sin(time), 2.0)/2.0f;

Checkbox interface

We will now add a GUI checkbox (button that can be checked) to activate/deactivate the wireframe display of the sphere.
bool display_wireframe = false;
ImGui::Checkbox("Wireframe", &gui.display_wireframe);
The last step consists in adapting the behavior of the display.
	if (gui.display_wireframe)
		draw_wireframe(sphere, environment, { 1,1,0 });

Texture

Textures images can also be associated to surface
Note that the per-vertex uv coordinates need to be defined correctly to get the mapping of the image on the surface.
// Reset the color of the shape to white (only the texture image will be seen)
shape_visual.material.color = {1,1,1};

// Load the image and associate the texture id to the structure
shape_visual.texture.load_and_initialize_texture_2d_on_gpu(project::path+"assets/squirrel.jpg");