eqemu
changeset 6:977bc1cb055b
almost done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Jul 2014 02:35:06 +0300 |
parents | 9b5bb05ae53a |
children | e9ab4861536d |
files | data/device.mtl data/device.obj data/envmap.png src/dev.cc src/main.cc src/material.cc src/material.h src/objfile.cc src/scene.cc src/scene.h |
diffstat | 10 files changed, 145 insertions(+), 100 deletions(-) [+] |
line diff
1.1 --- a/data/device.mtl Fri Jul 18 00:42:15 2014 +0300 1.2 +++ b/data/device.mtl Fri Jul 18 02:35:06 2014 +0300 1.3 @@ -1,6 +1,4 @@ 1.4 -# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware 1.5 -# File Created: 14.07.2014 08:46:21 1.6 - 1.7 +# box material 1.8 newmtl 01___Default 1.9 Ns 50.0000 1.10 Ni 1.5000 1.11 @@ -16,6 +14,7 @@ 1.12 map_Kd /Users/nuclear/code/equeue_dummy/data/labels.png 1.13 map_refl /Users/nuclear/code/equeue_dummy/data/envmap.png 1.14 1.15 +# ? 1.16 newmtl 02___Default 1.17 Ns 10.0000 1.18 Ni 1.5000 1.19 @@ -28,6 +27,7 @@ 1.20 Ks 0.0000 0.0000 0.0000 1.21 Ke 0.0000 0.0000 0.0000 1.22 1.23 +# LED material 1.24 newmtl 03___Default 1.25 Ns 24.0000 1.26 Ni 1.5000 1.27 @@ -35,11 +35,12 @@ 1.28 Tr 0.0000 1.29 Tf 1.0000 1.0000 1.0000 1.30 illum 2 1.31 - Ka 1.0000 0.0000 0.0000 1.32 - Kd 1.0000 0.0000 0.0000 1.33 + Ka 0.2000 0.0100 0.0100 1.34 + Kd 0.2000 0.0100 0.0100 1.35 Ks 0.6030 0.6030 0.6030 1.36 - Ke 0.0000 0.0000 0.0000 1.37 + Ke 1.0000 0.1 0.05 1.38 1.39 +# 7seg material 1.40 newmtl 08___Default 1.41 Ns 10.0000 1.42 Ni 1.5000 1.43 @@ -50,6 +51,6 @@ 1.44 Ka 0.5882 0.5882 0.5882 1.45 Kd 0.5882 0.5882 0.5882 1.46 Ks 0.0000 0.0000 0.0000 1.47 - Ke 0.0000 0.0000 0.0000 1.48 + Ke 1.0000 1.0000 1.0000 1.49 map_Ka /Users/nuclear/code/equeue_dummy/data/7seg.png 1.50 map_Kd /Users/nuclear/code/equeue_dummy/data/7seg.png
2.1 --- a/data/device.obj Fri Jul 18 00:42:15 2014 +0300 2.2 +++ b/data/device.obj Fri Jul 18 02:35:06 2014 +0300 2.3 @@ -2179,14 +2179,14 @@ 2.4 vn -1.0000 0.0000 -0.0000 2.5 # 6 vertex normals 2.6 2.7 -vt 0.4546 0.9995 0.9995 2.8 -vt 0.4546 0.0005 0.9995 2.9 -vt 0.5454 0.0005 0.9995 2.10 -vt 0.5454 0.9995 0.9995 2.11 -vt 0.5454 0.0005 0.0005 2.12 -vt 0.4546 0.0005 0.0005 2.13 -vt 0.4546 0.9995 0.0005 2.14 -vt 0.5454 0.9995 0.0005 2.15 +vt 0.0000 0.9995 0.9995 2.16 +vt 0.0000 0.0005 0.9995 2.17 +vt 0.0908 0.0005 0.9995 2.18 +vt 0.0908 0.9995 0.9995 2.19 +vt 0.0908 0.0005 0.0005 2.20 +vt 0.0000 0.0005 0.0005 2.21 +vt 0.0000 0.9995 0.0005 2.22 +vt 0.0908 0.9995 0.0005 2.23 # 8 texture coords 2.24 2.25 g 7seg1 2.26 @@ -2227,14 +2227,14 @@ 2.27 vn -1.0000 0.0000 -0.0000 2.28 # 6 vertex normals 2.29 2.30 -vt 0.4546 0.9995 0.9995 2.31 -vt 0.4546 0.0005 0.9995 2.32 -vt 0.5454 0.0005 0.9995 2.33 -vt 0.5454 0.9995 0.9995 2.34 -vt 0.5454 0.0005 0.0005 2.35 -vt 0.4546 0.0005 0.0005 2.36 -vt 0.4546 0.9995 0.0005 2.37 -vt 0.5454 0.9995 0.0005 2.38 +vt 0.0000 0.9995 0.9995 2.39 +vt 0.0000 0.0005 0.9995 2.40 +vt 0.0908 0.0005 0.9995 2.41 +vt 0.0908 0.9995 0.9995 2.42 +vt 0.0908 0.0005 0.0005 2.43 +vt 0.0000 0.0005 0.0005 2.44 +vt 0.0000 0.9995 0.0005 2.45 +vt 0.0908 0.9995 0.0005 2.46 # 8 texture coords 2.47 2.48 g 7seg0
3.1 Binary file data/envmap.png has changed
4.1 --- a/src/dev.cc Fri Jul 18 00:42:15 2014 +0300 4.2 +++ b/src/dev.cc Fri Jul 18 02:35:06 2014 +0300 4.3 @@ -119,6 +119,22 @@ 4.4 } 4.5 } 4.6 4.7 +#define TICKET_SHOW_DUR 1000 4.8 + 4.9 +int get_display_number() 4.10 +{ 4.11 + if(get_msec() - last_ticket_msec < TICKET_SHOW_DUR) { 4.12 + return ticket; 4.13 + } 4.14 + return customer; 4.15 +} 4.16 + 4.17 +int get_led_state(int led) 4.18 +{ 4.19 + int ledon = get_msec() - last_ticket_msec < TICKET_SHOW_DUR ? 0 : 1; 4.20 + return led == ledon ? 1 : 0; 4.21 +} 4.22 + 4.23 #define VERSTR \ 4.24 "Queue system emulator v0.1 by John Tsiombikas <nuclear@member.fsf.org>" 4.25
5.1 --- a/src/main.cc Fri Jul 18 00:42:15 2014 +0300 5.2 +++ b/src/main.cc Fri Jul 18 02:35:06 2014 +0300 5.3 @@ -42,8 +42,11 @@ 5.4 static Scene *scn; 5.5 5.6 enum { BN_TICKET, BN_NEXT, NUM_BUTTONS }; 5.7 -const char *button_names[] = { "button1", "button2" }; 5.8 +static const char *button_names[] = { "button1", "button2" }; 5.9 static Object *button_obj[NUM_BUTTONS]; 5.10 +static Object *disp_obj[2]; 5.11 +static Object *led_obj[2]; 5.12 +static Vector3 led_on_emissive; 5.13 5.14 int main(int argc, char **argv) 5.15 { 5.16 @@ -121,6 +124,25 @@ 5.17 bs.set_radius(bs.get_radius() * 1.5); 5.18 } 5.19 5.20 + disp_obj[0] = scn->get_object("7seg0"); 5.21 + disp_obj[1] = scn->get_object("7seg1"); 5.22 + if(!disp_obj[0] || !disp_obj[1]) { 5.23 + fprintf(stderr, "invalid 3D model\n"); 5.24 + return false; 5.25 + } 5.26 + scn->remove_object(disp_obj[0]); 5.27 + scn->remove_object(disp_obj[1]); 5.28 + 5.29 + led_obj[0] = scn->get_object("led1"); 5.30 + led_obj[1] = scn->get_object("led2"); 5.31 + if(!led_obj[0] || !led_obj[1]) { 5.32 + fprintf(stderr, "invalid 3D model\n"); 5.33 + return false; 5.34 + } 5.35 + scn->remove_object(led_obj[0]); 5.36 + scn->remove_object(led_obj[1]); 5.37 + led_on_emissive = led_obj[0]->mtl.emissive; 5.38 + 5.39 glEnable(GL_DEPTH_TEST); 5.40 glEnable(GL_CULL_FACE); 5.41 glEnable(GL_LIGHTING); 5.42 @@ -145,6 +167,8 @@ 5.43 XCloseDisplay(dpy); 5.44 } 5.45 5.46 +#define DIGIT_USZ (1.0 / 11.0) 5.47 + 5.48 static void display() 5.49 { 5.50 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 5.51 @@ -160,6 +184,28 @@ 5.52 5.53 scn->render(); 5.54 5.55 + // shift the textures and modify the materials to make the display match our state 5.56 + for(int i=0; i<2; i++) { 5.57 + int digit = get_display_number(); 5.58 + for(int j=0; j<i; j++) { 5.59 + digit /= 10; 5.60 + } 5.61 + digit %= 10; 5.62 + 5.63 + float uoffs = DIGIT_USZ + DIGIT_USZ * digit; 5.64 + 5.65 + disp_obj[i]->mtl.tex_offset[TEX_DIFFUSE] = Vector2(uoffs, 0); 5.66 + disp_obj[i]->render(); 5.67 + 5.68 + // LEDs 5.69 + if(get_led_state(i)) { 5.70 + led_obj[i]->mtl.emissive = led_on_emissive; 5.71 + } else { 5.72 + led_obj[i]->mtl.emissive = Vector3(0, 0, 0); 5.73 + } 5.74 + led_obj[i]->render(); 5.75 + } 5.76 + 5.77 glXSwapBuffers(dpy, win); 5.78 assert(glGetError() == GL_NO_ERROR); 5.79 } 5.80 @@ -240,13 +286,18 @@ 5.81 cam_phi += dy * 0.5; 5.82 if(cam_phi < -90) cam_phi = -90; 5.83 if(cam_phi > 90) cam_phi = 90; 5.84 - draw_pending = true; 5.85 - } 5.86 - if(bnstate[2]) { 5.87 + 5.88 + } else if(bnstate[2]) { 5.89 cam_dist += dy * 0.5; 5.90 if(cam_dist < 0.0) cam_dist = 0.0; 5.91 - draw_pending = true; 5.92 + 5.93 + } else { 5.94 + float xoffs = 2.0 * x / win_width - 1.0; 5.95 + float yoffs = 2.0 * y / win_height - 1.0; 5.96 + cam_theta = -xoffs * 15.0 * (win_width / win_height); 5.97 + cam_phi = -yoffs * 15.0; 5.98 } 5.99 + draw_pending = true; 5.100 } 5.101 5.102 static Ray calc_pick_ray(int x, int y) 5.103 @@ -317,7 +368,7 @@ 5.104 5.105 unsigned int evmask = StructureNotifyMask | VisibilityChangeMask | ExposureMask | 5.106 KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | 5.107 - ButtonMotionMask | PointerMotionMask; 5.108 + PointerMotionMask; 5.109 XSelectInput(dpy, win, evmask); 5.110 5.111 xa_wm_prot = XInternAtom(dpy, "WM_PROTOCOLS", False); 5.112 @@ -357,7 +408,7 @@ 5.113 5.114 case Expose: 5.115 if(win_mapped && ev.xexpose.count == 0) { 5.116 - draw_pending = 1; 5.117 + draw_pending = true; 5.118 } 5.119 break; 5.120
6.1 --- a/src/material.cc Fri Jul 18 00:42:15 2014 +0300 6.2 +++ b/src/material.cc Fri Jul 18 02:35:06 2014 +0300 6.3 @@ -20,20 +20,23 @@ 6.4 6.5 void Material::setup() const 6.6 { 6.7 + float amb[] = {ambient.x, ambient.y, ambient.z, 1.0}; 6.8 + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); 6.9 + 6.10 float col[] = {diffuse.x, diffuse.y, diffuse.z, alpha}; 6.11 - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, col); 6.12 + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col); 6.13 6.14 float spec[] = {specular.x, specular.y, specular.z, 1.0}; 6.15 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); 6.16 6.17 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess > 128 ? 128 : shininess); 6.18 6.19 - if(sdr) { 6.20 - glUseProgram(sdr); 6.21 - } 6.22 + float emit[] = {emissive.x, emissive.y, emissive.z, 1.0}; 6.23 + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emit); 6.24 6.25 + int num_tex = 0; 6.26 if(tex[TEX_DIFFUSE]) { 6.27 - glActiveTexture(GL_TEXTURE0); 6.28 + glActiveTexture(GL_TEXTURE0 + num_tex++); 6.29 6.30 glMatrixMode(GL_TEXTURE); 6.31 glLoadIdentity(); 6.32 @@ -43,13 +46,14 @@ 6.33 glBindTexture(GL_TEXTURE_2D, tex[TEX_DIFFUSE]); 6.34 glEnable(GL_TEXTURE_2D); 6.35 6.36 - int loc = glGetUniformLocation(sdr, "tex_diffuse"); 6.37 - if(loc != -1) { 6.38 - glUniform1i(loc, 0); 6.39 - } 6.40 + glDisable(GL_TEXTURE_GEN_S); 6.41 + glDisable(GL_TEXTURE_GEN_T); 6.42 + 6.43 + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 6.44 } 6.45 + 6.46 if(tex[TEX_ENVMAP]) { 6.47 - glActiveTexture(GL_TEXTURE1); 6.48 + glActiveTexture(GL_TEXTURE0 + num_tex++); 6.49 6.50 glMatrixMode(GL_TEXTURE); 6.51 glLoadIdentity(); 6.52 @@ -64,10 +68,13 @@ 6.53 glEnable(GL_TEXTURE_GEN_S); 6.54 glEnable(GL_TEXTURE_GEN_T); 6.55 6.56 - int loc = glGetUniformLocation(sdr, "tex_envmap"); 6.57 - if(loc != -1) { 6.58 - glUniform1i(loc, 1); 6.59 - } 6.60 + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); 6.61 + } 6.62 + 6.63 + 6.64 + for(int i=num_tex; i<4; i++) { 6.65 + glActiveTexture(GL_TEXTURE0 + i); 6.66 + glDisable(GL_TEXTURE_2D); 6.67 } 6.68 6.69 glActiveTexture(GL_TEXTURE0); 6.70 @@ -98,62 +105,6 @@ 6.71 return tex; 6.72 } 6.73 6.74 -static char *read_shader(const char *fname) 6.75 -{ 6.76 - FILE *fp = fopen(fname, "r"); 6.77 - if(!fp) { 6.78 - return 0; 6.79 - } 6.80 - fseek(fp, 0, SEEK_END); 6.81 - long len = ftell(); 6.82 - rewind(fp); 6.83 - 6.84 - char *buf = new char[len + 1]; 6.85 - fread(buf, len, fp); 6.86 - buf[len] = 0; 6.87 - fclose(fp); 6.88 - 6.89 - return buf; 6.90 -} 6.91 - 6.92 -unsigned int load_shader_program(const char *vname, const char *pname) 6.93 -{ 6.94 - unsigned int vsdr = 0, psdr = 0; 6.95 - 6.96 - if(vname) { 6.97 - char *src = read_shader(find_path(vname)); 6.98 - if(!src) { 6.99 - fprintf(stderr, "failed to load vertex shader: %s\n", vname); 6.100 - return 0; 6.101 - } 6.102 - vsdr = glCreateShader(GL_VERTEX_SHADER); 6.103 - glShaderSource(vsdr, 1, &src, 0); 6.104 - delete [] src; 6.105 - 6.106 - int res; 6.107 - glGetShaderiv(vsdr, GL_INFO_LOG_LENGTH, &res); 6.108 - if(res > 0) {URE_2D, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 6.109 - img_free_pixels(pixels); 6.110 - return tex; 6.111 -} 6.112 - 6.113 -static char *read_shader(const char *fname) 6.114 -{ 6.115 - FILE *fp = fopen(find_path(vname), "r"); 6.116 - if(!fp) { 6.117 - fprintf(stderr, "failed to load shader: %s\n", vname); 6.118 - return 0; 6.119 - char *info = new char[res]; 6.120 - glGetShaderInfoLog(vsdr, res, &res, info); 6.121 - printf("shader compiler log: %s\n", info); 6.122 - } 6.123 - glGetShaderiv(vsdr, GL_COMPILE_STATUS, &res); 6.124 - if(!res) { 6.125 - return 0; 6.126 - } 6.127 - } 6.128 -} 6.129 - 6.130 static const char *find_path(const char *fname) 6.131 { 6.132 const char *ptr = fname + strlen(fname) - 1;
7.1 --- a/src/material.h Fri Jul 18 00:42:15 2014 +0300 7.2 +++ b/src/material.h Fri Jul 18 02:35:06 2014 +0300 7.3 @@ -12,6 +12,7 @@ 7.4 7.5 class Material { 7.6 public: 7.7 + Vector3 emissive; 7.8 Vector3 ambient; 7.9 Vector3 diffuse; 7.10 Vector3 specular;
8.1 --- a/src/objfile.cc Fri Jul 18 00:42:15 2014 +0300 8.2 +++ b/src/objfile.cc Fri Jul 18 02:35:06 2014 +0300 8.3 @@ -22,6 +22,7 @@ 8.4 CMD(MTLLIB), \ 8.5 CMD(USEMTL), \ 8.6 CMD(NEWMTL), \ 8.7 + CMD(KE), \ 8.8 CMD(KA), \ 8.9 CMD(KD), \ 8.10 CMD(KS), \ 8.11 @@ -30,6 +31,8 @@ 8.12 CMD(D), \ 8.13 CMD(TR), \ 8.14 CMD(MAP_KD), \ 8.15 + CMD(MAP_REFL), \ 8.16 + CMD(MAP_BUMP), \ 8.17 CMD(MAP_KS), \ 8.18 CMD(MAP_NS), \ 8.19 CMD(MAP_D), \ 8.20 @@ -68,6 +71,7 @@ 8.21 struct ObjMat { 8.22 string name; // newmtl <name> 8.23 Color ambient, diffuse, specular; // Ka, Kd, Ks 8.24 + Color emissive; // Ke 8.25 float shininess; // Ns 8.26 float ior; // Ni 8.27 float alpha; // d, Tr 8.28 @@ -207,6 +211,7 @@ 8.29 mat.diffuse = vmtl[i].diffuse; 8.30 mat.specular = vmtl[i].specular; 8.31 mat.shininess = vmtl[i].shininess; 8.32 + mat.emissive = vmtl[i].emissive; 8.33 mat.alpha = vmtl[i].alpha; 8.34 8.35 if(vmtl[i].tex_dif.length()) { 8.36 @@ -383,6 +388,10 @@ 8.37 } 8.38 break; 8.39 8.40 + case CMD_KE: 8.41 + parse_color(&mat.emissive); 8.42 + break; 8.43 + 8.44 case CMD_KA: 8.45 parse_color(&mat.ambient); 8.46 break; 8.47 @@ -421,6 +430,10 @@ 8.48 mat.tex_dif = parse_map(); 8.49 break; 8.50 8.51 + case CMD_MAP_REFL: 8.52 + mat.tex_refl = parse_map(); 8.53 + break; 8.54 + 8.55 default: 8.56 break; 8.57 }
9.1 --- a/src/scene.cc Fri Jul 18 00:42:15 2014 +0300 9.2 +++ b/src/scene.cc Fri Jul 18 02:35:06 2014 +0300 9.3 @@ -61,6 +61,17 @@ 9.4 return 0; 9.5 } 9.6 9.7 +bool Scene::remove_object(Object *obj) 9.8 +{ 9.9 + for(size_t i=0; i<objects.size(); i++) { 9.10 + if(objects[i] == obj) { 9.11 + objects.erase(objects.begin() + i); 9.12 + return true; 9.13 + } 9.14 + } 9.15 + return false; 9.16 +} 9.17 + 9.18 Mesh *Scene::get_mesh(int idx) const 9.19 { 9.20 return meshes[idx];
10.1 --- a/src/scene.h Fri Jul 18 00:42:15 2014 +0300 10.2 +++ b/src/scene.h Fri Jul 18 02:35:06 2014 +0300 10.3 @@ -28,6 +28,7 @@ 10.4 Mesh *get_mesh(int idx) const; 10.5 10.6 Object *get_object(const char *name) const; 10.7 + bool remove_object(Object *obj); 10.8 10.9 void update(long msec); 10.10 void render() const;