conworlds
diff src/game.cc @ 15:9b0db7dbde6e
hmmm doesn't work properly yes
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 24 Aug 2014 14:36:00 +0300 |
parents | 283cdfa7dda2 |
children | 7a2041ddb7e7 e4257df067a1 |
line diff
1.1 --- a/src/game.cc Sun Aug 24 09:43:58 2014 +0300 1.2 +++ b/src/game.cc Sun Aug 24 14:36:00 2014 +0300 1.3 @@ -1,3 +1,4 @@ 1.4 +#include <math.h> 1.5 #include "game.h" 1.6 #include "gameopt.h" 1.7 #include "opengl.h" 1.8 @@ -8,6 +9,9 @@ 1.9 static void game_render_eye(int eye); 1.10 static void draw_scene(); 1.11 static bool setup_rtarg(int x, int y); 1.12 +static void draw_box(float sz); 1.13 +static void draw_pyramid(float basesz, float height); 1.14 + 1.15 1.16 static Texture *rtarg; 1.17 static unsigned int fbo, rtarg_depth; 1.18 @@ -143,9 +147,11 @@ 1.19 if(eye == 0 || !vr_view_matrix(eye < 0 ? 0 : 1, mat)) { 1.20 glLoadIdentity(); 1.21 } else { 1.22 - glLoadMatrixf(mat); 1.23 + glLoadIdentity(); 1.24 + //glLoadMatrixf(mat); 1.25 } 1.26 glMultTransposeMatrixf(view_matrix[0]); 1.27 + glMultMatrixf(mat); 1.28 1.29 draw_scene(); 1.30 } 1.31 @@ -258,27 +264,7 @@ 1.32 for(int i=0; i<4; i++) { 1.33 glPushMatrix(); 1.34 glTranslatef(i & 1 ? -10 : 10, 0, i & 2 ? -10 : 10); 1.35 - glScalef(2.0, 2.0, 2.0); 1.36 - 1.37 - glBegin(GL_TRIANGLES); 1.38 - glNormal3f(0, 1, 1); 1.39 - glVertex3f(-1, 0, 1); 1.40 - glVertex3f(1, 0, 1); 1.41 - glVertex3f(0, 1.75, 0); 1.42 - glNormal3f(1, 1, 0); 1.43 - glVertex3f(1, 0, 1); 1.44 - glVertex3f(1, 0, -1); 1.45 - glVertex3f(0, 1.75, 0); 1.46 - glNormal3f(0, 1, -1); 1.47 - glVertex3f(1, 0, -1); 1.48 - glVertex3f(-1, 0, -1); 1.49 - glVertex3f(0, 1.75, 0); 1.50 - glNormal3f(-1, 1, 0); 1.51 - glVertex3f(-1, 0, -1); 1.52 - glVertex3f(-1, 0, 1); 1.53 - glVertex3f(0, 1.75, 0); 1.54 - glEnd(); 1.55 - 1.56 + draw_pyramid(2.0, 2.0); 1.57 glPopMatrix(); 1.58 } 1.59 } 1.60 @@ -314,3 +300,68 @@ 1.61 printf("created render target %dx%d (texture: %dx%d)\n", x, y, tex_width, tex_height); 1.62 return true; 1.63 } 1.64 + 1.65 +static void draw_box(float sz) 1.66 +{ 1.67 + float hsz = sz / 2.0; 1.68 + 1.69 + glBegin(GL_QUADS); 1.70 + glNormal3f(0, 0, 1); 1.71 + glVertex3f(-hsz, -hsz, hsz); 1.72 + glVertex3f(hsz, -hsz, hsz); 1.73 + glVertex3f(hsz, hsz, hsz); 1.74 + glVertex3f(-hsz, hsz, hsz); 1.75 + glNormal3f(1, 0, 0); 1.76 + glVertex3f(hsz, -hsz, hsz); 1.77 + glVertex3f(hsz, -hsz, -hsz); 1.78 + glVertex3f(hsz, hsz, -hsz); 1.79 + glVertex3f(hsz, hsz, hsz); 1.80 + glNormal3f(0, 0, -1); 1.81 + glVertex3f(hsz, -hsz, -hsz); 1.82 + glVertex3f(-hsz, -hsz, -hsz); 1.83 + glVertex3f(-hsz, hsz, -hsz); 1.84 + glVertex3f(hsz, hsz, -hsz); 1.85 + glNormal3f(-1, 0, 0); 1.86 + glVertex3f(-hsz, -hsz, -hsz); 1.87 + glVertex3f(-hsz, -hsz, hsz); 1.88 + glVertex3f(-hsz, hsz, hsz); 1.89 + glVertex3f(-hsz, hsz, -hsz); 1.90 + glNormal3f(0, 1, 0); 1.91 + glVertex3f(-hsz, hsz, hsz); 1.92 + glVertex3f(hsz, hsz, hsz); 1.93 + glVertex3f(hsz, hsz, -hsz); 1.94 + glVertex3f(-hsz, hsz, -hsz); 1.95 + glNormal3f(0, -1, 0); 1.96 + glVertex3f(-hsz, -hsz, -hsz); 1.97 + glVertex3f(hsz, -hsz, -hsz); 1.98 + glVertex3f(hsz, -hsz, hsz); 1.99 + glVertex3f(-hsz, -hsz, hsz); 1.100 + glEnd(); 1.101 +} 1.102 + 1.103 +static void draw_pyramid(float basesz, float height) 1.104 +{ 1.105 + float hsz = basesz / 2.0; 1.106 + float theta = atan(hsz / height); 1.107 + float nx = cos(theta); 1.108 + float ny = sin(theta); 1.109 + 1.110 + glBegin(GL_TRIANGLES); 1.111 + glNormal3f(0, ny, nx); 1.112 + glVertex3f(-hsz, 0, hsz); 1.113 + glVertex3f(hsz, 0, hsz); 1.114 + glVertex3f(0, height, 0); 1.115 + glNormal3f(nx, ny, 0); 1.116 + glVertex3f(hsz, 0, hsz); 1.117 + glVertex3f(hsz, 0, -hsz); 1.118 + glVertex3f(0, height, 0); 1.119 + glNormal3f(0, ny, -nx); 1.120 + glVertex3f(hsz, 0, -hsz); 1.121 + glVertex3f(-hsz, 0, -hsz); 1.122 + glVertex3f(0, height, 0); 1.123 + glNormal3f(-nx, ny, 0); 1.124 + glVertex3f(-hsz, 0, -hsz); 1.125 + glVertex3f(-hsz, 0, hsz); 1.126 + glVertex3f(0, height, 0); 1.127 + glEnd(); 1.128 +} 1.129 \ No newline at end of file