Changeset 2151 for trunk


Ignore:
Timestamp:
Dec 19, 2012, 8:07:44 PM (7 years ago)
Author:
sam
Message:

easymesh: allow central holes in gears as well as internal gears.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/easymesh/easymesh-parser.y

    r2116 r2151  
    158158  | T_TRIANGLE args2       { mc.m_mesh.AppendSimpleTriangle($2.f0, (int)$2.f1); }
    159159  | T_QUAD args2           { mc.m_mesh.AppendSimpleQuad($2.f0, (int)$2.f1); }
    160   | T_COG args8            { mc.m_mesh.AppendCog((int)$2.f0, $2.f1, $2.f2, $2.f3,
    161                                             $2.f4, $2.f5, $2.f6, (int)$2.f7); }
     160  | T_COG args8            { mc.m_mesh.AppendCog((int)$2.f0, $2.f1,
     161                                 $2.f2 / 2, $2.f3 / 2, $2.f2, $2.f3, $2.f4,
     162                                 $2.f5, $2.f6, (int)$2.f7); }
    162163    ;
    163164
  • trunk/src/easymesh/easymesh.cpp

    r2148 r2151  
    783783}
    784784
    785 void EasyMesh::AppendCog(int nbsides, float h, float r1, float r2, float r12,
    786                          float r22, float sidemul, int offset)
     785void EasyMesh::AppendCog(int nbsides, float h, float r10, float r20,
     786                         float r1, float r2, float r12, float r22,
     787                         float sidemul, int offset)
    787788{
    788789    int ibase = m_indices.Count();
    789790    int vbase = m_vert.Count();
    790791
    791     AddVertex(vec3(0.f, h * .5f, 0.f));
    792     AddVertex(vec3(0.f, h * -.5f, 0.f));
    793     SetCurVertColor(m_color2);
     792    /* FIXME: enforce this some other way */
     793    if (r12 < 0)
     794    {
     795        r10 *= 2.5;
     796        r20 *= 2.5;
     797        h = -h;
     798    }
    794799
    795800    mat3 rotmat = mat3::rotate(180.0f / nbsides, 0.f, 1.f, 0.f);
     
    797802    mat3 smat2 = mat3::rotate(sidemul * -360.0f / nbsides, 0.f, 1.f, 0.f);
    798803
    799     vec3 p[8];
    800 
    801     p[0] = vec3(r1, h * .5f, 0.f);
     804    vec3 p[12];
     805
     806    p[0] = vec3(r10, h * .5f, 0.f);
    802807    p[1] = rotmat * p[0];
    803     p[2] = smat1 * (rotmat * vec3(r1 + r12, h * .5f, 0.f));
    804     p[3] = smat2 * (rotmat * p[2]);
    805 
    806     p[4] = vec3(r2, h * -.5f, 0.f);
    807     p[5] = rotmat * p[4];
    808     p[6] = smat1 * (rotmat * vec3(r2 + r22, h * -.5f, 0.f));
    809     p[7] = smat2 * (rotmat * p[6]);
     808    p[2] = vec3(r1, h * .5f, 0.f);
     809    p[3] = rotmat * p[2];
     810    p[4] = smat1 * (rotmat * vec3(r1 + r12, h * .5f, 0.f));
     811    p[5] = smat2 * (rotmat * p[4]);
     812
     813    p[6] = vec3(r20, h * -.5f, 0.f);
     814    p[7] = rotmat * p[6];
     815    p[8] = vec3(r2, h * -.5f, 0.f);
     816    p[9] = rotmat * p[8];
     817    p[10] = smat1 * (rotmat * vec3(r2 + r22, h * -.5f, 0.f));
     818    p[11] = smat2 * (rotmat * p[10]);
    810819
    811820    if (offset & 1)
    812         for (int n = 0; n < 8; n++)
     821        for (int n = 0; n < 12; n++)
    813822            p[n] = rotmat * p[n];
    814823
     
    819828        /* Each vertex will share three faces, so three different
    820829         * normals, therefore we add each vertex three times. */
    821         for (int n = 0; n < 24; n++)
     830        for (int n = 0; n < 3 * 12; n++)
    822831        {
    823832            AddVertex(p[n / 3]);
    824             if (n / 3 >= 4)
     833            if (n / 3 >= 6)
    825834                SetCurVertColor(m_color2);
    826835        }
    827836
    828         int j = 24 * i, k = 24 * ((i + 1) % nbsides);
     837        int j = 3 * 12 * i, k = 3 * 12 * ((i + 1) % nbsides);
    829838
    830839        /* The top and bottom faces */
    831         AppendQuad(0, j + 2, j + 5, k + 2, vbase);
    832         AppendQuad(1, k + 14, j + 17, j + 14, vbase);
    833         AppendQuad(j + 5, j + 8, j + 11, k + 2, vbase);
    834         AppendQuad(k + 14, j + 23, j + 20, j + 17, vbase);
    835 
    836         /* The side quads */
    837         AppendQuad(j + 6, j + 3, j + 15, j + 18, vbase);
    838         AppendQuad(j + 9, j + 7, j + 19, j + 21, vbase);
    839         AppendQuad(j + 12, j + 10, j + 22, j + 24, vbase);
    840         AppendQuad(k + 4, j + 13, j + 25, k + 16, vbase);
    841 
    842         for (int n = 0; n < 8; n++)
     840        AppendQuad(j, j + 6, j + 9, j + 3, vbase);
     841        AppendQuad(j + 21, j + 27, j + 24, j + 18, vbase);
     842        AppendQuad(j + 3, j + 9, k + 6, k, vbase);
     843        AppendQuad(k + 18, k + 24, j + 27, j + 21, vbase);
     844        AppendQuad(j + 9, j + 12, j + 15, k + 6, vbase);
     845        AppendQuad(k + 24, j + 33, j + 30, j + 27, vbase);
     846
     847        /* The inner side quads */
     848        AppendQuad(j + 1, j + 4, j + 22, j + 19, vbase);
     849        AppendQuad(j + 5, k + 2, k + 20, j + 23, vbase);
     850
     851        /* The outer side quads */
     852        AppendQuad(j + 10, j + 7, j + 25, j + 28, vbase);
     853        AppendQuad(j + 13, j + 11, j + 29, j + 31, vbase);
     854        AppendQuad(j + 16, j + 14, j + 32, j + 34, vbase);
     855        AppendQuad(k + 8, j + 17, j + 35, k + 26, vbase);
     856
     857        for (int n = 0; n < 12; n++)
    843858            p[n] = rotmat * p[n];
    844859    }
  • trunk/src/easymesh/easymesh.h

    r2148 r2151  
    8787    void AppendSimpleQuad(float size, int fade = 0);
    8888    void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0);
    89     void AppendCog(int nbsides, float h, float r1, float r2,
    90                    float r12, float r22, float sidemul, int offset);
     89    void AppendCog(int nbsides, float h, float r10, float r20, float r1,
     90                   float r2, float r12, float r22, float sidemul, int offset);
    9191
    9292private:
  • trunk/src/generated/easymesh-parser.cpp

    r2116 r2151  
    708708/* Line 677 of lalr1.cc  */
    709709#line 160 "easymesh/easymesh-parser.y"
    710     { mc.m_mesh.AppendCog((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1, (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3,
    711                                             (yysemantic_stack_[(2) - (2)].args).f4, (yysemantic_stack_[(2) - (2)].args).f5, (yysemantic_stack_[(2) - (2)].args).f6, (int)(yysemantic_stack_[(2) - (2)].args).f7); }
     710    { mc.m_mesh.AppendCog((int)(yysemantic_stack_[(2) - (2)].args).f0, (yysemantic_stack_[(2) - (2)].args).f1,
     711                                 (yysemantic_stack_[(2) - (2)].args).f2 / 2, (yysemantic_stack_[(2) - (2)].args).f3 / 2, (yysemantic_stack_[(2) - (2)].args).f2, (yysemantic_stack_[(2) - (2)].args).f3, (yysemantic_stack_[(2) - (2)].args).f4,
     712                                 (yysemantic_stack_[(2) - (2)].args).f5, (yysemantic_stack_[(2) - (2)].args).f6, (int)(yysemantic_stack_[(2) - (2)].args).f7); }
    712713    break;
    713714
     
    715716
    716717/* Line 677 of lalr1.cc  */
    717 #line 164 "easymesh/easymesh-parser.y"
     718#line 165 "easymesh/easymesh-parser.y"
    718719    { (yyval.args).f0 = (yysemantic_stack_[(1) - (1)].fval); }
    719720    break;
     
    722723
    723724/* Line 677 of lalr1.cc  */
    724 #line 165 "easymesh/easymesh-parser.y"
     725#line 166 "easymesh/easymesh-parser.y"
    725726    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f1 = (yysemantic_stack_[(2) - (2)].fval); }
    726727    break;
     
    729730
    730731/* Line 677 of lalr1.cc  */
    731 #line 166 "easymesh/easymesh-parser.y"
     732#line 167 "easymesh/easymesh-parser.y"
    732733    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f2 = (yysemantic_stack_[(2) - (2)].fval); }
    733734    break;
     
    736737
    737738/* Line 677 of lalr1.cc  */
    738 #line 167 "easymesh/easymesh-parser.y"
     739#line 168 "easymesh/easymesh-parser.y"
    739740    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f3 = (yysemantic_stack_[(2) - (2)].fval); }
    740741    break;
     
    743744
    744745/* Line 677 of lalr1.cc  */
    745 #line 168 "easymesh/easymesh-parser.y"
     746#line 169 "easymesh/easymesh-parser.y"
    746747    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f4 = (yysemantic_stack_[(2) - (2)].fval); }
    747748    break;
     
    750751
    751752/* Line 677 of lalr1.cc  */
    752 #line 169 "easymesh/easymesh-parser.y"
     753#line 170 "easymesh/easymesh-parser.y"
    753754    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f5 = (yysemantic_stack_[(2) - (2)].fval); }
    754755    break;
     
    757758
    758759/* Line 677 of lalr1.cc  */
    759 #line 170 "easymesh/easymesh-parser.y"
     760#line 171 "easymesh/easymesh-parser.y"
    760761    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f6 = (yysemantic_stack_[(2) - (2)].fval); }
    761762    break;
     
    764765
    765766/* Line 677 of lalr1.cc  */
    766 #line 171 "easymesh/easymesh-parser.y"
     767#line 172 "easymesh/easymesh-parser.y"
    767768    { (yyval.args) = (yysemantic_stack_[(2) - (1)].args); (yyval.args).f7 = (yysemantic_stack_[(2) - (2)].fval); }
    768769    break;
     
    771772
    772773/* Line 677 of lalr1.cc  */
    773 #line 174 "easymesh/easymesh-parser.y"
     774#line 175 "easymesh/easymesh-parser.y"
    774775    { (yyval.fval) = (yysemantic_stack_[(1) - (1)].fval); }
    775776    break;
     
    778779
    779780/* Line 677 of lalr1.cc  */
    780 #line 175 "easymesh/easymesh-parser.y"
     781#line 176 "easymesh/easymesh-parser.y"
    781782    { (yyval.fval) = -(yysemantic_stack_[(2) - (2)].fval); }
    782783    break;
     
    785786
    786787/* Line 677 of lalr1.cc  */
    787 #line 788 "generated/easymesh-parser.cpp"
     788#line 789 "generated/easymesh-parser.cpp"
    788789        default:
    789790          break;
     
    12061207     131,   132,   133,   134,   135,   136,   137,   141,   144,   145,
    12071208     147,   149,   151,   152,   153,   155,   157,   158,   159,   160,
    1208      164,   165,   166,   167,   168,   169,   170,   171,   174,   175
     1209     165,   166,   167,   168,   169,   170,   171,   172,   175,   176
    12091210  };
    12101211
     
    12991300
    13001301/* Line 1053 of lalr1.cc  */
    1301 #line 1302 "generated/easymesh-parser.cpp"
     1302#line 1303 "generated/easymesh-parser.cpp"
    13021303
    13031304
    13041305/* Line 1055 of lalr1.cc  */
    1305 #line 178 "easymesh/easymesh-parser.y"
     1306#line 179 "easymesh/easymesh-parser.y"
    13061307
    13071308
  • trunk/tutorial/05_easymesh.cpp

    r2147 r2151  
    4545        m_angle = 0;
    4646
    47         m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 5 5 0.1 0");
     47        //m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 5 5 0.1 0");
     48        m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 -5 -5 0.1 0");
    4849
    4950#if 0
Note: See TracChangeset for help on using the changeset viewer.