/* outdated, was implementing a universal (convex or concave) mesh vs ray check * * public static void checkMeshRayCollision(SpatialVectorDouble rayOrigin, SpatialVectorDouble rayDirection, PhysicsComponentAndCollidersPair physicsComponentAndMesh, CollisionDescriptor collisionDescriptor) { * TransformedMeshComponent transformedMeshComponent = physicsComponentAndMesh.transformedMeshComponent; * * PlueckerCoordinate plueckerCoordinateOfRay = PlueckerCoordinate.createByVector(rayOrigin, rayDirection); * * for(int faceIndex = 0; faceIndex < transformedMeshComponent.meshComponent.mesh.faces.Length; faceIndex++) { * if( !doesFaceIntersectRay(plueckerCoordinateOfRay, (uint)faceIndex, transformedMeshComponent) ) { * continue; * } * * SpatialVectorDouble planeNormal; * SpatialVectorDouble planeOrigin; * { * uint * vertexIndex0 = physicsComponentAndMesh.transformedMeshComponent.meshComponent.mesh.faces[faceIndex].verticesIndices[0], * vertexIndex1 = physicsComponentAndMesh.transformedMeshComponent.meshComponent.mesh.faces[faceIndex].verticesIndices[1], * vertexIndex2 = physicsComponentAndMesh.transformedMeshComponent.meshComponent.mesh.faces[faceIndex].verticesIndices[2]; * * SpatialVectorDouble * p0 = physicsComponentAndMesh.transformedMeshComponent.transformedVertices[vertexIndex0], * p1 = physicsComponentAndMesh.transformedMeshComponent.transformedVertices[vertexIndex1], * p2 = physicsComponentAndMesh.transformedMeshComponent.transformedVertices[vertexIndex2]; * * SpatialVectorDouble * diff01 = p1 - p0, * diff02 = p2 - p0; * * planeOrigin = p0; * * planeNormal = SpatialVectorDouble.crossProduct(diff01, diff02); * // TODO< normalize > * } * * // calculate distance of intersection to face * double intersectionDistance = WhiteSphereEngine.geometry.Plane.calcD(planeOrigin, planeNormal, rayOrigin, rayDirection); * * // check if distance to plane is smaller than the last collision and bigger than 0.0 * if ( intersectionDistance < 0.0 ) { * continue; * } * * if (collisionDescriptor.rayDistance < intersectionDistance) { * continue; * } * * // store collision information * collisionDescriptor.rayDistance = intersectionDistance; * collisionDescriptor.faceIndex = (uint)faceIndex; * collisionDescriptor.faceNormal = planeNormal; * collisionDescriptor.physicsComponentAndMesh = physicsComponentAndMesh; * collisionDescriptor.hit = true; * } * } */ public static bool doesFaceIntersectRay(PlueckerCoordinate plueckerCoordinate, uint faceIndex, TransformedMeshComponent transformedMeshComponent) { uint[] verticesIndices = transformedMeshComponent.meshComponent.mesh.faces[(int)faceIndex].verticesIndices; for (int edgeIndex = 0; edgeIndex < verticesIndices.Length - 1; edgeIndex++) { uint vertexIndex0 = verticesIndices[edgeIndex]; uint vertexIndex1 = verticesIndices[edgeIndex + 1]; SpatialVectorDouble vertex0 = transformedMeshComponent.transformedVertices[vertexIndex0]; SpatialVectorDouble vertex1 = transformedMeshComponent.transformedVertices[vertexIndex1]; if (!checkPlueckerCoordinateAgainstEdge(plueckerCoordinate, vertex1, vertex0)) { return(false); } } // check last vertex to first { SpatialVectorDouble vertex0 = transformedMeshComponent.transformedVertices[verticesIndices.Length - 1]; SpatialVectorDouble vertex1 = transformedMeshComponent.transformedVertices[0]; if (!checkPlueckerCoordinateAgainstEdge(plueckerCoordinate, vertex1, vertex0)) { return(false); } } return(true); }
static bool checkPlueckerCoordinateAgainstEdge(PlueckerCoordinate plueckerCoordinate, SpatialVectorDouble vertex0, SpatialVectorDouble vertex1) { PlueckerCoordinate plueckerCoordinateOfEdge = PlueckerCoordinate.createByPandQ(vertex0, vertex1); return(PlueckerCoordinate.checkCcw(plueckerCoordinate, plueckerCoordinateOfEdge)); }