mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Arrows now work as intended. Case added for interior angles.
#implement #story[1118]
This commit is contained in:
@@ -55,7 +55,7 @@ public class CompoundMark {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setRoundingSide(RoundingSide roundingSide) {
|
||||
public void setRoundingSide(RoundingSide roundingSide) {;
|
||||
switch (roundingSide) {
|
||||
case SP:
|
||||
getSubMark(1).setRoundingSide(RoundingSide.STARBOARD);
|
||||
|
||||
@@ -239,27 +239,10 @@ public class GameView extends Pane {
|
||||
}
|
||||
}
|
||||
}
|
||||
// System.out.println("<seq>");
|
||||
// for (Corner corner : sequence) {
|
||||
// for (CompoundMark cm : newCourse) {
|
||||
// if (cm.getId() == corner.getCompoundMarkID()) {
|
||||
// System.out.println(cm);
|
||||
// System.out.println(corner.getSeqID());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// System.out.println("</seq>");
|
||||
//
|
||||
// for (CompoundMark cm : course) {
|
||||
// System.out.println(cm);
|
||||
// }
|
||||
|
||||
// TODO: 16/08/17 Updating mark roundings here. It should not happen here. Nor should it be done this way.
|
||||
for (Corner corner : sequence){
|
||||
// System.out.println("corner.getSeqID() = " + corner.getSeqID());
|
||||
CompoundMark compoundMark = course.get(corner.getSeqID() - 1);
|
||||
// System.out.println(" = " + RoundingSide.getRoundingSide(corner.getRounding()));
|
||||
// System.out.println("compoundMark = " + compoundMark);
|
||||
compoundMark.setRoundingSide(
|
||||
RoundingSide.getRoundingSide(corner.getRounding())
|
||||
);
|
||||
@@ -315,18 +298,13 @@ public class GameView extends Pane {
|
||||
}
|
||||
GeoPoint nextMarkAv = new GeoPoint(averageLat / numMarks, averageLng / numMarks);
|
||||
// TODO: 16/08/17 This comparison is cancer and deserves to die.
|
||||
System.out.println("course.get(i).getMarks() = " + course.get(i).getMarks());
|
||||
for (Mark mark : course.get(i).getMarks()) {
|
||||
markerObjects.get(mark).addArrows(
|
||||
mark.getRoundingSide() == RoundingSide.STARBOARD ? MarkArrowFactory.RoundingSide.STARBOARD : MarkArrowFactory.RoundingSide.PORT,
|
||||
GeoUtility.getBearing(lastMarkAv, mark),
|
||||
GeoUtility.getBearing(mark, nextMarkAv)
|
||||
// GeoUtility.getBearing(mark, nextMarkAv),
|
||||
// GeoUtility.getBearing(lastMarkAv, mark)
|
||||
);
|
||||
// System.out.println(mark.getName() + " " + GeoUtility.getBearing(lastMarkAv, mark) + " " + GeoUtility.getBearing(mark, nextMarkAv));
|
||||
}
|
||||
System.out.println("end");
|
||||
}
|
||||
|
||||
// TODO: 16/08/17 Make this cleaner
|
||||
@@ -341,15 +319,10 @@ public class GameView extends Pane {
|
||||
}
|
||||
GeoPoint firstMarkAv = new GeoPoint(averageLat / numMarks, averageLng / numMarks);
|
||||
for (Mark mark : course.get(0).getMarks()) {
|
||||
System.out.println("thing " + GeoUtility.getBearing(mark, firstMarkAv));
|
||||
System.out.println(mark);
|
||||
System.out.println(mark.getRoundingSide());
|
||||
markerObjects.get(mark).addArrows(
|
||||
mark.getRoundingSide() == RoundingSide.STARBOARD ? MarkArrowFactory.RoundingSide.STARBOARD : MarkArrowFactory.RoundingSide.PORT,
|
||||
0d, //90
|
||||
GeoUtility.getBearing(mark, firstMarkAv)
|
||||
// GeoUtility.getBearing(mark, mark),
|
||||
// GeoUtility.getBearing(mark, firstMarkAv)
|
||||
);
|
||||
}
|
||||
//Last Mark case
|
||||
@@ -779,15 +752,9 @@ public class GameView extends Pane {
|
||||
playerYacht.toggleSail();
|
||||
boatObjects.get(playerYacht).setAsPlayer();
|
||||
CompoundMark currentMark = course.get(playerYacht.getLegNumber());
|
||||
System.out.println("currentMark = " + currentMark);
|
||||
for (Mark mark : currentMark.getMarks()) {
|
||||
markerObjects.get(mark).showNextExitArrow();
|
||||
}
|
||||
// CompoundMark destination = course.get(playerYacht.getLegNumber() + 1);
|
||||
// System.out.println("destination = " + destination);
|
||||
// for (Mark mark : destination.getMarks()) {
|
||||
// markerObjects.get(mark).showNextEnterArrow();
|
||||
// }
|
||||
annotations.get(playerYacht).addAnnotation(
|
||||
"velocity",
|
||||
playerYacht.getVelocityProperty(),
|
||||
@@ -804,22 +771,30 @@ public class GameView extends Pane {
|
||||
|
||||
private void updateMarkArrows (ClientYacht yacht, CompoundMark compoundMark, int legNumber) {
|
||||
//Only show arrows for this and next leg.
|
||||
if (legNumber - 2 >= 0) {
|
||||
CompoundMark lastMark = course.get(Math.max(0, legNumber - 2));
|
||||
}
|
||||
if (compoundMark != null) {
|
||||
for (Mark mark : compoundMark.getMarks()) {
|
||||
markerObjects.get(mark).showNextExitArrow();
|
||||
}
|
||||
if (legNumber < course.size()) {
|
||||
CompoundMark nextMark = course.get(legNumber);
|
||||
}
|
||||
CompoundMark nextMark = null;
|
||||
if (legNumber < course.size() - 1) {
|
||||
nextMark = course.get(legNumber);
|
||||
for (Mark mark : nextMark.getMarks()) {
|
||||
markerObjects.get(mark).showNextEnterArrow();
|
||||
}
|
||||
}
|
||||
if (legNumber - 2 >= 0) {
|
||||
CompoundMark lastMark = course.get(Math.max(0, legNumber - 2));
|
||||
if (lastMark != nextMark) {
|
||||
for (Mark mark : lastMark.getMarks()) {
|
||||
markerObjects.get(mark).hideAllArrows();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given yacht geopoint by race view controller, drawCollision will calculate canvas X and Y and
|
||||
|
||||
@@ -36,24 +36,20 @@ public class MarkArrowFactory {
|
||||
*/
|
||||
public static Group constructEntryArrow (RoundingSide roundingSide, double angleOfEntry,
|
||||
double angleOfExit, Paint colour) {
|
||||
if (roundingSide == RoundingSide.PORT && angleOfEntry < angleOfExit && Math.abs(angleOfExit - angleOfEntry) < 180) {
|
||||
return makeInteriorAngle(roundingSide, angleOfExit, angleOfEntry, colour);
|
||||
} else if (roundingSide == RoundingSide.STARBOARD && angleOfEntry > angleOfExit && -Math.abs(angleOfEntry - angleOfExit) > -180) {
|
||||
return makeInteriorAngle(roundingSide, angleOfExit, angleOfEntry, colour);
|
||||
}
|
||||
|
||||
angleOfEntry = 180 - angleOfEntry;
|
||||
Group arrow = new Group();
|
||||
Group exitSection = constructExitArrow(roundingSide, angleOfExit, colour);
|
||||
angleOfExit = 180 - angleOfExit;
|
||||
// double minAngle = Math.min(angleOfEntry, angleOfExit);
|
||||
// double arcLen = Math.max(angleOfEntry, angleOfExit) - minAngle;
|
||||
// Arc roundSection = new Arc(
|
||||
// 0, 0, MARK_ARROW_SEPARATION, MARK_ARROW_SEPARATION,
|
||||
// angleOfEntry, 180 - (angleOfEntry - angleOfExit)
|
||||
// );
|
||||
System.out.println(angleOfEntry);
|
||||
System.out.println(angleOfExit);
|
||||
System.out.println(angleOfExit - angleOfEntry);
|
||||
Arc roundSection = new Arc(
|
||||
0, 0, MARK_ARROW_SEPARATION, MARK_ARROW_SEPARATION,
|
||||
(roundingSide == RoundingSide.PORT ? -180 : 0) + angleOfEntry,
|
||||
// roundingSide == RoundingSide.PORT ? Math.abs(angleOfExit - angleOfEntry) : angleOfExit - angleOfEntry
|
||||
roundingSide == RoundingSide.PORT ? angleOfExit- angleOfEntry : angleOfEntry - angleOfExit
|
||||
roundingSide == RoundingSide.PORT ? Math.abs(angleOfExit - angleOfEntry) : -Math.abs(angleOfEntry - angleOfExit)
|
||||
);
|
||||
roundSection.setStrokeWidth(STROKE_WIDTH);
|
||||
roundSection.setType(ArcType.OPEN);
|
||||
@@ -62,11 +58,43 @@ public class MarkArrowFactory {
|
||||
Polygon entrySection = constructLineSegment(
|
||||
roundingSide == RoundingSide.PORT ? RoundingSide.STARBOARD : RoundingSide.PORT, 180 + angleOfEntry, colour
|
||||
);
|
||||
// Polygon entrySection = new Polygon();
|
||||
arrow.getChildren().addAll(exitSection, roundSection, entrySection);
|
||||
return arrow;
|
||||
}
|
||||
|
||||
private static Group makeInteriorAngle (RoundingSide roundingSide, double angleOfExit, double angleOfEntry, Paint colour) {
|
||||
Group arrow = new Group();
|
||||
Polygon lineSegment;
|
||||
angleOfEntry = Math.toRadians(360 - angleOfEntry);
|
||||
angleOfExit = Math.toRadians(180 - angleOfExit);
|
||||
int multiplier = roundingSide == RoundingSide.STARBOARD ? -1 : 1;
|
||||
double xStart = multiplier * MARK_ARROW_SEPARATION * Math.sin(angleOfEntry + Math.PI / 2);
|
||||
double yStart = multiplier * MARK_ARROW_SEPARATION * Math.cos(angleOfEntry + Math.PI / 2);
|
||||
xStart = xStart + (ARROW_LENGTH * Math.sin(angleOfEntry));
|
||||
yStart = yStart + (ARROW_LENGTH * Math.cos(angleOfEntry));
|
||||
multiplier = roundingSide == RoundingSide.STARBOARD ? 1 : -1;
|
||||
double xEnd = multiplier * MARK_ARROW_SEPARATION * Math.sin(angleOfExit + Math.PI / 2);
|
||||
double yEnd = multiplier * MARK_ARROW_SEPARATION * Math.cos(angleOfExit + Math.PI / 2);
|
||||
xEnd = xEnd + (ARROW_LENGTH * Math.sin(angleOfExit));
|
||||
yEnd = yEnd + (ARROW_LENGTH * Math.cos(angleOfExit));
|
||||
lineSegment = new Polygon(
|
||||
xStart, yStart,
|
||||
xEnd, yEnd
|
||||
);
|
||||
lineSegment.setStroke(colour);
|
||||
lineSegment.setFill(Color.BLUE);
|
||||
lineSegment.setStrokeWidth(STROKE_WIDTH);
|
||||
lineSegment.setStrokeLineCap(StrokeLineCap.ROUND);
|
||||
Polyline arrowHead = constructArrowHead(
|
||||
90 + Math.toDegrees(Math.atan2(yStart - yEnd, xEnd - xStart)),
|
||||
colour
|
||||
);
|
||||
arrowHead.setLayoutX(xEnd);
|
||||
arrowHead.setLayoutY(yEnd);
|
||||
arrow.getChildren().addAll(lineSegment, arrowHead);
|
||||
return arrow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an exit arrow group pointing towards the next mark.
|
||||
* @param roundingSide The side of the boat that will be closest to the mark.
|
||||
@@ -89,9 +117,6 @@ public class MarkArrowFactory {
|
||||
Polygon lineSegment;
|
||||
angle = Math.toRadians(angle);
|
||||
int multiplier = roundingSide == RoundingSide.STARBOARD ? 1 : -1;
|
||||
// System.out.println("rounding side " + roundingSide);
|
||||
// System.out.println("multiplier = " + multiplier);
|
||||
// int multiplier = 1;
|
||||
double xStart = multiplier * MARK_ARROW_SEPARATION * Math.sin(angle + Math.PI / 2);
|
||||
double yStart = multiplier * MARK_ARROW_SEPARATION * Math.cos(angle + Math.PI / 2);
|
||||
double xEnd = xStart + (ARROW_LENGTH * Math.sin(angle));
|
||||
|
||||
@@ -56,6 +56,10 @@ public class Marker extends Group {
|
||||
exitArrows.add(
|
||||
MarkArrowFactory.constructExitArrow(roundingSide, exitAngle, colour)
|
||||
);
|
||||
// Platform.runLater(() -> {
|
||||
// this.getChildren().add(enterArrows.get(enterArrows.size()-1));
|
||||
// this.getChildren().add(exitArrows.get(exitArrows.size()-1));
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,6 +80,8 @@ public class Marker extends Group {
|
||||
|
||||
private void showArrow(List<Group> arrowList, int arrowListIndex) {
|
||||
if (arrowListIndex < arrowList.size()) {
|
||||
if (arrowListIndex == 1) {;
|
||||
}
|
||||
Platform.runLater(() -> {
|
||||
this.getChildren().remove(1);
|
||||
this.getChildren().add(arrowList.get(arrowListIndex));
|
||||
@@ -87,6 +93,6 @@ public class Marker extends Group {
|
||||
* Hides all arrows.
|
||||
*/
|
||||
public void hideAllArrows() {
|
||||
Platform.runLater(() -> this.getChildren().setAll(mark));
|
||||
Platform.runLater(() -> this.getChildren().setAll(mark, new Group()));
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@
|
||||
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.671629" TargetLng="11.840951" SourceID="125" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="4" Name="Mark3">
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.665316" TargetLng="11.827184" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.664190" TargetLng="11.829576" SourceID="127" />
|
||||
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.664190" TargetLng="11.829576" SourceID="126" />
|
||||
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.665316" TargetLng="11.827184" SourceID="127" />
|
||||
</CompoundMark>
|
||||
<CompoundMark CompoundMarkID="5" Name="Mark4">
|
||||
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.672350" TargetLng="11.842535" SourceID="128" />
|
||||
|
||||
Reference in New Issue
Block a user