/** * Get the triangles at the specified grid point. Probably only 2 triangles * @param x local to the terrain patch * @param z local to the terrain patch * @return the triangles in world coordinates, or null if the point does intersect this patch on the XZ axis */ public Triangle[] getGridTriangles(float x, float z) { return geomap.getGridTrianglesAtPoint(x, z, getWorldScale() , getWorldTranslation()); }
/** * Get the two triangles that make up the grid section at the specified point, * translated to world coordinates. * * @param x local x coordinate * @param z local z coordinate * @param scale * @param translation * @return two triangles in world space not local space */ protected Triangle[] getGridTrianglesAtPoint(float x, float z, Vector3f scale, Vector3f translation) { Triangle[] tris = getGridTrianglesAtPoint(x, z); if (tris != null) { tris[0].get1().multLocal(scale).addLocal(translation); tris[0].get2().multLocal(scale).addLocal(translation); tris[0].get3().multLocal(scale).addLocal(translation); tris[1].get1().multLocal(scale).addLocal(translation); tris[1].get2().multLocal(scale).addLocal(translation); tris[1].get3().multLocal(scale).addLocal(translation); } return tris; }
/** * Get the triangle that the point is on. * * @param x coordinate in local space to the geomap * @param z coordinate in local space to the geomap * @return triangle in local space to the geomap */ protected Triangle getTriangleAtPoint(float x, float z) { Triangle[] triangles = getGridTrianglesAtPoint(x, z); if (triangles == null) { //System.out.println("x,z: " + x + "," + z); return null; } Vector2f point = new Vector2f(x, z); Vector2f t1 = new Vector2f(triangles[0].get1().x, triangles[0].get1().z); Vector2f t2 = new Vector2f(triangles[0].get2().x, triangles[0].get2().z); Vector2f t3 = new Vector2f(triangles[0].get3().x, triangles[0].get3().z); if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) { return triangles[0]; } t1.set(triangles[1].get1().x, triangles[1].get1().z); t1.set(triangles[1].get2().x, triangles[1].get2().z); t1.set(triangles[1].get3().x, triangles[1].get3().z); if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) { return triangles[1]; } return null; }
/** * Get the triangles at the specified grid point. Probably only 2 triangles * @param x local to the terrain patch * @param z local to the terrain patch * @return the triangles in world coordinates, or null if the point does intersect this patch on the XZ axis */ public Triangle[] getGridTriangles(float x, float z) { return geomap.getGridTrianglesAtPoint(x, z, getWorldScale() , getWorldTranslation()); }
/** * Get the two triangles that make up the grid section at the specified point, * translated to world coordinates. * * @param x local x coordinate * @param z local z coordinate * @param scale * @param translation * @return two triangles in world space not local space */ protected Triangle[] getGridTrianglesAtPoint(float x, float z, Vector3f scale, Vector3f translation) { Triangle[] tris = getGridTrianglesAtPoint(x, z); if (tris != null) { tris[0].get1().multLocal(scale).addLocal(translation); tris[0].get2().multLocal(scale).addLocal(translation); tris[0].get3().multLocal(scale).addLocal(translation); tris[1].get1().multLocal(scale).addLocal(translation); tris[1].get2().multLocal(scale).addLocal(translation); tris[1].get3().multLocal(scale).addLocal(translation); } return tris; }
/** * Get the triangle that the point is on. * * @param x coordinate in local space to the geomap * @param z coordinate in local space to the geomap * @return triangle in local space to the geomap */ protected Triangle getTriangleAtPoint(float x, float z) { Triangle[] triangles = getGridTrianglesAtPoint(x, z); if (triangles == null) { //System.out.println("x,z: " + x + "," + z); return null; } Vector2f point = new Vector2f(x, z); Vector2f t1 = new Vector2f(triangles[0].get1().x, triangles[0].get1().z); Vector2f t2 = new Vector2f(triangles[0].get2().x, triangles[0].get2().z); Vector2f t3 = new Vector2f(triangles[0].get3().x, triangles[0].get3().z); if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) { return triangles[0]; } t1.set(triangles[1].get1().x, triangles[1].get1().z); t1.set(triangles[1].get2().x, triangles[1].get2().z); t1.set(triangles[1].get3().x, triangles[1].get3().z); if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) { return triangles[1]; } return null; }