Created
June 23, 2014 16:32
-
-
Save timyates/0b5caf0d9556181fe5e9 to your computer and use it in GitHub Desktop.
Java 7-ification of renderRay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Polygon renderRay( Point mp, Set<Point> points, Set<Segment> segmentSet ) { | |
Polygon lightPoly = new Polygon(); | |
List<Point> beams = new ArrayList<>(); | |
List<Double> raypoints = new ArrayList<>(); | |
for( Point p : points ) { | |
double atan = Math.atan2(p.getY() - mp.getY(), p.getX() - mp.getX()); | |
raypoints.add(atan - 0.001); | |
raypoints.add(atan); | |
raypoints.add(atan + 0.001); | |
} | |
Collections.sort(raypoints); | |
for(double a : raypoints) { | |
Segment s = new Segment(mp, new Point(mp.getX() + Math.cos(a), mp.getY() + Math.sin(a))); | |
Intersection i = Intersection.NONE ; | |
for(Segment ss : segmentSet) { | |
Intersection j = Intersection.intersect(s, ss); | |
if(j.getDistance() < i.getDistance()) { | |
i = j; | |
} | |
} | |
if(i != Intersection.NONE) { | |
beams.add(i.getPoint()); | |
} | |
} | |
for(Point beam : beams) { | |
lightPoly.getPoints().add(beam.getX()); | |
lightPoly.getPoints().add(beam.getY()); | |
} | |
lightPoly.setFill( new RadialGradient( 0, .5, mp.getX(), mp.getY(), | |
400, false, CycleMethod.NO_CYCLE, new Stop( 0, Color.valueOf( "#FFFFFF55" ) ), | |
new Stop( 1, Color.valueOf( "#33333300" ) ) ) ); | |
lightPoly.setBlendMode( BlendMode.SOFT_LIGHT ); | |
return lightPoly ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment