public static BlockFacing FromVector(double x, double y, double z) { float smallestAngle = GameMath.PI; BlockFacing facing = null; double len = GameMath.Sqrt(x * x + y * y + z * z); x /= len; y /= len; z /= len; for (int i = 0; i < ALLFACES.Length; i++) { BlockFacing f = ALLFACES[i]; float angle = (float)Math.Acos(f.Normalf.X * x + f.Normalf.Y * y + f.Normalf.Z * z); if (angle < smallestAngle) { smallestAngle = angle; facing = f; } } return(facing); }
/// <summary> /// Rotates the face by given angle and returns the interpolated brightness of this face. /// </summary> /// <param name="matrix"></param> /// <param name="BlockSideBrightnessByFacing">Array of brightness values between 0 and 1 per face. In index order (N, E, S, W, U, D)</param> /// <returns></returns> public float GetFaceBrightness(double[] matrix, float[] BlockSideBrightnessByFacing) { double[] pos = new double[] { Normalf.X, Normalf.Y, Normalf.Z, 1 }; matrix[12] = 0; matrix[13] = 0; matrix[14] = 0; pos = Mat4d.MulWithVec4(matrix, pos); float len = GameMath.Sqrt(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]); pos[0] /= len; pos[1] /= len; pos[2] /= len; float brightness = 0; for (int i = 0; i < ALLFACES.Length; i++) { BlockFacing f = ALLFACES[i]; float angle = (float)Math.Acos(f.Normalf.Dot(pos)); if (angle >= GameMath.PIHALF) { continue; } brightness += (1 - angle / GameMath.PIHALF) * BlockSideBrightnessByFacing[f.Index]; } return(brightness); }
public float DistanceTo(float x, float y) { float dx = X - x; float dy = Y - y; return(GameMath.Sqrt(dx * dx + dy * dy)); }
public static float Distance(float x1, float y1, float x2, float y2) { float dx = x2 - x1; float dy = y2 - y1; return(GameMath.Sqrt(dx * dx + dy * dy)); }
/// <summary> /// Returns the Euclidean distance to between this and given position /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public float DistanceTo(double x, double y, double z) { double dx = x - X; double dy = y - Y; double dz = z - Z; return(GameMath.Sqrt(dx * dx + dy * dy + dz * dz)); }
/// <summary> /// Returns the Euclidean distance to between this and given position /// </summary> /// <param name="pos"></param> /// <returns></returns> public float DistanceTo(BlockPos pos) { double dx = pos.X - X; double dy = pos.Y - Y; double dz = pos.Z - Z; return(GameMath.Sqrt(dx * dx + dy * dy + dz * dz)); }
public double Length() { return(GameMath.Sqrt(X * X + Y * Y + Z * Z)); }