Hopefully someone knows enough about toxiclibs to help me out here...
I am trying to hide faces on a mesh that are hidden from the current camera position (obscured by some other face on the mesh). To do this I am trying to implement the intersectsRay method in the toxiclibs TriangleMesh class. However, when I retrieve the intersection pos vector from isectData3d it just spits out a bunch of points on a plane, not intersection points with the mesh. I have tried reversing the ray, which gives me some very wacky points - but still not intersection points on the mesh. Heres the function I am using:
public void updateDisplayFaces(Vec3D fromPos){ //loop through faces for(int i = 0;i<bounds.faces.size();i++){ WEFace f = (WEFace) bounds.faces.get(i); //create an intersector between face center and camera pos Vec3D target = f.getCentroid().copy(); Ray3D isec = new Ray3D(fromPos,target); //intersect the mesh if( bounds.intersectsRay(isec)){ IsectData3D data = bounds.getIntersectionData(); if(data.isIntersection){ Vec3D ipos = data.pos.copy(); parent.stroke(255); parent.point(ipos.x,ipos.y,ipos.z);
} } } }
Any suggestions of help with using these intersection methods? I dont want to have to use TriangleIntersector3d because looping through all the mesh faces gets very slow.
I am trying to move agents from within one triangle to another in 2d. I am currently achieving this by looping through the triangles edges, checking for an intersection, and moving to the corrosponding edge on the new triangle. I then perform a containment check to see whether the agent should move in one of 2 directions.
However, I am getting some problems when my agent is very close to the triangles corner. Ideally I want to test for containment within the triangle by placing my agent on an edge of the triangle, and then moving it in each of the two possible vectors by an infinitesimally small amount to test containment, to avoid the possibility of the movement causing the agent to 'skip around the corner' of the triangle. But when I try scaling the vectors like so, the isInTriangle method doesnt return true. Any ideas?
vel = N.copy(); vel.rotate(angleA);
//check to see if velocity pushes away from face
// - this is where things break, I cannot scale the vel
//vector to less than around 0.1 of a unit or things break.
//but ideally this is tiny, like 0.0001
Vec2D push =loc.add(vel.scale(0.1));
Vec2D a = onFace.a.to2DXY(); Vec2D b = onFace.b.to2DXY(); Vec2D c = onFace.c.to2DXY();
if(push.isInTriangle(a,b,c)){ }else{ //reverse vector relative to edge vel = N.copy(); vel.rotate(angleB); }