123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package me.hammerle.supersnuvi.util;
- import me.hammerle.supersnuvi.tiles.Tile;
- public class Utils
- {
- public static float interpolate(float from, float to, float factor)
- {
- return from + (to - from) * factor;
- }
-
- public static int toBlock(float c)
- {
- return (int) (c / Tile.SIZE);
- }
- public static float toCoord(int b)
- {
- return b * Tile.SIZE;
- }
-
- public static float getSquaredDistance(float x1, float y1, float x2, float y2)
- {
- return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
- }
-
- public static Face getCollidingFace(
- float xMin1, float yMin1, float xMax1, float yMax1,
- float xMin2, float yMin2, float xMax2, float yMax2)
- {
- float diffUp = yMax1 - yMin2;
- float diffRight = xMax2 - xMin1;
- float diffDown = yMax2 - yMin1;
- float diffLeft = xMax1 - xMin2;
-
- float min = diffUp;
-
- Face f = Face.UP;
- if(min > diffRight)
- {
- min = diffRight;
- f = Face.RIGHT;
- }
- if(min > diffDown)
- {
- min = diffDown;
- f = Face.DOWN;
- }
- if(min > diffLeft)
- {
- f = Face.LEFT;
- }
-
- int c = 0;
- c += (min == diffUp) ? 1 : 0;
- c += (min == diffRight) ? 1 : 0;
- c += (min == diffDown) ? 1 : 0;
- c += (min == diffLeft) ? 1 : 0;
- if(c >= 2)
- {
- return Face.NULL;
- }
-
- return f;
- }
- }
|