X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fbasic%2FGlowingPoint.java;h=a7b4784029ca75e48a343d3a5ba7b8eb5a9e0e88;hp=3b7376ef5b8999682d8d254e92cbca4fbb6b86e4;hb=316a696bf9db6e8eddf90ef3df5e1119481c0192;hpb=0f7068dde61bcdbee69782182607015132dc1060 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java index 3b7376e..a7b4784 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java @@ -12,15 +12,18 @@ import java.util.Collections; import java.util.Set; import java.util.WeakHashMap; +import static java.lang.Math.pow; +import static java.lang.Math.sqrt; + public class GlowingPoint extends ForwardOrientedTexture { - private static final int TEXTURE_SIZE = 50; + private static final int TEXTURE_RESOLUTION_PIXELS = 100; private static final Set glowingPoints = Collections.newSetFromMap(new WeakHashMap<>()); private final Color color; public GlowingPoint(final Point3D point, final double pointSize, final Color color) { - super(point, pointSize, getTexture(color)); + super(point, computeScale(pointSize), getTexture(color)); this.color = color; synchronized (glowingPoints) { @@ -28,6 +31,10 @@ public class GlowingPoint extends ForwardOrientedTexture { } } + private static double computeScale(double pointSize) { + return pointSize / ((double) (TEXTURE_RESOLUTION_PIXELS / 50f)); + } + private static Texture getTexture(final Color color) { // attempt to reuse texture from existing glowing point of the same color synchronized (glowingPoints) { @@ -41,16 +48,16 @@ public class GlowingPoint extends ForwardOrientedTexture { } private static Texture createTexture(final Color color) { - final Texture texture = new Texture(TEXTURE_SIZE, TEXTURE_SIZE, 1); - for (int x = 0; x < TEXTURE_SIZE; x++) - for (int y = 0; y < TEXTURE_SIZE; y++) { + final Texture texture = new Texture(TEXTURE_RESOLUTION_PIXELS, TEXTURE_RESOLUTION_PIXELS, 1); + int halfResolution = TEXTURE_RESOLUTION_PIXELS / 2; + + for (int x = 0; x < TEXTURE_RESOLUTION_PIXELS; x++) + for (int y = 0; y < TEXTURE_RESOLUTION_PIXELS; y++) { int address = texture.primaryBitmap.getAddress(x, y); - final int distance = (int) Math - .sqrt((((TEXTURE_SIZE / 2) - x) * ((TEXTURE_SIZE / 2) - x)) - + (((TEXTURE_SIZE / 2) - y) * ((TEXTURE_SIZE / 2) - y))); + final int distanceFromCenter = (int) sqrt(pow (halfResolution - x, 2) + pow (halfResolution - y, 2)); - int alpha = 255 - ((270 * distance) / (TEXTURE_SIZE / 2)); + int alpha = 255 - ((270 * distanceFromCenter) / halfResolution); if (alpha < 0) alpha = 0;