We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to get a ball moving on a mesh and have it react according to the slope of the mesh. I have calculated all the slopes of the vertexes and saved the values in an arraylist called slope. I can find the closest vertex to my moving ball, but I am not able to figure out how to access the id number of the vertex to get the slope out of my arraylist. Any help will be appreciated.
Thanks
the code i used
import processing.opengl.*;
import toxi.geom.*;
import java.util.Iterator;
import java.util.*;
import peasy.*;
import wblut.math.*;
import wblut.processing.*;
import wblut.core.*;
import wblut.hemesh.*;
import wblut.geom.*;
ArrayList Slope = new ArrayList();
HE_Mesh mesh;
WB_KDTree vertexTree;
WB_Render render;
WB_Coord mnorm;
PeasyCam cam;
int speedx =1;
int speedy =1;
void setup() {
size(700, 700, P3D);
frameRate(30);
smooth();
cam = new PeasyCam(this, 1200);
mesh = new HEC_FromOBJFile(sketchPath("meshtoimport2.obj")).create();
vertexTree = mesh.getVertexTree();
int novert = mesh.getNumberOfVertices();
for (int i=0; i< novert; i++) {
mnorm = mesh.getVertexNormal(i);
float xnPos = (Float) mnorm.xf();
float ynPos = (Float) mnorm.yf();
float znPos = (Float) mnorm.zf();
Vec3D mnormv = new Vec3D(xnPos, ynPos, znPos);
Vec3D mvert = new Vec3D(0, 0, 1);
float slope = mnormv.angleBetween(mvert);
slope = degrees(slope);
Slope.add(slope);
}
render = new WB_Render( this );
}
void draw() {
background(0);
lights();
noStroke();
render.drawFaces(mesh);
stroke(255, 0, 255);
strokeWeight(.5);
render.drawFaceNormals(2, mesh);
speedx = speedx+1;
speedy = speedy+1;
WB_Point tpos = new WB_Point(speedx, speedy, 0);
WB_Coord ptonmesh = mesh.getClosestPoint(tpos, vertexTree);
HE_Vertex meshPt = mesh.getClosestVertex(tpos, vertexTree);
float xPos = (Float) ptonmesh.xf();
float yPos = (Float) ptonmesh.yf();
float zPos = (Float) ptonmesh.zf();
fill(60, 60, 200, 200);
translate(xPos, yPos, zPos);
sphere(15);
}
Answers
highlight code, press ctrl-o to format.
thanks, do you know how to get the vertex id?
Before line 50 just store the id in the slope
Thanks Chrisir, the thing is I have the id from line 50. Its when I run line 70 I get the the closest vertex, but not the id. Is it possible to get the id in HE MEsh or by some other method?
I mean is there any way in HEMesh to get the id instead of closest vertex on line 70?
you could use a Hashmap<HE_Vertex, Integer>, store them during your setup loop, use it to lookup the index in draw...
(if you're only going to use the index to look up the slope then you can put the slope into the hashmap instead of the index)
Thanks thats solved it :)
Here is the updated code if anyone else is looking for it