|
|
|
@ -32,6 +32,7 @@ |
|
|
|
|
package com.jme3.light; |
|
|
|
|
|
|
|
|
|
import com.jme3.bounding.BoundingBox; |
|
|
|
|
import com.jme3.bounding.BoundingSphere; |
|
|
|
|
import com.jme3.bounding.BoundingVolume; |
|
|
|
|
import com.jme3.export.*; |
|
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
@ -225,12 +226,49 @@ public class SpotLight extends Light { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean intersectsSphere(BoundingSphere sphere, TempVars vars) { |
|
|
|
|
if (this.spotRange > 0f) { |
|
|
|
|
// Check spot range first.
|
|
|
|
|
// Sphere v. sphere collision
|
|
|
|
|
if (sphere.getCenter().subtract(position).lengthSquared() >= FastMath.sqr(spotRange + sphere.getRadius())) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float otherRadiusSquared = FastMath.sqr(sphere.getRadius()); |
|
|
|
|
float otherRadius = sphere.getRadius(); |
|
|
|
|
|
|
|
|
|
// Check if sphere is within spot angle.
|
|
|
|
|
// Cone v. sphere collision.
|
|
|
|
|
Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1); |
|
|
|
|
Vector3f U = position.subtract(E, vars.vect2); |
|
|
|
|
Vector3f D = sphere.getCenter().subtract(U, vars.vect3); |
|
|
|
|
|
|
|
|
|
float dsqr = D.dot(D); |
|
|
|
|
float e = direction.dot(D); |
|
|
|
|
|
|
|
|
|
if (e > 0f && e * e >= dsqr * outerAngleCosSqr) { |
|
|
|
|
D = sphere.getCenter().subtract(position, vars.vect3); |
|
|
|
|
dsqr = D.dot(D); |
|
|
|
|
e = -direction.dot(D); |
|
|
|
|
|
|
|
|
|
if (e > 0f && e * e >= dsqr * outerAngleSinSqr) { |
|
|
|
|
return dsqr <= otherRadiusSquared; |
|
|
|
|
} else { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean intersectsFrustum(Camera cam, TempVars vars) { |
|
|
|
|
if (spotRange == 0) { |
|
|
|
|
// The algorithm below does not support infinite spot range.
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
Vector3f farPoint = vars.vect1.set(position).addLocal(vars.vect2.set(direction).multLocal(spotRange)); |
|
|
|
|
for (int i = 5; i >= 0; i--) { |
|
|
|
|
//check origin against the plane
|
|
|
|
|