# HG changeset patch # User John Tsiombikas # Date 1435285426 -10800 # Node ID f1ecc24398025f1a5ae493d50ddc1b341b965b70 # Parent a0d30f6f20d491d860b930eb94844dd5d9842fe9 hinges diff -r a0d30f6f20d4 -r f1ecc2439802 src/board.cc --- a/src/board.cc Fri Jun 26 04:22:06 2015 +0300 +++ b/src/board.cc Fri Jun 26 05:23:46 2015 +0300 @@ -125,35 +125,63 @@ // generate the hinges Mesh *hinges = new Mesh; - gen_cylinder(hinges, HINGE_RAD, HINGE_HEIGHT, 10, 1, 1); - xform.reset_identity(); - xform.translate(Vector3(0, WALL_HEIGHT - HINGE_RAD * 0.5, VSIZE / 4.0)); - xform.rotate(Vector3(M_PI / 2.0, 0, 0)); - hinges->apply_xform(xform); + for(int i=0; i<2; i++) { + float sign = i * 2 - 1; - gen_cylinder(&tmp, HINGE_RAD, HINGE_HEIGHT, 10, 1, 1); - xform.reset_identity(); - xform.translate(Vector3(0, WALL_HEIGHT - HINGE_RAD * 0.5, -VSIZE / 4.0)); - xform.rotate(Vector3(M_PI / 2.0, 0, 0)); - tmp.apply_xform(xform); + // barrel + gen_cylinder(&tmp, HINGE_RAD, HINGE_HEIGHT, 10, 1, 1); + xform.reset_identity(); + xform.translate(Vector3(0, WALL_HEIGHT - HINGE_RAD * 0.5, sign * VSIZE / 4.0)); + xform.rotate(Vector3(-M_PI / 2.0, 0, 0)); + tmp.apply_xform(xform); + hinges->append(tmp); - hinges->append(tmp); + // flange + gen_plane(&tmp, HINGE_HEIGHT * 0.6, HINGE_HEIGHT * 0.8); + tmp.apply_xform(xform); + + Matrix4x4 tex_xform; + tex_xform.set_rotation(Vector3(0, 0, M_PI / 2.0)); + tmp.texcoord_apply_xform(tex_xform); + hinges->append(tmp); + + // studs + for(int j=0; j<4; j++) { + Vector3 pos; + + pos.x = (float)((j & 1) * 2 - 1) * HINGE_HEIGHT * 0.2; + pos.y = (float)((j & 2) - 1) * HINGE_HEIGHT * 0.3; + + Matrix4x4 stud_xform = xform; + stud_xform.translate(pos); + + Matrix4x4 squash; + squash.set_scaling(Vector3(1, 1, 0.5)); + + gen_sphere(&tmp, HINGE_RAD * 0.5, 8, 4); + tmp.apply_xform(stud_xform * squash); + hinges->append(tmp); + } + } Object *ohinges = new Object; ohinges->set_mesh(hinges); + ohinges->set_texture(img_hinge.texture()); obj.push_back(ohinges); // debug object - /*Mesh *dbgmesh = new Mesh; + /* + Mesh *dbgmesh = new Mesh; gen_box(dbgmesh, 0.5, 0.5, 0.5); xform.set_translation(Vector3(0, 0.4, 0)); - xform.set_scaling(Vector3(4, 1, 4)); + xform.set_scaling(Vector3(1, 1, 1)); dbgmesh->apply_xform(xform); Object *dbgobj = new Object; dbgobj->set_mesh(dbgmesh); - dbgobj->set_texture(img_wood.texture()); - dbgobj->tex_xform().set_scaling(Vector3(3, 3, 3)); - obj.push_back(dbgobj);*/ + dbgobj->set_texture(img_hinge.texture()); + //dbgobj->tex_xform().set_scaling(Vector3(3, 3, 3)); + obj.push_back(dbgobj); + */ return true; } @@ -284,5 +312,40 @@ } } img_wood.texture(); + + // ---- metal hinge diffuse texture ---- + Vector3 rusty_col1 = Vector3(0.43, 0.46, 0.52); + Vector3 rusty_col2 = Vector3(0.52, 0.47, 0.43); + + img_hinge.create(128, 128); + pptr = img_hinge.pixels; + for(int i=0; i 255 ? 255 : (r < 0 ? 0 : r); + pptr[1] = g > 255 ? 255 : (g < 0 ? 0 : g); + pptr[2] = b > 255 ? 255 : (b < 0 ? 0 : b); + + pptr += 3; + } + } + img_hinge.texture(); + return true; } diff -r a0d30f6f20d4 -r f1ecc2439802 src/board.h --- a/src/board.h Fri Jun 26 04:22:06 2015 +0300 +++ b/src/board.h Fri Jun 26 05:23:46 2015 +0300 @@ -16,7 +16,7 @@ std::vector obj; Object *puck_obj; - Image img_wood, img_field; + Image img_wood, img_field, img_hinge; bool generate(); bool generate_textures(); diff -r a0d30f6f20d4 -r f1ecc2439802 src/mesh.cc --- a/src/mesh.cc Fri Jun 26 04:22:06 2015 +0300 +++ b/src/mesh.cc Fri Jun 26 05:23:46 2015 +0300 @@ -322,6 +322,11 @@ { unsigned int idxoffs = nverts; + if(!nverts) { + clone(mesh); + return; + } + nverts += mesh.nverts; nfaces += mesh.nfaces;