List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D getNorm
public double getNorm()
From source file:services.SimulationService.java
public boolean checkLineOfSightInBuilding(SWGObject obj1, SWGObject obj2, SWGObject building) { PortalVisitor portalVisitor = building.getPortalVisitor(); if (portalVisitor == null) return true; Point3D position1 = obj1.getPosition(); Point3D position2 = obj2.getPosition(); Point3D origin = new Point3D(position1.x, position1.y + 1, position1.z); Point3D end = new Point3D(position2.x, position2.y + 1, position2.z); Vector3D direction = new Vector3D(end.x - origin.x, end.y - origin.y, end.z - origin.z); if (direction.getNorm() != 0) { direction.normalize();/*from w w w .java2 s . c om*/ } else { System.out.println("WARNING: checkLineOfSightInBuilding: Vector norm was 0."); } float distance = position1.getDistance2D(position2); Ray ray = new Ray(origin, direction); for (int i = 1; i < portalVisitor.cells.size(); i++) { Cell cell = portalVisitor.cells.get(i); try { MeshVisitor meshVisitor; if (!cellMeshes.containsKey(cell.mesh)) { meshVisitor = ClientFileManager.loadFile(cell.mesh, MeshVisitor.class); meshVisitor.getTriangles(); cellMeshes.put(cell.mesh, meshVisitor); } else { meshVisitor = cellMeshes.get(cell.mesh); } if (meshVisitor == null) continue; List<Mesh3DTriangle> tris = meshVisitor.getTriangles(); if (tris.isEmpty()) continue; for (Mesh3DTriangle tri : tris) { if (ray.intersectsTriangle(tri, distance) != null) { // System.out.println("Collision with: " + cell.name); return false; } } } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } } return true; }