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.
OF create geometries
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, float h, float d)
{
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,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);
// 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(-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);
// 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,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);
// 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(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);
// 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment