This page was last updated: January 18, 2023
The objective of Project #2 is to load an OBJ file and perform a keytime animation with it.
vkuloadObjFile.h |
vkuLoadObjFile.cpp |
vkuKeytime.h |
vkuKeytime.cpp |
Sample2019-P2.zip |
In the sample.cpp file, put these lines after the MyBuffer struct has been defined:
#include "vkuLoadObjFile.h" #include "vkuKeytime.h"Put these lines at the end of the sample.cpp file:
#include "vkuLoadObjFile.cpp" #include "vkuKeytime.cpp"
MyBuffer MyVertexDataBuffer; // global -- already in the sample program . . . // this goes in InitGraphics( ): MyVertexDataBuffer = VkuLoadObjFile((char *)"cow.obj"); // comment out or delete these lines: //Init05MyVertexDataBuffer( sizeof(VertexData), &MyVertexDataBuffer ); //Fill05DataBuffer( MyVertexDataBuffer, (void *) VertexData ); //Init05MyVertexDataBuffer( sizeof(JustVertexData), &MyJustVertexDataBuffer ); //Fill05DataBuffer( MyJustVertexDataBuffer, (void *) JustVertexData ); //Init05MyIndexDataBuffer( sizeof(JustIndexData), &MyJustIndexDataBuffer ); //Fill05DataBuffer( MyJustIndexDataBuffer, (void *) JustIndexData );
The smooth interpolation technique that you will be using employs a piecewise cubic curve. Normally this type of curve requires you to enter slopes. But, rather than you having to specify the slopes, this technique makes a reasonable approximation of them based on the surrounding keytime information.
The methods for the Keytimes class are:
void AddTimeValue( float time, float value );
float GetFirstTime( );
float GetLastTime( );
int GetNumKeytimes( );
float GetValue( float time );
void PrintTimeValues( );
Set the values like this:
// global variables:
Keytimes Xpos, Ypos, Zpos;
Keytimes ThetaX, ThetaY, ThetaZ;
Keytimes ScaleXYZ; // i used uniform scaling, you don't have to
. . .
// at the bottom of InitGraphics( ):
ScaleXYZ.AddTimeValue( 0.f, 1.f);
ScaleXYZ.AddTimeValue( 7.5f, 0.25f);
ScaleXYZ.AddTimeValue(15.f, 1.f);
ScaleXYZ.AddTimeValue(22.5f, 2.f);
ScaleXYZ.AddTimeValue(30.f, 1.f);
ThetaX.AddTimeValue(0.0f, 0.0f);
ThetaX.AddTimeValue(5.f, glm::radians(720.f));
ThetaX.AddTimeValue(10.f, glm::radians(0.f));
ThetaX.AddTimeValue(20.f, glm::radians(-720.f));
ThetaX.AddTimeValue(30.f, glm::radians(0.f));
ThetaY.AddTimeValue(0.0f, 0.0f);
ThetaY.AddTimeValue(30.f, glm::radians(10.f*360.f+180.f));
. . .
Right now, in your sample code, the global variable Time just keeps increasing. But, it would be better to get Time to repeat. So, consider doing something like this:
#define MAXSECONDS 30. . . . Time = glfwGetTime( ); // this is already in main( ) Time = fmod( Time, MAXSECONDS ); // add this
The C fmod( ) function divides Time by MAXSECONDS and give you back the remainder of that division. Thus, Time will always be between 0. and MAXSECONDS.
At the fmod'ed Time, sample the GetValue( ) method for each variable. Using GLM calls, produce a glm::mat4 from that and pass it over as the uObjectModel for the object you are about to draw, something like this. Put this at the end of the UpdateScene( ) function.
float time = (float)Time; Object.uModel = glm::mat4(1.); // identity Object.uModel = glm::rotate(Object.uModel, ThetaX.GetValue(time), glm::vec3(1.f, 0.f, 0.f)); Object.uModel = glm::rotate(Object.uModel, ThetaY.GetValue(time), glm::vec3(0.f, 1.f, 0.f)); Object.uModel = glm::scale(Object.uModel, glm::vec3(ScaleXYZ.GetValue(time))); Object.uNormal = glm::mat4(glm::inverseTranspose(glm::mat3(Scene.uSceneOrient*Object.uModel))); Object.uColor = glm::vec4( 1.f, 0.2f, 0.2f, 1.f ); Object.uShininess = 32.f; Fill05DataBuffer( MyObjectUniformBuffer, (void *) &Object );In your video, somehow demonstrate that this all works.
'l' (ell) | Toggle lighting on and off |
'm' | Toggle display mode (textures vs. colors) |
'p' | Pause/resume the animation |
'r' | Toggle allowing the mouse to rotate and scale the animating scene |
Esc, 'q' | Exit the program |
Feel free to add more keyboard inputs to control more aspects of the display if you want.
Use Teach to turn in your:
Feature | Points |
---|---|
An OBJ object displays, but doesn't animate | 40 |
At least 6 quantities are animated | 30 |
Each quantity has at least 8 key-times | 30 |
Potential Total | 100 |