Skip to content

Instantly share code, notes, and snippets.

@davidwparker
Created November 24, 2011 18:00
Show Gist options
  • Select an option

  • Save davidwparker/1391933 to your computer and use it in GitHub Desktop.

Select an option

Save davidwparker/1391933 to your computer and use it in GitHub Desktop.
OpenGL Screencast 17: Animation part 2
#include "screencasts.h"
/*
* main()
* ----
* Start up GLUT and tell it what to do
*/
int main(int argc,char* argv[])
{
initializeGlobals();
/* screencast specific variables */
windowName = "OpenGL screenscasts 17: Animation part 2";
screencastID = 17;
toggleAxes = 0;
toggleAnimation = 0;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(windowWidth,windowHeight);
glutInitWindowPosition(450,350);
glutCreateWindow(windowName);
glutDisplayFunc(display);
glutReshapeFunc(displayReshape);
glutKeyboardFunc(windowKey);
glutSpecialFunc(windowSpecial);
initializeTextures();
initializeObjs();
timer(toggleAnimation);
redisplayAll();
glutMainLoop();
return 0;
}
#include "screencasts.h"
/*
* moveCube()
* ------
* Rotates a cube if animations are on
*/
void moveCube(void)
{
cubes[0].tsr.r.y = fmod(cubes[0].tsr.r.y+4.0,360.0);
}
/*
* moveLight()
* ------
* Moves the light if it is on
*/
void moveLight(void)
{
if (toggleLight) lightPh = (lightPh+2)%360;
}
/*
* timer()
* ------
* Timer called periodically
*/
void timer(int value)
{
if (toggleAnimation != DEF_ANIMATE_PAUSED) {
moveLight();
moveCube();
}
/*
* glutTimerFunc(millisecs, timerCallback, value)
* millisecs = how long until you want the callback to be called
* timerCallback = the function to be called when time is up
* value = can be used for whatever. I'm using it toggle the animation
*/
glutTimerFunc(20,timer,toggleAnimation);
redisplayAll();
}
/*
* initializeObjs(void)
* ------
* Initializes all of our objects
*/
void initializeObjs(void)
{
cube_s cb = {{{0,0,0},{2,2,2},{0,0,0}}};
cubes[0] = cb;
}
typedef struct point {
float x;
float y;
float z;
} point;
typedef struct tsr {
point t; /* translation */
point s; /* scale */
point r; /* rotation */
} tsr;
typedef struct cube_s {
tsr tsr;
} cube_s;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment