Changeset 1276


Ignore:
Timestamp:
Apr 23, 2012, 8:42:01 AM (11 years ago)
Author:
sam
Message:

orbital: implement cylinders in the mesh builder; their normals are wrong
in the smooth case, for now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/orbital/mesh.h

    r1275 r1276  
    2525        vec4 v4;
    2626        vec3 v3;
    27         float f1, f2, f3, f4, f5;
     27        float f1, f2, f3, f4, f5, f6;
    2828
    2929        for (char const *p = command; p && *p; )
     
    5252            else CASE("my")  { MirrorY(); }
    5353            else CASE("mz")  { MirrorZ(); }
    54             else CASE("ac")  { /* TODO */ }
     54            else CASE("ac")  { p = GetArg(p, f1, f2, f3); p = GetArg(p, f4, f5, f6); AppendCylinder((int)f1, f2, f3, f4, (int)f5, (int)f6); }
    5555            else CASE("ab")  { p = GetArg(p, v3); AppendBox(v3); }
    5656            else CASE("ascb") { p = GetArg(p, v3, f1); AppendSmoothChamfBox(v3, f1); }
     
    494494    }
    495495
    496     void AppendCylinder() {} /* TODO */
     496    void AppendCylinder(int nsides, float h, float r1, float r2,
     497                        int dualside, int smooth)
     498    {
     499        int ibase = m_quadidx.Count();
     500        int vbase = m_vert.Count();
     501
     502        mat3 rotmat = mat3::rotate(360.0f / nsides, 0.f, 1.f, 0.f);
     503        vec3 p1(r1, -h, 0.f);
     504        vec3 p2(r2, h, 0.f);
     505
     506        for (int i = 0; i < nsides; i++)
     507        {
     508            AppendQuadVert(p1);
     509            AppendQuadVert(p2);
     510            SetCurVertColor(m_color2);
     511
     512            if (smooth)
     513            {
     514                int j = (i + 1) % nsides;
     515                AppendQuad(j * 2, j * 2 + 1, i * 2 + 1, i * 2, vbase);
     516                if (dualside)
     517                    AppendQuad(i * 2, i * 2 + 1, j * 2 + 1, j * 2, vbase);
     518
     519                /* TODO: compute normals */
     520            }
     521
     522            p1 = rotmat * p1;
     523            p2 = rotmat * p2;
     524
     525            if (!smooth)
     526            {
     527                AppendQuadVert(p1);
     528                AppendQuadVert(p2);
     529                SetCurVertColor(m_color2);
     530
     531                AppendQuad(i * 4 + 2, i * 4 + 3, i * 4 + 1, i * 4, vbase);
     532                if (dualside)
     533                    AppendQuad(i * 4, i * 4 + 1, i * 4 + 3, i * 4 + 2, vbase);
     534            }
     535        }
     536
     537        if (!smooth)
     538            ComputeQuadNormals(ibase, m_quadidx.Count() - ibase);
     539    }
    497540
    498541    void AppendSphere(vec3 const &size, int divisions)
Note: See TracChangeset for help on using the changeset viewer.