Noobie moving from Processing to oF. What is equivalent in oF for Pshape?

Hello

My first post and sorry for being such a noob with this.

Iâ€™ve read some tutorials and been practicing C++ for a bit too but Iâ€™m having difficulties understanding the openFrameworks documentation since it hasnâ€™t got any examples. So my question is that what is the equivalent or PShape and vertices in OF? I want to create a 3D space(a room basically) and that the walls would constitute of looped lines.

So what I need is rather simple: four XYZ cordinates and make four looped vertical lines between them, so basically it is just 3D cube made with looped lines. How to proceed with this, the ofDrawLine allows only X and Y.

Thanks!

What you need is probably ofMesh (or ofVboMesh. Look for these classes in the documentation

Hi Buoyancist,

Iâ€™m learning oF right now too, but without knowing any Processing at all. There are some great examples in ofBook and the OF Video Series (in the Learning tab of the website), but sometimes you have to dig a bit, and some of the example code in ofBook is a bit dated now (deprecated). The ofBook -> Basics -> Gaphics tutorial has a sectiion on ofPolylines which could be helpful for you. They use 2-D vertices in the example, but 3-D could be used (?). Also, the ofBook -> Approaches -> Animation chapter has an example with using ofNoise to generate vertices that are drawn with ofBeginShape() and ofEndShape(). Also, it looks like a version ofDrawLine() can be used with 3-D coordinates, but Iâ€™ve only used it with 2 dimensions. Hope this helps and Iâ€™ll bet youâ€™ve figured it out by now.

Tim

Thanks for your replies Ain & Tim!

I ended up using Polylines and that ofBeginShape() and ofEndShape() and was able to do what I wanted to. Though now I need to start all over again since didnâ€™t read enough before started working on the whole thing I wonder what is the fastest way to draw lines, there seems to be so many options and what is the best way to create vertices. ofPolyline, ofDrawLine, lineTo, ofPath, ofVec3f, ofMesh, ofVboMeshâ€¦

As far as I know now the ofMesh or ofVboMesh is probably the way I will try it now with the OF_PRIMITIVE_LINES mode. The ofMesh seems to be the best/proper way to do stuff in OF? Though this thread says that the OF_PRIMITIVE_LINES is a slow way:

And the openGL chapter in of book says it might not work on every platform/device as says this thread too:

Been working with the OF_PRIMITIVE_LINES now and donâ€™t really understand this one thing. The amount of lines I have changes even though the amount of vertices stay the same. My code looks likes this:

void ofApp::setup(){
ofEnableDepthTest();

``````int wallMax = 1000;
int wallLow = 0;
int wallTop = 200;

wall1.setMode(OF_PRIMITIVE_LINES);
wall1.enableIndices();
wall1.enableTextures();
wall1.enableNormals();
wall1.enableColors();

for (int i = 0; i < (0.75*wallMax); i += wallAdd) {
wall1.addColor(ofFloatColor(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1)));
wall1.addColor(ofFloatColor(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1)));
}

int numVerts = wall1.getNumVertices();

for (int i = 0; i < numVerts; i++) {
}
``````

}

So for example if I remove the first addColor in the for-loop I get half the amount of lines I do now even though the amount of Vertices stay the same. I checked it with BitmapString and getNumVertices(). Why is that? Clearly the addColor isnâ€™t creating any more vertices so I donâ€™t really understand where the extra(or fewer if you want) lines come from. Iâ€™m not sure if that is the right way to do indices for lines but it works. Also tried this way that I found from the first thread I posted before but I donâ€™t quite understand it. So if somebody knows I would be greatly thankful for an explanation

`````` for (int i = 0; i < numVerts; i++) {
}
``````

Hopefully this Noobie thread is helpful for somebody else too as for me at least the oFbook and tutorials didnâ€™t quite clear everything regarding ofMesh etc.

Hi again Buoyancist,

I just finished the GL section of ofBook; it took me a while to get thru that. So, those examples use OF_PRIMITIVE_TRIANGLES, but you could see if the following applies to using OF_PRIMITIVE_LINES. Basically, the vertices of the mesh are set (along with colors and textures if appropriate), and then the mesh is indexed according to the order of drawing. So, in the case of triangles, three sequential indexes create 1 triangle, and the subsequent three create the next, etc. Indexes are repeated if necessary, and are ordered in a regular and consistent way. So, drawing a square (2 triangles) uses 4 vertices (1, 2, 3, 4) and 6 indexes((1, 2, 3), (2, 4, 3)). The order of indicies is important.

So with that in mind, if youâ€™re creating indices without color, and they are in indexed and drawn in the order that theyâ€™re created, could the triangle-nature of the GPU explain why there are 1/2 as many lines as when that color is specified? I guess the GPU interpolates between colors when they are different, and since it seems to see the world as triangles, maybe its interpolating the color of the line differently depending on the location of the vertex in a world of triangles (instead of lines). In other words, for 4 vertices, the first triangle will form from indexes 1-3, with vertexes 1, 3 having a defined color and 2 having an undefined color. The second triangle will form from indexes 2-4, with vertexes 2, 4 having an undefined color and 3 having a defined color. So maybe it interprets the line from the first triangle as having an interpolated color, and the line from the second triangle as having undefined color. I could be completely wrong; this is pure speculation and a semi-educated guess. It would be fun to try omitting the color twice in every 4th run of the loop and see if fewer lines disappear. Or, you could try alternating the omitted color and see what happens with omitted lines.

Also, Iâ€™m still hazy on type conversions, but I wonder if the i < (0.75wallMax) is a float? If it is, then the true value could be something like 750.000001 or whatever, which would make 1 extra pair of vertices (but only sometimes (?)). So anyhow, you could try creating an int max = 0.75wallMax, and then using it in the loop as i < max. Or alternatively try i < ((int)(0.75*wallMax)). Iâ€™ve had plenty of trouble lately with integers, integer division, and type conversions. Hysterical but frustrating.

Again youâ€™ve probably figured these things out by now. Glad the ofBeginShape() and ofEndShape() from earlier worked. Iâ€™m not sure what the best way to make vertices is; to some degree I think it may matter what you end up doing with them. If theyâ€™re for an ofPolyline, then they may be best made â€śthat wayâ€ť, as opposed to an ofMesh (cpu side) or ofVboMesh (gpu side) which may be best made in a slightly different way. The different oF classes may have slightly different representations of â€śverticesâ€ť. Iâ€™m pretty sure that ofPoint is a psudeoname for ofVec3f. The ofMesh object resides on the cpu side of things, while the ofVboMesh is more of a gpu object (in gpu memory). The ofBook tutorial (if I remember right) explains that the ofVboMesh object also has some bool variables that track if its been updated or not. If not, it just redraws the same mesh from the gpu memory. If it has been updated, it gets an updated copy from the cpu (slow transfer time, relatively). But I think the ofMesh just sends a new copy to the gpu every time the mesh is drawn.

OK well anyway hope this helps. its been fun to write about it on a Sunday night. Take care.

Tim