Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Positioning effectively with ofNode and ofMesh

$
0
0

@aceslowman wrote:

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);
        mesh.addTexCoord((ofVec2f)position);
        mesh.addColor(ofColor(position.z));
    }
}

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?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles