-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add trackedlocations * reimplement TrackedLocation to specification * use built-in methods for vector manipulation * Fix merge * Fix build * Process tracked locations on all parent crafts * Update RotationTask.java --------- Co-authored-by: TylerS1066 <TylerS1066@users.noreply.github.com>
- Loading branch information
1 parent
82d9749
commit 6085cc5
Showing
5 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
47 changes: 47 additions & 0 deletions
47
api/src/main/java/net/countercraft/movecraft/TrackedLocation.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.countercraft.movecraft; | ||
|
||
import net.countercraft.movecraft.craft.Craft; | ||
import net.countercraft.movecraft.util.MathUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class TrackedLocation { | ||
private MovecraftLocation offSet; | ||
private final Craft craft; | ||
|
||
/** | ||
* Creates a new TrackedLocation instance which tracks a location about a craft's midpoint. | ||
* @param craft The craft that's that tied to the location. | ||
* @param location The absolute position to track. This location will be stored as a relative | ||
* location to the craft's central hitbox. | ||
*/ | ||
public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location) { | ||
this.craft = craft; | ||
MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); | ||
offSet = location.subtract(midPoint); | ||
} | ||
|
||
/** | ||
* Rotates the stored location. | ||
* @param rotation A clockwise or counter-clockwise direction to rotate. | ||
*/ | ||
public void rotate(MovecraftRotation rotation, MovecraftLocation origin) { | ||
offSet = MathUtils.rotateVec(rotation, getAbsoluteLocation().subtract(origin)); | ||
} | ||
|
||
/** | ||
* Gets the stored absolute location. | ||
* @return Returns the absolute location instead of a vector. | ||
*/ | ||
public MovecraftLocation getAbsoluteLocation() { | ||
MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); | ||
return offSet.add(midPoint); | ||
} | ||
|
||
/** | ||
* Gets the stored location as a position vector relative to the midpoint. | ||
* @return Returns the absolute location instead of a vector. | ||
*/ | ||
public MovecraftLocation getOffSet() { | ||
return offSet; | ||
} | ||
} |
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