Get xyz coordinates of vertices inside ofMesh

Hi guys!
I’m just starting with OF but I have a good background in 3d graphics
(so I’m trying to do some of the things that I would do in Maya only through OF, and it’s very exciting!) .

My simple problem is: I’d like to add more or less random movement to the vertices of a mesh based on their distance from a point light.

I’m currently moving the vertices using this code, which is having some (unintended) results:

for(ofVec3f & vertex : mesh.getVertices()){ lightDistance = ofDist(pointLight1.getPosition().x, pointLight1.getPosition().y, pointLight1.getPosition().z, vertex.x, vertex.y, vertex.z); if(lightDistance < 1000){ vertex += ofVec3f(ofRandom(-1, 1) * lightDistance/300); } }

I guess I need to have the vertex xyz coordinates in world space, or something like that…
Does anybody know how to achieve this?

Namasté

Hello,

Maybe you could try the ofVec3f distance function

lightDistance = pointLight.distance(vertex);
1 Like

Thanks @Gallo !
But the result is similar… (maybe ofVec3f.distance() is just wrapping ofDistance())
Here’s a short video documenting the result:
On the top left margin I’m printing the distance, and as you can see there’s something strange :grimacing: :