11package swervelib .simulation .ironmaple .simulation ;
22
3+ import static edu .wpi .first .units .Units .Degrees ;
4+
35import edu .wpi .first .math .geometry .Pose3d ;
46import edu .wpi .first .math .geometry .Rotation3d ;
57import edu .wpi .first .math .geometry .Translation3d ;
68import edu .wpi .first .units .Units ;
79import edu .wpi .first .units .measure .Angle ;
810import edu .wpi .first .units .measure .Distance ;
9- import org .dyn4j .geometry .Rectangle ;
10- import org .dyn4j .geometry .Vector2 ;
1111import swervelib .simulation .ironmaple .simulation .gamepieces .GamePiece ;
1212
1313import java .util .List ;
14-
15- import static edu . wpi . first . units . Units . Degrees ;
14+ import org . dyn4j . geometry . Rectangle ;
15+ import org . dyn4j . geometry . Vector2 ;
1616
1717/**
1818 *
@@ -35,6 +35,11 @@ public abstract class Goal implements SimulatedArena.Simulatable {
3535 protected Rotation3d pieceAngle = null ;
3636 protected Angle pieceAngleTolerance = Angle .ofBaseUnits (15 , Degrees );
3737
38+ protected final double minZ ;
39+ protected final double maxZ ;
40+
41+ protected final boolean allowGrounded ;
42+
3843 /**
3944 *
4045 *
@@ -52,14 +57,15 @@ public static Rotation3d flipRotation(Rotation3d toFlip) {
5257 *
5358 * <h2>Creates a goal object </h2>
5459 *
55- * @param arena The host arena of this goal
56- * @param xDimension The x dimension of the default box collider.
57- * @param yDimension The y dimension of the default box collider.
58- * @param height The height or z dimension of the default box collider.
60+ * @param arena The host arena of this goal
61+ * @param xDimension The x dimension of the default box collider.
62+ * @param yDimension The y dimension of the default box collider.
63+ * @param height The height or z dimension of the default box collider.
5964 * @param gamePieceType the string game piece type to be handled by this goal.
60- * @param position The position of this goal.
61- * @param isBlue Wether this is a blue goal or a red one.
62- * @param max How many pieces can be scored in this goal.
65+ * @param position The position of this goal.
66+ * @param isBlue Wether this is a blue goal or a red one.
67+ * @param max How many pieces can be scored in this goal.
68+ * @param allowsGrounded Wether or not grounded pieces can be scored in this goal
6369 */
6470 public Goal (
6571 SimulatedArena arena ,
@@ -69,7 +75,8 @@ public Goal(
6975 String gamePieceType ,
7076 Translation3d position ,
7177 boolean isBlue ,
72- int max ) {
78+ int max ,
79+ boolean allowGrounded ) {
7380
7481 xyBox = new Rectangle (xDimension .in (Units .Meters ), yDimension .in (Units .Meters ));
7582 this .height = height ;
@@ -80,6 +87,11 @@ public Goal(
8087 this .elevation = position .getMeasureZ ();
8188 this .isBlue = isBlue ;
8289
90+ this .allowGrounded = allowGrounded ;
91+
92+ minZ = elevation .in (Units .Meters );
93+ maxZ = minZ + height .in (Units .Meters );
94+
8395 xyBox .translate (new Vector2 (position .getX (), position .getY ()));
8496 }
8597
@@ -88,13 +100,14 @@ public Goal(
88100 *
89101 * <h2>Creates a goal object with no scoring max.</h2>
90102 *
91- * @param arena The host arena of this goal.
92- * @param xDimension The x dimension of the default box collider.
93- * @param yDimension The y dimension of the default box collider.
94- * @param height The height or z dimension of the default box collider.
103+ * @param arena The host arena of this goal.
104+ * @param xDimension The x dimension of the default box collider.
105+ * @param yDimension The y dimension of the default box collider.
106+ * @param height The height or z dimension of the default box collider.
95107 * @param gamePieceType the string game piece type to be handled by this goal.
96- * @param position The position of this goal.
97- * @param isBlue Wether this is a blue goal or a red one.
108+ * @param position The position of this goal.
109+ * @param isBlue Wether this is a blue goal or a red one.
110+ * @param allowsGrounded Wether or not grounded pieces can be scored in this goal
98111 */
99112 public Goal (
100113 SimulatedArena arena ,
@@ -103,8 +116,9 @@ public Goal(
103116 Distance height ,
104117 String gamePieceType ,
105118 Translation3d position ,
106- boolean isBlue ) {
107- this (arena , xDimension , yDimension , height , gamePieceType , position , isBlue , 99999 );
119+ boolean isBlue ,
120+ boolean allowsGrounded ) {
121+ this (arena , xDimension , yDimension , height , gamePieceType , position , isBlue , 99999 , allowsGrounded );
108122 }
109123
110124 /**
@@ -118,7 +132,7 @@ public void simulationSubTick(int subTickNum) {
118132 /// Use list filtering for more efficient bulk checking.
119133 // Get all pieces of our type as a list.
120134 arena .getGamePiecesByType (gamePieceType ).stream ()
121- .filter (gamePiece -> ! checkGrounded (gamePiece ))
135+ .filter (gamePiece -> checkGrounded (gamePiece ))
122136 .filter (this ::checkValidity )
123137 .limit (max - gamePieceCount ) // Only score what we can
124138 .forEach (
@@ -134,7 +148,7 @@ public void simulationSubTick(int subTickNum) {
134148 *
135149 * <h2>Sets the angle to be used when checking game piece rotation.
136150 *
137- * @param angle The angle that pieces should have when interacting with this goal
151+ * @param angle The angle that pieces should have when interacting with this goal
138152 * @param angleTolerance The tolerance to be used in checking said angle.
139153 */
140154 public void setNeededAngle (Rotation3d angle , Angle angleTolerance ) {
@@ -176,20 +190,20 @@ protected boolean checkValidity(GamePiece gamePiece) {
176190 /**
177191 *
178192 *
179- * <h2>Checks whether the submitted game piece is grounded </h2>
193+ * <h2>Checks whether the submitted game piece is grounded and if this is acceptable </h2>
180194 *
181195 * @param gamePiece The game piece to have its groundedness checked.
182- * @return Whether the piece is grounded .
196+ * @return Whether the piece is acceptable for this goal .
183197 */
184198 protected boolean checkGrounded (GamePiece gamePiece ) {
185- return gamePiece .isGrounded ();
199+ return allowGrounded || ! gamePiece .isGrounded ();
186200 }
187201
188202 /**
189203 *
190204 *
191205 * <h2>Checks wether or not the submitted game piece has a rotation able to be scored in this goal </h2>
192- * <p>
206+ *
193207 * By default the rotation needed and tolerance may be set using the {@link Goal#setNeededAngle(Rotation3d, Angle)}
194208 * function. However rotation checks may be handled differently by some children making this not apply. Additionally
195209 * be aware that this function only supports pitch and yaw, not role. If support for roll is needed a custom
@@ -208,13 +222,13 @@ protected boolean checkRotation(GamePiece gamePiece) {
208222 flipRotation (gamePiece .getPose3d ().getRotation ()).minus (pieceAngle );
209223
210224 return new Rotation3d (Degrees .of (0 ), normalDiff .getMeasureZ (), normalDiff .getMeasureZ ())
211- .getMeasureAngle ()
212- .in (Degrees )
213- < pieceAngleTolerance .in (Degrees )
225+ .getMeasureAngle ()
226+ .in (Degrees )
227+ < pieceAngleTolerance .in (Degrees )
214228 || new Rotation3d (Degrees .of (0 ), flippedDiff .getMeasureZ (), flippedDiff .getMeasureZ ())
215- .getMeasureAngle ()
216- .in (Degrees )
217- < pieceAngleTolerance .in (Degrees );
229+ .getMeasureAngle ()
230+ .in (Degrees )
231+ < pieceAngleTolerance .in (Degrees );
218232 }
219233
220234 /**
@@ -228,8 +242,6 @@ protected boolean checkRotation(GamePiece gamePiece) {
228242 protected boolean checkCollision (GamePiece gamePiece ) {
229243 // Call our values just once.
230244 var pose = gamePiece .getPose3d ();
231- double minZ = elevation .in (Units .Meters );
232- double maxZ = minZ + height .in (Units .Meters );
233245
234246 return xyBox .contains (new Vector2 (pose .getX (), pose .getY ())) && pose .getZ () >= minZ && pose .getZ () <= maxZ ;
235247 }
@@ -238,7 +250,7 @@ protected boolean checkCollision(GamePiece gamePiece) {
238250 *
239251 *
240252 * <h2>Function to check wether the velocity of potential game pieces is acceptable.</h2>
241- * <p>
253+ *
242254 * The default implementation of this function always returns true so any velocity checks will need to be
243255 * implemented by children classes.
244256 *
@@ -273,7 +285,7 @@ public boolean isFull() {
273285 *
274286 *
275287 * <h2>Adds points when a piece has been successfully scored in this goal</h2>
276- * <p>
288+ *
277289 * Since this function is the only trigger called when a piece is scored it may handle other small things outside of
278290 * adding points.
279291 */
@@ -285,7 +297,7 @@ public boolean isFull() {
285297 * <h2>Displays game pieces to advantage scope if applicable.</h2>
286298 *
287299 * @param drawList a list of {@link Pose3d} objects used to visualize the positions of the game pieces on
288- * AdvantageScope
300+ * AdvantageScope
289301 */
290302 public abstract void draw (List <Pose3d > drawList );
291303
0 commit comments