light : replaced duplicated code by methods from Intersection

experimental
Dokthar 9 years ago
parent 505aa23048
commit 4be09e3505
  1. 2
      jme3-core/src/main/java/com/jme3/light/PointLight.java
  2. 7
      jme3-core/src/main/java/com/jme3/light/SpotLight.java

@ -203,7 +203,7 @@ public class PointLight extends Light {
return true; return true;
} else { } else {
// Sphere v. sphere collision // Sphere v. sphere collision
return sphere.getCenter().subtract(position).lengthSquared() < FastMath.sqr(radius + sphere.getRadius()); return Intersection.intersect(sphere, position, radius);
} }
} }

@ -34,6 +34,7 @@ package com.jme3.light;
import com.jme3.bounding.BoundingBox; import com.jme3.bounding.BoundingBox;
import com.jme3.bounding.BoundingSphere; import com.jme3.bounding.BoundingSphere;
import com.jme3.bounding.BoundingVolume; import com.jme3.bounding.BoundingVolume;
import com.jme3.bounding.Intersection;
import com.jme3.export.*; import com.jme3.export.*;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
@ -189,9 +190,7 @@ public class SpotLight extends Light {
if (this.spotRange > 0f) { if (this.spotRange > 0f) {
// Check spot range first. // Check spot range first.
// Sphere v. box collision // Sphere v. box collision
if (FastMath.abs(box.getCenter().x - position.x) >= spotRange + box.getXExtent() if (!Intersection.intersect(box, position, spotRange)) {
|| FastMath.abs(box.getCenter().y - position.y) >= spotRange + box.getYExtent()
|| FastMath.abs(box.getCenter().z - position.z) >= spotRange + box.getZExtent()) {
return false; return false;
} }
} }
@ -231,7 +230,7 @@ public class SpotLight extends Light {
if (this.spotRange > 0f) { if (this.spotRange > 0f) {
// Check spot range first. // Check spot range first.
// Sphere v. sphere collision // Sphere v. sphere collision
if (sphere.getCenter().subtract(position).lengthSquared() >= FastMath.sqr(spotRange + sphere.getRadius())) { if (!Intersection.intersect(sphere, position, spotRange)) {
return false; return false;
} }
} }

Loading…
Cancel
Save