coeng
changeset 0:14e743b53289
component system test
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 04 Feb 2015 17:23:35 +0200 |
parents | |
children | b0d8d454c546 |
files | src/comp.h src/comp_phys.h src/test.cc |
diffstat | 3 files changed, 133 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/comp.h Wed Feb 04 17:23:35 2015 +0200 1.3 @@ -0,0 +1,18 @@ 1.4 +#ifndef COMP_H_ 1.5 +#define COMP_H_ 1.6 + 1.7 +#include <vmath/vmath.h> 1.8 + 1.9 +class Component { 1.10 +public: 1.11 + Component() {} 1.12 + virtual ~Component() {} 1.13 +}; 1.14 + 1.15 +class CompPRS : public Component { 1.16 +public: 1.17 + Vector3 pos, scale; 1.18 + Quaternion rot; 1.19 +}; 1.20 + 1.21 +#endif // COMP_H_
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/comp_phys.h Wed Feb 04 17:23:35 2015 +0200 2.3 @@ -0,0 +1,20 @@ 2.4 +#ifndef COMP_PHYS_H_ 2.5 +#define COMP_PHYS_H_ 2.6 + 2.7 +#include <vmath/vmath.h> 2.8 +#include "comp.h" 2.9 + 2.10 +class CompRigid : public CompPRS { 2.11 +public: 2.12 + float mass, elast, friction; 2.13 + Vector3 pos, vel; 2.14 + 2.15 + CompRigid() 2.16 + { 2.17 + mass = 1.0; 2.18 + elast = 0.5; 2.19 + friction = 0.0; 2.20 + } 2.21 +}; 2.22 + 2.23 +#endif // COMP_PHYS_H_
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/test.cc Wed Feb 04 17:23:35 2015 +0200 3.3 @@ -0,0 +1,95 @@ 3.4 +#include <stdio.h> 3.5 +#include <stdlib.h> 3.6 +#include <assert.h> 3.7 + 3.8 +#ifndef __APPLE__ 3.9 +#include <GL/glut.h> 3.10 +#else 3.11 +#include <GLUT/glut.h> 3.12 +#endif 3.13 + 3.14 +static bool init(); 3.15 +static void cleanup(); 3.16 +static void display(); 3.17 +static void idle(); 3.18 +static void reshape(int x, int y); 3.19 +static void keyb(unsigned char key, int x, int y); 3.20 +static void mouse(int bn, int st, int x, int y); 3.21 +static void motion(int x, int y); 3.22 + 3.23 + 3.24 +int main(int argc, char **argv) 3.25 +{ 3.26 + glutInit(&argc, argv); 3.27 + glutInitWindowSize(800, 600); 3.28 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 3.29 + glutCreateWindow("component system test"); 3.30 + 3.31 + glutDisplayFunc(display); 3.32 + glutIdleFunc(idle); 3.33 + glutReshapeFunc(reshape); 3.34 + glutKeyboardFunc(keyb); 3.35 + glutMouseFunc(mouse); 3.36 + glutMotionFunc(motion); 3.37 + 3.38 + if(!init()) { 3.39 + return 1; 3.40 + } 3.41 + atexit(cleanup); 3.42 + 3.43 + glutMainLoop(); 3.44 + return 0; 3.45 +} 3.46 + 3.47 +static bool init() 3.48 +{ 3.49 + glEnable(GL_DEPTH_TEST); 3.50 + glEnable(GL_CULL_FACE); 3.51 + 3.52 + return true; 3.53 +} 3.54 + 3.55 +static void cleanup() 3.56 +{ 3.57 +} 3.58 + 3.59 +static void display() 3.60 +{ 3.61 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 3.62 + 3.63 + glutSwapBuffers(); 3.64 + assert(glGetError() == GL_NO_ERROR); 3.65 +} 3.66 + 3.67 +static void idle() 3.68 +{ 3.69 + glutPostRedisplay(); 3.70 +} 3.71 + 3.72 +static void reshape(int x, int y) 3.73 +{ 3.74 + glViewport(0, 0, x, y); 3.75 + 3.76 + glMatrixMode(GL_PROJECION); 3.77 + glLoadIdentity(); 3.78 + gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0); 3.79 +} 3.80 + 3.81 +static void keyb(unsigned char key, int x, int y) 3.82 +{ 3.83 + switch(key) { 3.84 + case 27: 3.85 + exit(0); 3.86 + } 3.87 +} 3.88 + 3.89 +static int bnstate[16]; 3.90 +static int prev_x, prev_y; 3.91 + 3.92 +static void mouse(int bn, int st, int x, int y) 3.93 +{ 3.94 +} 3.95 + 3.96 +static void motion(int x, int y) 3.97 +{ 3.98 +}