Class Goal
- All Implemented Interfaces:
SimulatedArena.Simulatable
- Direct Known Subclasses:
CrescendoAmp,CrescendoSpeaker,RebuiltHub,RebuiltOutpost,ReefscapeBargeSimulation,ReefscapeProcessorSimulation,ReefscapeReefBranch
An Abstract Class to Handle Scoring Elements in Simulation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional Interface for Position-Based Bound Checkingstatic interfaceFunctional Interface for Rotation-Based Validation -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanprotected final SimulatedArenaprotected final Distanceprotected intprotected final Stringprotected final Distancefinal booleanprotected final intprotected final Translation3dprotected Goal.PositionCheckerprotected Goal.RotationCheckerprotected org.dyn4j.geometry.Rectangle -
Constructor Summary
ConstructorsConstructorDescriptionGoal(SimulatedArena arena, Distance xDimension, Distance yDimension, Distance height, String gamePieceType, Translation3d position, boolean isBlue, boolean allowsGrounded) Creates a Goal Object with No Scoring MaximumGoal(SimulatedArena arena, Distance xDimension, Distance yDimension, Distance height, String gamePieceType, Translation3d position, boolean isBlue, int max, boolean allowGrounded) Creates a Goal Object -
Method Summary
Modifier and TypeMethodDescriptionstatic Goal.RotationCheckerabsoluteAngle(Rotation3d expectedAngle, Angle tolerance) Creates an Absolute Angle Rotation Checkerprotected abstract voidAdds Points When a Piece Has Been Successfully Scored in This Goalstatic Goal.RotationCheckerCreates an Always-Valid Rotation Checkerstatic Goal.PositionCheckerbox(org.dyn4j.geometry.Rectangle xyBox, double minZMeters, double maxZMeters) Creates a Box-Shaped Position Checkerprotected booleancheckCollision(GamePiece gamePiece) Sets a Custom Position Checker for This Goalprotected booleancheckGrounded(GamePiece gamePiece) Checks whether the submitted game piece is grounded and if this is acceptableprotected booleancheckValidity(GamePiece gamePiece) Sets a Custom Rotation Validator for This Goalvoidclear()Removes All Game Pieces from This Goalabstract voidDisplays Game Pieces to AdvantageScope if Applicablestatic Rotation3dflipRotation(Rotation3d toFlip) Reverses a Rotation 180 Degrees Around the Z-AxisintReturns the Number of Game Pieces Currently Scored in This GoalbooleanisFull()Returns Whether This Goal is Fullstatic Goal.RotationCheckerCreates a Pitch-Only Rotation CheckervoidsetNeededAngle(Rotation3d angle) Sets the Angle to be Used When Checking Game Piece RotationvoidsetNeededAngle(Rotation3d angle, Angle angleTolerance) Sets the Angle to be Used When Checking Game Piece RotationvoidsimulationSubTick(int subTickNum) Handles the update triggers for the goal object.withCustomCollisionPredicate(Predicate<Translation3d> predicate) Sets a Custom Collision Detection PredicateSets a Custom Rotation Checker for This GoalwithCustomRotationValidator(Predicate<GamePiece> validator) withCustomVelocityValidator(Predicate<GamePiece> validator) Configures custom velocity requirements for scoring.withRotationTolerance(Angle tolerance) Deprecated.
-
Field Details
-
xyBox
protected org.dyn4j.geometry.Rectangle xyBox -
height
-
elevation
-
gamePieceType
-
position
-
arena
-
max
protected final int max -
isBlue
public final boolean isBlue -
gamePieceCount
protected int gamePieceCount -
allowGrounded
protected final boolean allowGrounded -
rotationChecker
-
positionChecker
-
velocityValidator
-
-
Constructor Details
-
Goal
public Goal(SimulatedArena arena, Distance xDimension, Distance yDimension, Distance height, String gamePieceType, Translation3d position, boolean isBlue, int max, boolean allowGrounded) Creates a Goal Object
- Parameters:
arena- The host arena of this goalxDimension- The x dimension of the default box collider.yDimension- The y dimension of the default box collider.height- The height or z dimension of the default box collider.gamePieceType- the string game piece type to be handled by this goal.position- The position of this goal.isBlue- Whether this is a blue goal or a red one.max- How many pieces can be scored in this goal.allowsGrounded- Wether or not grounded pieces can be scored in this goal
-
Goal
public Goal(SimulatedArena arena, Distance xDimension, Distance yDimension, Distance height, String gamePieceType, Translation3d position, boolean isBlue, boolean allowsGrounded) Creates a Goal Object with No Scoring Maximum
- Parameters:
arena- The host arena of this goal.xDimension- The x dimension of the default box collider.yDimension- The y dimension of the default box collider.height- The height or z dimension of the default box collider.gamePieceType- the string game piece type to be handled by this goal.position- The position of this goal.isBlue- Wether this is a blue goal or a red one.allowsGrounded- Wether or not grounded pieces can be scored in this goal
-
-
Method Details
-
flipRotation
Reverses a Rotation 180 Degrees Around the Z-Axis
Used internally for checking game pieces that can score in either orientation.
- Parameters:
toFlip- the rotation to flip- Returns:
- the flipped rotation
-
box
public static Goal.PositionChecker box(org.dyn4j.geometry.Rectangle xyBox, double minZMeters, double maxZMeters) Creates a Box-Shaped Position Checker
Validates that a position is within an axis-aligned 3D box.
- Parameters:
xyBox- the 2D box in XY planeminZMeters- minimum Z coordinate in metersmaxZMeters- maximum Z coordinate in meters- Returns:
- position checker for box-shaped bounds
-
absoluteAngle
Creates an Absolute Angle Rotation Checker
Validates that a game piece's rotation matches an expected angle within tolerance, checking both pitch and yaw. Considers both normal and flipped (180-degree rotated) orientations.
- Parameters:
expectedAngle- the expected 3D rotationtolerance- the allowed angular difference- Returns:
- rotation checker for absolute angle matching
-
pitchOnly
Creates a Pitch-Only Rotation Checker
Validates only the pitch (Y-axis rotation) of a game piece, ignoring yaw and roll. Useful for ring-shaped game pieces where orientation around the vertical axis doesn't matter.
- Parameters:
expectedPitchRadians- the expected pitch in radianstolerance- the allowed angular difference- Returns:
- rotation checker for pitch-only validation
-
anyRotation
Creates an Always-Valid Rotation Checker
- Returns:
- rotation checker that always returns true
-
simulationSubTick
public void simulationSubTick(int subTickNum) Handles the update triggers for the goal object.
- Specified by:
simulationSubTickin interfaceSimulatedArena.Simulatable- Parameters:
subTickNum- the number of this sub-tick (counting from 0 in each robot period)
-
setNeededAngle
Sets the Angle to be Used When Checking Game Piece Rotation
- Parameters:
angle- The angle that pieces should have when interacting with this goalangleTolerance- The tolerance to be used in checking said angle.
-
setNeededAngle
Sets the Angle to be Used When Checking Game Piece Rotation
- Parameters:
angle- The angle that pieces should have when interacting with this goal
-
withCustomRotationChecker
Sets a Custom Rotation Checker for This Goal
Replaces the default rotation validation logic with a custom checker. This allows for complex rotation checks beyond simple pitch/yaw tolerance, such as validating only specific axes or implementing custom logic.
- Parameters:
checker- rotation checker that validates game piece rotation- Returns:
- this Goal instance for method chaining
-
checkValidity
Sets a Custom Rotation Validator for This Goal
Convenience method that accepts a Predicate for backward compatibility.
- Parameters:
validator- predicate that accepts GamePiece and returns true if rotation is valid- Returns:
- this Goal instance for method chaining
-
checkGrounded
Checks whether the submitted game piece is grounded and if this is acceptable
- Parameters:
gamePiece- The game piece to have its groundedness checked.- Returns:
- Whether the piece is acceptable for this goal.
-
withCustomRotationValidator
-
withRotationTolerance
Deprecated.UsesetNeededAngle(Rotation3d, Angle)instead to set both angle and toleranceSets Rotation Tolerance for Pitch and Yaw
Configures the tolerance used by the default rotation validation logic. This only works if you have previously set an expected angle using
setNeededAngle(Rotation3d, Angle).Note: This method cannot update the tolerance without knowing the expected angle. If you need to change the tolerance, use
setNeededAngle(Rotation3d, Angle)again with the new tolerance.- Parameters:
tolerance- maximum allowed difference in degrees- Returns:
- this Goal instance for method chaining
-
checkCollision
Sets a Custom Position Checker for This Goal
Replaces the default box collision with a custom shape check. This allows for cylindrical, spherical, or other complex collision zones beyond axis-aligned boxes.
- Parameters:
checker- position checker that validates 3D positions- Returns:
- this Goal instance for method chaining
-
withCustomPositionChecker
-
withCustomCollisionPredicate
Sets a Custom Collision Detection Predicate
Convenience method that accepts a Predicate for backward compatibility.
- Parameters:
predicate- function that accepts Translation3d and returns true if inside goal zone- Returns:
- this Goal instance for method chaining
-
withCustomVelocityValidator
Configures custom velocity requirements for scoring. This can be used to require pieces to be ascending, descending, or moving within certain speed ranges.The predicate receives the
GamePieceand should returntrueif the velocity is acceptable for scoring.- Parameters:
validator- predicate that accepts GamePiece and returns true if velocity is valid- Returns:
- this Goal instance for method chaining
-
clear
public void clear()Removes All Game Pieces from This Goal
-
isFull
public boolean isFull()Returns Whether This Goal is Full
- Returns:
- Whether or not the goal is full.
-
addPoints
protected abstract void addPoints()Adds Points When a Piece Has Been Successfully Scored in This Goal
Since this function is the only trigger called when a piece is scored it may handle other small things outside of adding points.
-
draw
Displays Game Pieces to AdvantageScope if Applicable
- Parameters:
drawList- a list ofPose3dobjects used to visualize the positions of the game pieces on AdvantageScope
-
getGamePieceCount
public int getGamePieceCount()Returns the Number of Game Pieces Currently Scored in This Goal
- Returns:
- This goals game piece count.
-
setNeededAngle(Rotation3d, Angle)instead to set both angle and tolerance