Skip to content

Instantly share code, notes, and snippets.

@vvzen
Last active April 25, 2018 23:09
Show Gist options
  • Save vvzen/419e002162ebf45244198eb051a9725b to your computer and use it in GitHub Desktop.
Save vvzen/419e002162ebf45244198eb051a9725b to your computer and use it in GitHub Desktop.
// a map used for storing distances between target and mesh points
// the key is a pair made by the target point and mesh point indices
// the value is the distance between those two points
std::map <pair<int,int>, float> distances_map;
for (int t = 0; t < target_points.size(); t++){
ofPoint random_point = target_points.at(t);
for (int p = 0; p < plane.getNumVertices(); p++){
ofPoint mesh_point = ofPoint(plane.getVertex(p));
float current_distance = ofDist(random_point.x, random_point.y, random_point.z, mesh_point.x, mesh_point.y, mesh_point.z);
// store this distance in the map so that we can later retrieve it quickly without recomputing it
pair<int, int> key = std::make_pair(t, p);
distances_map[key] = current_distance;
if (current_distance > max_distance) max_distance = current_distance;
}
}
// 2.2 apply the amplitude to the y axis of the vertex
for (int t = 0; t < target_points.size(); t++){
ofPoint random_point = target_points.at(t);
for (int p = 0; p < plane.getNumVertices(); p++){
ofPoint mesh_point = plane.getVertex(p);
// get the distance from the map where we stored it
pair<int, int> key = std::make_pair(t, p);
float current_distance = distances_map[key];
// float current_distance = ofDist(random_point.x, random_point.y, random_point.z, mesh_point.x, mesh_point.y, mesh_point.z);
// amp gets weaker the more distant it is from the point
float amp_strength = ofMap(current_distance, 0, max_distance, 0.5, 0);
float current_amplitude = sin(current_distance * frequency) * amp_strength * amplify_factor;
mesh_point.z += current_amplitude;
plane.setVertex(p, mesh_point);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment