Add rudimentary cone v. frustum intersection test for light culling.

Restrict spot light angles to be between [0, pi/2]
experimental
shadowislord 10 years ago
parent 9435d28431
commit b51f015fb9
  1. 27
      jme3-core/src/main/java/com/jme3/light/SpotLight.java

@ -140,8 +140,17 @@ public class SpotLight extends Light implements Savable {
@Override @Override
public boolean intersectsFrustum(Camera camera, TempVars vars) { public boolean intersectsFrustum(Camera camera, TempVars vars) {
// TODO: implement cone vs. frustum collision detection. if (this.spotRange == 0) {
return true; return true;
} else {
// Do a frustum v. sphere test against the spot range.
for (int i = 5; i >= 0; i--) {
if (camera.getWorldPlane(i).pseudoDistance(position) <= -spotRange) {
return false;
}
}
return true;
}
} }
@Override @Override
@ -197,8 +206,8 @@ public class SpotLight extends Light implements Savable {
throw new IllegalArgumentException("SpotLight range cannot be negative"); throw new IllegalArgumentException("SpotLight range cannot be negative");
} }
this.spotRange = spotRange; this.spotRange = spotRange;
if (spotRange != 0) { if (spotRange != 0f) {
this.invSpotRange = 1 / spotRange; this.invSpotRange = 1f / spotRange;
} else { } else {
this.invSpotRange = 0; this.invSpotRange = 0;
} }
@ -222,10 +231,16 @@ public class SpotLight extends Light implements Savable {
/** /**
* Sets the inner angle of the cone of influence. * Sets the inner angle of the cone of influence.
* <p>
* Must be between 0 and pi/2.
* <p>
* This angle is the angle between the spot direction axis and the inner border of the cone of influence. * This angle is the angle between the spot direction axis and the inner border of the cone of influence.
* @param spotInnerAngle * @param spotInnerAngle
*/ */
public void setSpotInnerAngle(float spotInnerAngle) { public void setSpotInnerAngle(float spotInnerAngle) {
if (spotInnerAngle < 0f || spotInnerAngle >= FastMath.HALF_PI) {
throw new IllegalArgumentException("spot angle must be between 0 and pi/2");
}
this.spotInnerAngle = spotInnerAngle; this.spotInnerAngle = spotInnerAngle;
computeAngleParameters(); computeAngleParameters();
} }
@ -240,11 +255,17 @@ public class SpotLight extends Light implements Savable {
/** /**
* Sets the outer angle of the cone of influence. * Sets the outer angle of the cone of influence.
* <p>
* Must be between 0 and pi/2.
* <p>
* This angle is the angle between the spot direction axis and the outer border of the cone of influence. * This angle is the angle between the spot direction axis and the outer border of the cone of influence.
* this should be greater than the inner angle or the result will be unexpected. * this should be greater than the inner angle or the result will be unexpected.
* @param spotOuterAngle * @param spotOuterAngle
*/ */
public void setSpotOuterAngle(float spotOuterAngle) { public void setSpotOuterAngle(float spotOuterAngle) {
if (spotOuterAngle < 0f || spotOuterAngle >= FastMath.HALF_PI) {
throw new IllegalArgumentException("spot angle must be between 0 and pi/2");
}
this.spotOuterAngle = spotOuterAngle; this.spotOuterAngle = spotOuterAngle;
computeAngleParameters(); computeAngleParameters();
} }

Loading…
Cancel
Save