24 lines
638 B
Java
24 lines
638 B
Java
package chess.view.DDDrender;
|
|
|
|
import org.joml.Vector2f;
|
|
|
|
import chess.model.Coordinate;
|
|
|
|
/**
|
|
* Helper functions to convert from 2D to 3D coordinates systems.
|
|
*/
|
|
public class DDDPlacement {
|
|
public static Vector2f coordinatesToVector(Coordinate coo) {
|
|
return coordinatesToVector(coo.getX(), coo.getY());
|
|
}
|
|
|
|
public static Vector2f coordinatesToVector(float x, float y) {
|
|
return new Vector2f(1.0f - 0.125f - x * 0.250f, 1.0f - 0.125f - y * 0.250f);
|
|
}
|
|
|
|
public static Coordinate vectorToCoordinates(Vector2f pos) {
|
|
int x = (int) ((1.0f - pos.x) * 4.0f);
|
|
int y = (int) ((1.0f - pos.y) * 4.0f);
|
|
return new Coordinate(x, y);
|
|
}
|
|
} |