diff --git a/src/box2dLight/PointLight.java b/src/box2dLight/PointLight.java index 2c13814..123f042 100644 --- a/src/box2dLight/PointLight.java +++ b/src/box2dLight/PointLight.java @@ -200,34 +200,29 @@ protected void updateDynamicShadowMeshes() { CircleShape shape = (CircleShape)fixtureShape; float r = shape.getRadius(); float dst = tmpVec.set(center).dst(start); - float a = (float)Math.acos(r/dst) * MathUtils.radDeg; + float a = (float) Math.acos(r/dst); l = data.getLimit(dst, height, distance); - tmpVec.set(start).sub(center).clamp(r, r).rotate(a); + tmpVec.set(start).sub(center).clamp(r, r).rotateRad(a); tmpStart.set(center).add(tmpVec); - dynamicSegments[size++] = tmpStart.x; - dynamicSegments[size++] = tmpStart.y; - dynamicSegments[size++] = colBits; - dynamicSegments[size++] = f; - - tmpEnd.set(tmpStart).sub(start).limit(l).add(tmpStart); - dynamicSegments[size++] = tmpEnd.x; - dynamicSegments[size++] = tmpEnd.y; - dynamicSegments[size++] = colBits; - dynamicSegments[size++] = f; - - tmpVec.rotate(-2f*a); - tmpStart.set(center).add(tmpVec); - dynamicSegments[size++] = tmpStart.x; - dynamicSegments[size++] = tmpStart.y; - dynamicSegments[size++] = colBits; - dynamicSegments[size++] = f; - tmpEnd.set(tmpStart).sub(start).limit(l).add(tmpStart); - dynamicSegments[size++] = tmpEnd.x; - dynamicSegments[size++] = tmpEnd.y; - dynamicSegments[size++] = colBits; - dynamicSegments[size++] = f; + float angle = (MathUtils.PI2 - 2f * a) / + RayHandler.CIRCLE_APPROX_POINTS; + for (int k = 0; k < RayHandler.CIRCLE_APPROX_POINTS; k++) { + tmpStart.set(center).add(tmpVec); + dynamicSegments[size++] = tmpStart.x; + dynamicSegments[size++] = tmpStart.y; + dynamicSegments[size++] = colBits; + dynamicSegments[size++] = f; + + tmpEnd.set(tmpStart).sub(start).limit(l).add(tmpStart); + dynamicSegments[size++] = tmpEnd.x; + dynamicSegments[size++] = tmpEnd.y; + dynamicSegments[size++] = colBits; + dynamicSegments[size++] = f; + + tmpVec.rotateRad(angle); + } } else if (type == Type.Edge) { EdgeShape shape = (EdgeShape)fixtureShape; diff --git a/src/box2dLight/RayHandler.java b/src/box2dLight/RayHandler.java index e35efb8..9d1b842 100644 --- a/src/box2dLight/RayHandler.java +++ b/src/box2dLight/RayHandler.java @@ -31,6 +31,11 @@ public class RayHandler implements Disposable { static boolean gammaCorrection = false; static float gammaCorrectionParameter = 1f; + + /** TODO: This could be made adaptive to ratio of camera sizes * zoom + * vs the CircleShape radius - thus will provide smooth radial shadows + * while resizing and zooming in and out */ + static int CIRCLE_APPROX_POINTS = 32; /** if this is public why we have a setter? * TODO: remove public modifier and add getter