eqemu

diff src/main.cc @ 6:977bc1cb055b

almost done
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Jul 2014 02:35:06 +0300
parents 3d3656360a82
children e9ab4861536d
line diff
     1.1 --- a/src/main.cc	Fri Jul 18 00:42:15 2014 +0300
     1.2 +++ b/src/main.cc	Fri Jul 18 02:35:06 2014 +0300
     1.3 @@ -42,8 +42,11 @@
     1.4  static Scene *scn;
     1.5  
     1.6  enum { BN_TICKET, BN_NEXT, NUM_BUTTONS };
     1.7 -const char *button_names[] = { "button1", "button2" };
     1.8 +static const char *button_names[] = { "button1", "button2" };
     1.9  static Object *button_obj[NUM_BUTTONS];
    1.10 +static Object *disp_obj[2];
    1.11 +static Object *led_obj[2];
    1.12 +static Vector3 led_on_emissive;
    1.13  
    1.14  int main(int argc, char **argv)
    1.15  {
    1.16 @@ -121,6 +124,25 @@
    1.17  		bs.set_radius(bs.get_radius() * 1.5);
    1.18  	}
    1.19  
    1.20 +	disp_obj[0] = scn->get_object("7seg0");
    1.21 +	disp_obj[1] = scn->get_object("7seg1");
    1.22 +	if(!disp_obj[0] || !disp_obj[1]) {
    1.23 +		fprintf(stderr, "invalid 3D model\n");
    1.24 +		return false;
    1.25 +	}
    1.26 +	scn->remove_object(disp_obj[0]);
    1.27 +	scn->remove_object(disp_obj[1]);
    1.28 +
    1.29 +	led_obj[0] = scn->get_object("led1");
    1.30 +	led_obj[1] = scn->get_object("led2");
    1.31 +	if(!led_obj[0] || !led_obj[1]) {
    1.32 +		fprintf(stderr, "invalid 3D model\n");
    1.33 +		return false;
    1.34 +	}
    1.35 +	scn->remove_object(led_obj[0]);
    1.36 +	scn->remove_object(led_obj[1]);
    1.37 +	led_on_emissive = led_obj[0]->mtl.emissive;
    1.38 +
    1.39  	glEnable(GL_DEPTH_TEST);
    1.40  	glEnable(GL_CULL_FACE);
    1.41  	glEnable(GL_LIGHTING);
    1.42 @@ -145,6 +167,8 @@
    1.43  	XCloseDisplay(dpy);
    1.44  }
    1.45  
    1.46 +#define DIGIT_USZ	(1.0 / 11.0)
    1.47 +
    1.48  static void display()
    1.49  {
    1.50  	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.51 @@ -160,6 +184,28 @@
    1.52  
    1.53  	scn->render();
    1.54  
    1.55 +	// shift the textures and modify the materials to make the display match our state
    1.56 +	for(int i=0; i<2; i++) {
    1.57 +		int digit = get_display_number();
    1.58 +		for(int j=0; j<i; j++) {
    1.59 +			digit /= 10;
    1.60 +		}
    1.61 +		digit %= 10;
    1.62 +
    1.63 +		float uoffs = DIGIT_USZ + DIGIT_USZ * digit;
    1.64 +
    1.65 +		disp_obj[i]->mtl.tex_offset[TEX_DIFFUSE] = Vector2(uoffs, 0);
    1.66 +		disp_obj[i]->render();
    1.67 +
    1.68 +		// LEDs
    1.69 +		if(get_led_state(i)) {
    1.70 +			led_obj[i]->mtl.emissive = led_on_emissive;
    1.71 +		} else {
    1.72 +			led_obj[i]->mtl.emissive = Vector3(0, 0, 0);
    1.73 +		}
    1.74 +		led_obj[i]->render();
    1.75 +	}
    1.76 +
    1.77  	glXSwapBuffers(dpy, win);
    1.78  	assert(glGetError() == GL_NO_ERROR);
    1.79  }
    1.80 @@ -240,13 +286,18 @@
    1.81  		cam_phi += dy * 0.5;
    1.82  		if(cam_phi < -90) cam_phi = -90;
    1.83  		if(cam_phi > 90) cam_phi = 90;
    1.84 -		draw_pending = true;
    1.85 -	}
    1.86 -	if(bnstate[2]) {
    1.87 +
    1.88 +	} else if(bnstate[2]) {
    1.89  		cam_dist += dy * 0.5;
    1.90  		if(cam_dist < 0.0) cam_dist = 0.0;
    1.91 -		draw_pending = true;
    1.92 +
    1.93 +	} else {
    1.94 +		float xoffs = 2.0 * x / win_width - 1.0;
    1.95 +		float yoffs = 2.0 * y / win_height - 1.0;
    1.96 +		cam_theta = -xoffs * 15.0 * (win_width / win_height);
    1.97 +		cam_phi = -yoffs * 15.0;
    1.98  	}
    1.99 +	draw_pending = true;
   1.100  }
   1.101  
   1.102  static Ray calc_pick_ray(int x, int y)
   1.103 @@ -317,7 +368,7 @@
   1.104  
   1.105  	unsigned int evmask = StructureNotifyMask | VisibilityChangeMask | ExposureMask |
   1.106  		KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
   1.107 -		ButtonMotionMask | PointerMotionMask;
   1.108 +		PointerMotionMask;
   1.109  	XSelectInput(dpy, win, evmask);
   1.110  
   1.111  	xa_wm_prot = XInternAtom(dpy, "WM_PROTOCOLS", False);
   1.112 @@ -357,7 +408,7 @@
   1.113  
   1.114  		case Expose:
   1.115  			if(win_mapped && ev.xexpose.count == 0) {
   1.116 -				draw_pending = 1;
   1.117 +				draw_pending = true;
   1.118  			}
   1.119  			break;
   1.120