소스 검색

light : replaced duplicated code by methods from Intersection

Dokthar 10 년 전
부모
커밋
4be09e3505
2개의 변경된 파일4개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      jme3-core/src/main/java/com/jme3/light/PointLight.java
  2. 3 4
      jme3-core/src/main/java/com/jme3/light/SpotLight.java

+ 1 - 1
jme3-core/src/main/java/com/jme3/light/PointLight.java

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

+ 3 - 4
jme3-core/src/main/java/com/jme3/light/SpotLight.java

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