vrheights

diff src/game.cc @ 8:3f221bdc9bab

mesh loading walk polys
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 03 Oct 2014 04:16:16 +0300
parents 0eca023ed909
children df3a70664a7d
line diff
     1.1 --- a/src/game.cc	Wed Oct 01 01:06:55 2014 +0300
     1.2 +++ b/src/game.cc	Fri Oct 03 04:16:16 2014 +0300
     1.3 @@ -10,6 +10,7 @@
     1.4  #include "console.h"
     1.5  #include "drawtext.h"
     1.6  #include "game_var.h"
     1.7 +#include "scenefile.h"
     1.8  
     1.9  static void draw_scene();
    1.10  static void material(float r, float g, float b, float roughness);
    1.11 @@ -26,19 +27,33 @@
    1.12  
    1.13  static unsigned int chess_tex;
    1.14  
    1.15 -static float cam_theta, cam_phi;
    1.16 -static Vector3 cam_pos;
    1.17 +static float cam_theta = -90, cam_phi;
    1.18 +static Vector3 cam_pos = {15.4, 0, 0};
    1.19  static bool keystate[256];
    1.20  
    1.21  static Console con;
    1.22  static dtx_font *con_font;
    1.23  
    1.24 -#define OPT_LOOK_WALK	"look-walk"
    1.25 +static SceneFile scn;
    1.26 +
    1.27 +#define GVAR_LOOK_WALK	"look-walk"
    1.28 +#define GVAR_MAX_STEP	"max-step"
    1.29  
    1.30  bool game_init()
    1.31  {
    1.32  	init_opengl();
    1.33  
    1.34 +	if(!(con_font = dtx_open_font_glyphmap("data/mono14.glyphmap"))) {
    1.35 +		fprintf(stderr, "failed to open console font\n");
    1.36 +		return false;
    1.37 +	}
    1.38 +	con.set_font(con_font, 14);
    1.39 +	con.set_size(7, 52);
    1.40 +	con.set_position(0, 0, Console::CENTER);
    1.41 +	con.set_command_func(con_handle);
    1.42 +	con.set_echo(false);
    1.43 +
    1.44 +
    1.45  	if(vr_init() == -1) {
    1.46  		return false;
    1.47  	}
    1.48 @@ -57,18 +72,14 @@
    1.49  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    1.50  	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, chess_pixels);
    1.51  
    1.52 -	if(!(con_font = dtx_open_font_glyphmap("data/mono14.glyphmap"))) {
    1.53 -		fprintf(stderr, "failed to open console font\n");
    1.54 +	if(!scn.load("data/sibenik.goatsce")) {
    1.55 +		fprintf(stderr, "failed to load scene file\n");
    1.56  		return false;
    1.57  	}
    1.58 -	con.set_font(con_font, 14);
    1.59 -	con.set_size(7, 52);
    1.60 -	con.set_position(0, 0, Console::CENTER);
    1.61 -	con.set_command_func(con_handle);
    1.62 -	con.set_echo(false);
    1.63  
    1.64  	/* initialize all option variables */
    1.65 -	set_gvar_bool(OPT_LOOK_WALK, true);
    1.66 +	set_gvar_bool(GVAR_LOOK_WALK, true);
    1.67 +	set_gvar_num(GVAR_MAX_STEP, 0.5);
    1.68  
    1.69  	return true;
    1.70  }
    1.71 @@ -105,7 +116,7 @@
    1.72  		dir += Vector3(0, 0, offs);
    1.73  	}
    1.74  
    1.75 -	if(get_gvar_bool(OPT_LOOK_WALK)) {
    1.76 +	if(get_gvar_bool(GVAR_LOOK_WALK)) {
    1.77  		float rot[4];
    1.78  		vr_view_rotation(0, rot);
    1.79  		Quaternion q(rot[3], rot[0], rot[1], rot[2]);
    1.80 @@ -118,6 +129,8 @@
    1.81  	cam_pos.x += dir.x * cos_theta - dir.z * sin_theta;
    1.82  	cam_pos.z += dir.x * sin_theta + dir.z * cos_theta;
    1.83  
    1.84 +	float max_step = get_gvar_num(GVAR_MAX_STEP);
    1.85 +	cam_pos = scn.find_walk_pos(cam_pos + Vector3(0, max_step, 0));
    1.86  }
    1.87  
    1.88  void game_display()
    1.89 @@ -242,6 +255,8 @@
    1.90  	}
    1.91  }
    1.92  
    1.93 +MeshFace dbg_walk_face;
    1.94 +
    1.95  static void draw_scene()
    1.96  {
    1.97  	float lpos[][4] = {
    1.98 @@ -261,6 +276,7 @@
    1.99  
   1.100  	glMatrixMode(GL_MODELVIEW);
   1.101  
   1.102 +	/*
   1.103  	glBindTexture(GL_TEXTURE_2D, chess_tex);
   1.104  	glEnable(GL_TEXTURE_2D);
   1.105  	material(1, 1, 1, 1);
   1.106 @@ -272,14 +288,33 @@
   1.107  	glTexCoord2f(0, 1); glVertex3f(-10, 0, -10);
   1.108  	glEnd();
   1.109  	glDisable(GL_TEXTURE_2D);
   1.110 +	*/
   1.111  
   1.112 -	material(1, 1, 1, 0.4);
   1.113 +	/*material(1, 1, 1, 0.4);
   1.114  	glPushMatrix();
   1.115  	glTranslatef(0, 1.3, -10);
   1.116  	glFrontFace(GL_CW);
   1.117  	bezier_teapot(2.0);
   1.118  	glFrontFace(GL_CCW);
   1.119 -	glPopMatrix();
   1.120 +	glPopMatrix();*/
   1.121 +
   1.122 +	for(size_t i=0; i<scn.obj.size(); i++) {
   1.123 +		scn.obj[i]->draw();
   1.124 +	}
   1.125 +
   1.126 +	glPushAttrib(GL_ENABLE_BIT);
   1.127 +	glDisable(GL_DEPTH_TEST);
   1.128 +	glDisable(GL_LIGHTING);
   1.129 +
   1.130 +	glBegin(GL_TRIANGLES);
   1.131 +	glColor3f(0, 1, 0);
   1.132 +	glVertex3fv(&dbg_walk_face.v[0].x);
   1.133 +	glVertex3fv(&dbg_walk_face.v[1].x);
   1.134 +	glVertex3fv(&dbg_walk_face.v[2].x);
   1.135 +	glColor3f(1, 1, 1);
   1.136 +	glEnd();
   1.137 +
   1.138 +	glPopAttrib();
   1.139  }
   1.140  
   1.141  static void material(float r, float g, float b, float roughness)
   1.142 @@ -392,6 +427,11 @@
   1.143  
   1.144  static void con_handle(const char *cmd)
   1.145  {
   1.146 +	/* set debug values */
   1.147 +	set_gvar_num("cam-pos-x", cam_pos[0]);
   1.148 +	set_gvar_num("cam-pos-y", cam_pos[1]);
   1.149 +	set_gvar_num("cam-pos-z", cam_pos[2]);
   1.150 +
   1.151  	std::vector<char*> argv;
   1.152  	cmd = strip_spaces(cmd);
   1.153