Skip to content

Instantly share code, notes, and snippets.

@larsberg
Last active August 29, 2015 14:08
Show Gist options
  • Save larsberg/ab03dfc1498c9b514ba3 to your computer and use it in GitHub Desktop.
Save larsberg/ab03dfc1498c9b514ba3 to your computer and use it in GitHub Desktop.

Revisions

  1. larsberg revised this gist Nov 5, 2014. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions createOFGeometries
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ static void makeScreenQuad(ofMesh& m, float w=2, float h=2)
    m.addIndex(3);
    }

    static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    static void makeBoxMesh(ofMesh& m, float w, float h, float d)
    {
    w *= .5, h *= .5, d *= .5;

    @@ -40,7 +40,7 @@ static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    m.addVertex(ofVec3f( w, h,-d));
    m.addVertex(ofVec3f( w,-h,-d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,0,-1)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    @@ -52,7 +52,7 @@ static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    m.addVertex(ofVec3f(-w, h,-d));
    m.addVertex(ofVec3f(-w,-h,-d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addNormals(vector<ofVec3f>(4, ofVec3f(-1,0,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    @@ -64,7 +64,7 @@ static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    m.addVertex(ofVec3f(-w, h, d));
    m.addVertex(ofVec3f(-w,-h, d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,0,1)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    @@ -76,7 +76,7 @@ static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    m.addVertex(ofVec3f( w, h, d));
    m.addVertex(ofVec3f( w,-h, d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addNormals(vector<ofVec3f>(4, ofVec3f(1,0,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    @@ -89,7 +89,7 @@ static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    m.addVertex(ofVec3f(-w,-h, d));
    m.addVertex(ofVec3f(-w,-h,-d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,-1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

  2. larsberg revised this gist Nov 5, 2014. 2 changed files with 108 additions and 25 deletions.
    108 changes: 108 additions & 0 deletions createOFGeometries
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,108 @@
    static void makeScreenQuad(ofMesh& m, float w=2, float h=2)
    {
    w *= .5;
    h *= .5;
    m.clear();

    m.addVertex(ofVec3f(-w,-h,0));
    m.addVertex(ofVec3f( w,-h,0));
    m.addVertex(ofVec3f( w, h,0));
    m.addVertex(ofVec3f(-w, h,0));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,0,-1)));

    m.addTexCoord(ofVec2f(0,1));
    m.addTexCoord(ofVec2f(1,1));
    m.addTexCoord(ofVec2f(1,0));
    m.addTexCoord(ofVec2f(0,0));

    m.addIndex(0);
    m.addIndex(1);
    m.addIndex(2);
    m.addIndex(0);
    m.addIndex(2);
    m.addIndex(3);
    }

    static void makeBoxMesh(ofMesh& m, float w=1, float h=1, float d=1)
    {
    w *= .5, h *= .5, d *= .5;

    m.clear();

    int i0, i1, i2, i3;

    // back
    i0 = m.getVertices().size(), i1 = i0+1, i2 = i1+1, i3 = i2+1;

    m.addVertex(ofVec3f(-w,-h,-d));
    m.addVertex(ofVec3f(-w, h,-d));
    m.addVertex(ofVec3f( w, h,-d));
    m.addVertex(ofVec3f( w,-h,-d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    // left
    i0 = m.getVertices().size(), i1 = i0+1, i2 = i1+1, i3 = i2+1;

    m.addVertex(ofVec3f(-w,-h, d));
    m.addVertex(ofVec3f(-w, h, d));
    m.addVertex(ofVec3f(-w, h,-d));
    m.addVertex(ofVec3f(-w,-h,-d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    // front
    i0 = m.getVertices().size(), i1 = i0+1, i2 = i1+1, i3 = i2+1;

    m.addVertex(ofVec3f( w,-h, d));
    m.addVertex(ofVec3f( w, h, d));
    m.addVertex(ofVec3f(-w, h, d));
    m.addVertex(ofVec3f(-w,-h, d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);

    // right
    i0 = m.getVertices().size(), i1 = i0+1, i2 = i1+1, i3 = i2+1;

    m.addVertex(ofVec3f( w,-h,-d));
    m.addVertex(ofVec3f( w, h,-d));
    m.addVertex(ofVec3f( w, h, d));
    m.addVertex(ofVec3f( w,-h, d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);


    // top
    i0 = m.getVertices().size(), i1 = i0+1, i2 = i1+1, i3 = i2+1;

    m.addVertex(ofVec3f( w,-h,-d));
    m.addVertex(ofVec3f( w,-h, d));
    m.addVertex(ofVec3f(-w,-h, d));
    m.addVertex(ofVec3f(-w,-h,-d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);


    // bottom
    i0 = m.getVertices().size(), i1 = i0+1, i2 = i1+1, i3 = i2+1;

    m.addVertex(ofVec3f( w, h, d));
    m.addVertex(ofVec3f( w, h,-d));
    m.addVertex(ofVec3f(-w, h,-d));
    m.addVertex(ofVec3f(-w, h, d));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,1,0)));
    m.addTexCoord(ofVec2f(0,0)), m.addTexCoord(ofVec2f(0,1)), m.addTexCoord(ofVec2f(1,1)), m.addTexCoord(ofVec2f(1,0));
    m.addIndex(i0), m.addIndex(i1), m.addIndex(i2), m.addIndex(i0), m.addIndex(i2), m.addIndex(i3);
    }
    25 changes: 0 additions & 25 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,25 +0,0 @@
    static void createScreenQuad(ofMesh& m, float w=2, float h=2)
    {
    w *= .5;
    h *= .5;
    m.clear();

    m.addVertex(ofVec3f(-w,-h,0));
    m.addVertex(ofVec3f( w,-h,0));
    m.addVertex(ofVec3f( w, h,0));
    m.addVertex(ofVec3f(-w, h,0));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,0,-1)));

    m.addTexCoord(ofVec2f(0,1));
    m.addTexCoord(ofVec2f(1,1));
    m.addTexCoord(ofVec2f(1,0));
    m.addTexCoord(ofVec2f(0,0));

    m.addIndex(0);
    m.addIndex(1);
    m.addIndex(2);
    m.addIndex(0);
    m.addIndex(2);
    m.addIndex(3);
    }
  3. larsberg created this gist Nov 5, 2014.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    static void createScreenQuad(ofMesh& m, float w=2, float h=2)
    {
    w *= .5;
    h *= .5;
    m.clear();

    m.addVertex(ofVec3f(-w,-h,0));
    m.addVertex(ofVec3f( w,-h,0));
    m.addVertex(ofVec3f( w, h,0));
    m.addVertex(ofVec3f(-w, h,0));

    m.addNormals(vector<ofVec3f>(4, ofVec3f(0,0,-1)));

    m.addTexCoord(ofVec2f(0,1));
    m.addTexCoord(ofVec2f(1,1));
    m.addTexCoord(ofVec2f(1,0));
    m.addTexCoord(ofVec2f(0,0));

    m.addIndex(0);
    m.addIndex(1);
    m.addIndex(2);
    m.addIndex(0);
    m.addIndex(2);
    m.addIndex(3);
    }