Positioning effectively with ofNode and ofMesh


I’m currently working on a procedural terrain toolkit, and running into some quirky problems with local/global positioning. I’m curious if/how ofNode could be useful in this situation, or just some general guidance on how to most effectively approach this.

I have two classes:

One is a ProceduralMap class, containing ofPixels and an ofTexture. These (for now) are using ARB textures.

The other is a ProceduralTerrain class, which holds an ofVboMesh (using ofMesh::plane()).

When I attempt to sample from the map to displace my plane, I run into an issue. The mesh generated by ofMesh::plane() positions the object centered at 0,0,0.

void ofxProceduralTerrain::displace(){
    for(int i = 0; i < mesh.getNumVertices(); i++){
        ofVec3f position = mesh.getVertex(i);
        position.z = elevation->sample(position + (city->dimensions / 2.0));
        mesh.setVertex(i, position);

int ofxProceduralMap::sample(ofVec2f st){
    return pix.getColor(floor(st.x),floor(st.y)).r;

I of course can just shift the position before sampling, but this feels tedious to work between two coordinate spaces in this way.

I also find it more intuitive to sample by x,y position, and displace the z value. This doesn’t work in my favor when it comes to drawing and using a camera, requiring me to either rotate all of my objects, or rotate the camera.

I feel like I must be able to utilize ofNode here, and give it the responsibility of maintaining the global position / rotation, separately from the local coordinates used for sampling and other calculations.

What might be the best way to get started with this? I’ve only ever seen ofNode utilized with some of3dPrimitive, can I attach nodes to arbitrary objects? Should all of my classes extend ofNode?


When sampling, you could use ofMap and map the two different spaces?:

int ofxProceduralMap::sample(ofVec2f st){
    int x = ofMap(st.x,minPlaneX,maxPlaneX, minImgX,maxImgX);
    int y = ofMap(st.y,minPlaneY,maxPlaneY, minImgY,maxImgY);
    return pix.getColor(floor(y),floor(y)).r;


That would absolutely work for the sampling. Late yesterday I ended up just abandoning ofMesh::plane, now just generating my own with the right coordinates but some of my uncertainty about ofNode and positioning remain, but allowing the sample method to accept some mapping parameters would be useful.

Can I (or should I) use ofNode to manage the transform of my various systems? Similar to how I might have an object hierarchy in Unity or something like that? I just don’t have any experience applying ofNode transformation to custom meshes or point vectors.


ofNode is effectively pretty similar to the transformation hierarchy in unity or any 3d software so you can use it in the same way to position things on a 3d scene