vrheights
changeset 6:608e03b688f8
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 30 Sep 2014 18:57:20 +0300 |
parents | 053a52f0cb64 |
children | 0eca023ed909 |
files | src/game.cc |
diffstat | 1 files changed, 53 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/src/game.cc Fri Sep 26 18:40:15 2014 +0300 1.2 +++ b/src/game.cc Tue Sep 30 18:57:20 2014 +0300 1.3 @@ -1,5 +1,6 @@ 1.4 #include <stdio.h> 1.5 #include <assert.h> 1.6 +#include <vector> 1.7 #include <algorithm> 1.8 #include <vmath/vmath.h> 1.9 #include "opengl.h" 1.10 @@ -14,6 +15,7 @@ 1.11 static void toggle_hmd_fullscr(); 1.12 static void create_rtarg(int x, int y); 1.13 static int next_pow2(int x); 1.14 +static void con_handle(const char *cmd); 1.15 1.16 bool opt_separate_walk_look; 1.17 1.18 @@ -58,9 +60,10 @@ 1.19 fprintf(stderr, "failed to open console font\n"); 1.20 return false; 1.21 } 1.22 - con.set_size(6, 40); 1.23 con.set_font(con_font, 14); 1.24 + con.set_size(7, 40); 1.25 con.set_position(0, 0, Console::CENTER); 1.26 + con.set_command_func(con_handle); 1.27 1.28 return true; 1.29 } 1.30 @@ -103,6 +106,11 @@ 1.31 cam_pos.z += dir.x * sin_theta + dir.z * cos_theta; 1.32 1.33 if(!opt_separate_walk_look) { 1.34 + float rot[4]; 1.35 + vr_view_rotation(0, rot); 1.36 + Quaternion q(rot[3], rot[0], rot[1], rot[2]); 1.37 + 1.38 + cam_pos.transform(q); 1.39 } 1.40 } 1.41 1.42 @@ -362,3 +370,47 @@ 1.43 x |= x >> 16; 1.44 return x + 1; 1.45 } 1.46 + 1.47 +static const char *strip_spaces(const char *str) 1.48 +{ 1.49 + while(*str && isspace(*str)) str++; 1.50 + return str; 1.51 +} 1.52 + 1.53 +static void con_handle(const char *cmd) 1.54 +{ 1.55 + std::vector<char*> argv; 1.56 + cmd = strip_spaces(cmd); 1.57 + 1.58 + if(!*cmd || *cmd == '#') { 1.59 + return; 1.60 + } 1.61 + 1.62 + char *line = (char*)alloca(strlen(cmd) + 1); 1.63 + strcpy(line, cmd); 1.64 + 1.65 + char *tok = 0; 1.66 + while((tok = strtok(tok ? 0 : line, " \t\v\n\r"))) { 1.67 + argv.push_back(tok); 1.68 + } 1.69 + 1.70 + if(strcmp(argv[0], "set") == 0) { 1.71 + if(argv.size() < 3) { 1.72 + fprintf(stderr, "set must be followed by 2 arguments\n"); 1.73 + return; 1.74 + } 1.75 + if(strcmp(argv[1], "separate-walk") == 0) { 1.76 + if(strcmp(argv[2], "true") == 0) { 1.77 + opt_separate_walk_look = true; 1.78 + } else if(strcmp(argv[2], "false") == 0) { 1.79 + opt_separate_walk_look = false; 1.80 + } 1.81 + } else { 1.82 + con.printf("unknown option: %s\n", argv[1]); 1.83 + } 1.84 + } else if(strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "quit") == 0) { 1.85 + exit_game(); 1.86 + } else { 1.87 + con.printf("invalid command: %s\n", argv[0]); 1.88 + } 1.89 +}