-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt at implementing collision box rotation
- Loading branch information
Showing
2 changed files
with
56 additions
and
8 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
37 changes: 37 additions & 0 deletions
37
shared/src/main/java/org/geysermc/hydraulic/util/Vec3f.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,37 @@ | ||
package org.geysermc.hydraulic.util; | ||
|
||
public record Vec3f(float x, float y, float z) { | ||
private static final Vec3f CENTER = new Vec3f(0.5f, 0.5f, 0.5f); | ||
|
||
public Vec3f rotateX(float angle) { | ||
if (angle == 0) return this; | ||
|
||
double radians = Math.toRadians(angle); | ||
double cos = Math.cos(radians); | ||
double sin = Math.sin(radians); | ||
float newY = (float) ((y - CENTER.y) * cos - (z - CENTER.z) * sin + CENTER.y); | ||
float newZ = (float) ((y - CENTER.y) * sin + (z - CENTER.z) * cos + CENTER.z); | ||
|
||
return new Vec3f(x(), newY, newZ); | ||
} | ||
|
||
public Vec3f rotateY(float angle) { | ||
if (angle == 0) return this; | ||
|
||
double radians = Math.toRadians(angle); | ||
double cos = Math.cos(radians); | ||
double sin = Math.sin(radians); | ||
float newX = (float) ((x - CENTER.x) * cos + (z - CENTER.z) * sin + CENTER.x); | ||
float newZ = (float) (-(x - CENTER.x) * sin + (z - CENTER.z) * cos + CENTER.z); | ||
|
||
return new Vec3f(newX, y(), newZ); | ||
} | ||
|
||
public static Vec3f min(Vec3f min, Vec3f max) { | ||
return new Vec3f(Math.min(min.x(), max.x()), Math.min(min.y(), max.y()), Math.min(min.z(), max.z())); | ||
} | ||
|
||
public static Vec3f max(Vec3f min, Vec3f max) { | ||
return new Vec3f(Math.max(min.x(), max.x()), Math.max(min.y(), max.y()), Math.max(min.z(), max.z())); | ||
} | ||
} |