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/src/easymesh
Files:
3 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:
Note: See TracChangeset for help on using the changeset viewer.