3dphotoshoot

annotate src/game.c @ 0:a4bf2687e406

3d photoshoot initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 12 May 2015 05:31:21 +0300
parents
children 38377f54527a
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <math.h>
nuclear@0 4 #include "opengl.h"
nuclear@0 5 #include "game.h"
nuclear@0 6
nuclear@0 7 static int win_width, win_height;
nuclear@0 8
nuclear@0 9
nuclear@0 10 int game_init(void)
nuclear@0 11 {
nuclear@0 12 glEnable(GL_DEPTH_TEST);
nuclear@0 13 glEnable(GL_CULL_FACE);
nuclear@0 14 glEnable(GL_LIGHTING);
nuclear@0 15
nuclear@0 16 glClearColor(0.4, 0.4, 0.4, 1);
nuclear@0 17 return 0;
nuclear@0 18 }
nuclear@0 19
nuclear@0 20 void game_shutdown(void)
nuclear@0 21 {
nuclear@0 22 }
nuclear@0 23
nuclear@0 24 void game_display(unsigned long msec)
nuclear@0 25 {
nuclear@0 26 float tsec = (float)msec / 1000.0f;
nuclear@0 27
nuclear@0 28 glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
nuclear@0 29 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@0 30
nuclear@0 31 glMatrixMode(GL_MODELVIEW);
nuclear@0 32 glLoadIdentity();
nuclear@0 33 }
nuclear@0 34
nuclear@0 35 void game_reshape(int x, int y)
nuclear@0 36 {
nuclear@0 37 win_width = x;
nuclear@0 38 win_height = y;
nuclear@0 39 glViewport(0, 0, x, y);
nuclear@0 40
nuclear@0 41 glMatrixMode(GL_PROJECTION);
nuclear@0 42 glLoadIdentity();
nuclear@0 43 glScalef((float)win_height / (float)win_width, 1.0, 1.0);
nuclear@0 44 }
nuclear@0 45
nuclear@0 46 void game_keyboard(int key, int pressed)
nuclear@0 47 {
nuclear@0 48 if(!pressed) return;
nuclear@0 49
nuclear@0 50 switch(key) {
nuclear@0 51 case 27:
nuclear@0 52 exit(0);
nuclear@0 53
nuclear@0 54 default:
nuclear@0 55 break;
nuclear@0 56 }
nuclear@0 57 }
nuclear@0 58
nuclear@0 59 #define MAX_TOUCH_IDS 16
nuclear@0 60 static struct {
nuclear@0 61 int bnstate[8];
nuclear@0 62 int prev_x, prev_y;
nuclear@0 63 } mstate[MAX_TOUCH_IDS];
nuclear@0 64
nuclear@0 65 void game_mouse_button(int id, int bn, int pressed, int x, int y)
nuclear@0 66 {
nuclear@0 67 if(id >= MAX_TOUCH_IDS) return;
nuclear@0 68
nuclear@0 69 mstate[id].prev_x = x;
nuclear@0 70 mstate[id].prev_y = y;
nuclear@0 71 mstate[id].bnstate[bn] = pressed;
nuclear@0 72 }
nuclear@0 73
nuclear@0 74 void game_mouse_motion(int id, int x, int y)
nuclear@0 75 {
nuclear@0 76 /*
nuclear@0 77 int dx, dy, cx, cy;
nuclear@0 78
nuclear@0 79 if(id >= MAX_TOUCH_IDS) return;
nuclear@0 80
nuclear@0 81 cx = win_width / 2;
nuclear@0 82 cy = win_height / 2;
nuclear@0 83
nuclear@0 84 dx = x - mstate[id].prev_x;
nuclear@0 85 dy = y - mstate[id].prev_y;
nuclear@0 86 mstate[id].prev_x = x;
nuclear@0 87 mstate[id].prev_y = y;
nuclear@0 88
nuclear@0 89 if(!dx && !dy) return;
nuclear@0 90
nuclear@0 91 if(mouselook || mstate[id].bnstate[0]) {
nuclear@0 92 player_turn(&player, dx * 0.5, dy * 0.5);
nuclear@0 93 }
nuclear@0 94 if(mstate[id].bnstate[2]) {
nuclear@0 95 dbg_cam_dist += 0.1 * dy;
nuclear@0 96 if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0;
nuclear@0 97 }
nuclear@0 98
nuclear@0 99 if(mouselook) {
nuclear@0 100 warping_mouse = 1;
nuclear@0 101 set_mouse_pos(cx, cy);
nuclear@0 102 mstate[id].prev_x = cx;
nuclear@0 103 mstate[id].prev_y = cy;
nuclear@0 104 }
nuclear@0 105 */
nuclear@0 106 }
nuclear@0 107