List of usage examples for com.badlogic.gdx.math Vector3 dst2
@Override
public float dst2(Vector3 point)
From source file:com.mygdx.game.pathfinding.NavMesh.java
License:Apache License
/** * Ray tests the navmesh along up/down axis, if no triangles are found, it makes an * exhaustive search of all triangles on the navmesh. * * TODO: Exhaustive search is somewhat expensive depending on amount of * triangles in navmesh, maybe something like quadtrees can be used? * * @param fromPoint Test point/*w w w . j av a 2 s . c om*/ * @param closestPoint Output for closest point on closest triangle * @param allowedMeshParts Indices of which mesh parts to ray test. If null, do only an exhaustive search. * @return The closest triangle */ public Triangle getClosestTriangle(Vector3 fromPoint, Vector3 closestPoint, Bits allowedMeshParts) { Triangle fromTri = null; float minDst2 = Float.POSITIVE_INFINITY; if (allowedMeshParts != null) { for (int meshPartIndex = 0; meshPartIndex < graph.getMeshPartCount(); meshPartIndex++) { if (!allowedMeshParts.get(meshPartIndex)) { continue; } Triangle tri = verticalRayTest(fromPoint, tmpGetClosestTriangle, meshPartIndex); float dst2 = fromPoint.dst2(tmpGetClosestTriangle); if (dst2 < minDst2) { minDst2 = dst2; fromTri = tri; closestPoint.set(tmpGetClosestTriangle); } } } // Exhaustive scan through all the tris to find the closest tri and point if (fromTri == null) { for (int i = 0; i < graph.getNodeCount(); i++) { Triangle tri = graph.getTriangleFromGraphIndex(i); float dst2 = GeometryUtils.getClosestPointOnTriangle(tri.a, tri.b, tri.c, fromPoint, tmpGetClosestTriangle); if (dst2 < minDst2) { minDst2 = dst2; fromTri = tri; closestPoint.set(tmpGetClosestTriangle); } } } return fromTri; }