Created
November 24, 2011 18:00
-
-
Save davidwparker/1391933 to your computer and use it in GitHub Desktop.
OpenGL Screencast 17: Animation part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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