# HG changeset patch # User John Tsiombikas # Date 1362124013 -7200 # Node ID 603db903160023ebeaa4801d8caa027dd554d3ac # Parent e9db1d0c09b3deb697c49fe62350fa7bb2952970 added an example program diff -r e9db1d0c09b3 -r 603db9031600 example/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/Makefile Fri Mar 01 09:46:53 2013 +0200 @@ -0,0 +1,19 @@ +src = $(wildcard *.c) +obj = $(src:.c=.o) +bin = test + +CFLAGS = -pedantic -Wall -g -I../src +LDFLAGS = -L.. -lanim -lvmath $(libgl) -lm + +ifeq ($(shell uname -s), Darwin) + libgl = -framework OpenGL -framework GLUT +else + libgl = -lGL -lGLU -lglut +endif + +$(bin): $(obj) ../libanim.a + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff -r e9db1d0c09b3 -r 603db9031600 example/test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/example/test.c Fri Mar 01 09:46:53 2013 +0200 @@ -0,0 +1,276 @@ +#include +#include +#include + +#ifndef __APPLE__ +#include +#else +#include +#endif + +#include +#include "anim.h" + +struct body_part { + vec3_t pos, pivot, sz, color; +} parts[] = { + /* position pivot size color */ + {{0, 1, 0}, {0, -1, 0}, {1.8, 2.8, 0.8},{1, 0, 1}}, /* torso */ + + {{-0.5, -2.5, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {1, 0, 0}}, /* left-upper leg */ + {{0.5, -2.5, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {0, 1, 0}}, /* right-upper leg */ + + {{0, -2.1, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {1, 0.5, 0.5}}, /* left-lower leg */ + {{0, -2.1, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {0.5, 1, 0.5}}, /* right-lower leg */ + + {{0, 2.6, 0}, {0, -0.5, 0}, {1.2, 1.2, 1.2},{0, 1, 1}}, /* head */ + + {{-1.3, 0.4, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {0, 0, 1}}, /* left-upper arm */ + {{1.3, 0.4, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {1, 1, 0}}, /* right-upper arm */ + + {{0, -2.1, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {0.5, 0.5, 1}}, /* left-lower arm */ + {{0, -2.1, 0}, {0, 1, 0}, {0.8, 2, 0.8}, {1, 1, 0.5}}, /* right-lower arm */ +}; + +enum { + NODE_TORSO, + NODE_LEFT_UPPER_LEG, + NODE_RIGHT_UPPER_LEG, + NODE_LEFT_LOWER_LEG, + NODE_RIGHT_LOWER_LEG, + NODE_HEAD, + NODE_LEFT_UPPER_ARM, + NODE_RIGHT_UPPER_ARM, + NODE_LEFT_LOWER_ARM, + NODE_RIGHT_LOWER_ARM, + + NUM_NODES +}; + +int init(void); +void disp(void); +void idle(void); +void reshape(int x, int y); +void keyb(unsigned char key, int x, int y); +void mouse(int bn, int state, int x, int y); +void motion(int x, int y); + +float cam_theta = 20, cam_phi = 20, cam_dist = 15; +struct anm_node *root; + +struct anm_node *nodes[NUM_NODES]; + +int main(int argc, char **argv) +{ + glutInitWindowSize(800, 600); + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + glutCreateWindow("libanim example"); + + glutDisplayFunc(disp); + glutIdleFunc(idle); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyb); + glutMouseFunc(mouse); + glutMotionFunc(motion); + + if(init() == -1) { + return 1; + } + glutMainLoop(); + return 0; +} + +int init(void) +{ + int i; + + glPointSize(3); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + root = nodes[0]; + + for(i=0; i 90) { + cam_phi = 90; + } + glutPostRedisplay(); + } + if(bnstate[2]) { + cam_dist += dy * 0.1; + if(cam_dist < 0.0) { + cam_dist = 0.0; + } + glutPostRedisplay(); + } +}