tavli

diff src/game.cc @ 22:c2a2069a49ec

slot highlighting, TODO blur
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 07 Jul 2015 21:56:37 +0300
parents c3fbf9616dbd
children
line diff
     1.1 --- a/src/game.cc	Thu Jul 02 00:01:39 2015 +0300
     1.2 +++ b/src/game.cc	Tue Jul 07 21:56:37 2015 +0300
     1.3 @@ -19,6 +19,8 @@
     1.4  bool wireframe;
     1.5  int dbg_int;
     1.6  
     1.7 +Ray pick_ray;
     1.8 +
     1.9  static Board board;
    1.10  
    1.11  static float cam_theta, cam_phi = 45, cam_dist = 3;
    1.12 @@ -289,13 +291,29 @@
    1.13  
    1.14  		if(cam_phi < -90) cam_phi = -90;
    1.15  		if(cam_phi > 90) cam_phi = 90;
    1.16 -
    1.17 -		redisplay();
    1.18  	}
    1.19  	if(bnstate[2]) {
    1.20  		cam_dist += dy * 0.1;
    1.21  		if(cam_dist < 0.0) cam_dist = 0.0;
    1.22 +	}
    1.23  
    1.24 -		redisplay();
    1.25 -	}
    1.26 +	// in all cases construct the global pick ray
    1.27 +	double viewmat[16], projmat[16];
    1.28 +	int vp[4], ysz;
    1.29 +	double px, py, pz;
    1.30 +
    1.31 +	glGetIntegerv(GL_VIEWPORT, vp);
    1.32 +	glGetDoublev(GL_MODELVIEW_MATRIX, viewmat);
    1.33 +	glGetDoublev(GL_PROJECTION_MATRIX, projmat);
    1.34 +
    1.35 +	ysz = vp[3] - vp[1];
    1.36 +
    1.37 +	gluUnProject(x, ysz - y, 0, viewmat, projmat, vp, &px, &py, &pz);
    1.38 +	pick_ray.origin = Vector3(px, py, pz);
    1.39 +	gluUnProject(x, ysz - y, 1, viewmat, projmat, vp, &px, &py, &pz);
    1.40 +	pick_ray.dir = Vector3(px, py, pz) - pick_ray.origin;
    1.41 +
    1.42 +	board.select_slot(board.slot_hit(pick_ray));
    1.43 +
    1.44 +	redisplay();
    1.45  }