Guess why this method isn't working" private static Vector3…
- User
Guess why this method isn't working"
private static Vector3 rayPointsQuadIntersection(Vector3 rayPoint1, Vector3 rayPoint2, Vector3 v1, Vector3 v2, Vector3 v3) { System.out.println(rayPoint1 + " " + rayPoint2); // Compute ray direction from two points Vector3 rayDirection = VectorUtils.subNew(rayPoint2, rayPoint1); rayDirection.normalize(); // The starting point of the ray remains the same as the first point Vector3 rayOrigin = rayPoint1; // 1. Compute the normal of the plane Vector3 a = VectorUtils.subNew(v2, v1); Vector3 b = VectorUtils.subNew(v3, v1); Vector3 normal = VectorUtils.cross(a, b); normal.normalize(); // 2. Check for ray-plane intersection double dotDifference = normal.dot(rayDirection); if(Math.abs(dotDifference) < 1e-6f) return null; // Parallel check double t = -normal.dot(VectorUtils.subNew(rayOrigin, v1)) / dotDifference; // Check if intersection is in the direction of the ray // And within the segment defined by rayPoint1 and rayPoint2 if(t < 0 || t > 1) return null; // Compute the potential collision point Vector3 collision = VectorUtils.addNew(rayOrigin, VectorUtils.scaleNew(rayDirection, t)); // 3. Project the collision point onto the plane defined by quad vertices Vector3 dMS1 = VectorUtils.subNew(collision, v1); double dotA = a.dot(a); double dotB = b.dot(b); double u = dMS1.dot(a) / dotA; double v = dMS1.dot(b) / dotB; // 4. Check if the point is within the quad bounds if(u >= 0.0f && u <= 1.0f && v >= 0.0f && v <= 1.0f) { // Collision within quad bounds return collision; } // No valid collision found return null; } - Assistant