/// <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); }
/// <summary> /// Performs a 3-dimensional rotation on the cuboid and returns a new axis-aligned cuboid resulting from this rotation. Not sure it it makes any sense to use this for other rotations than 90 degree intervals. /// </summary> public Cuboidi RotatedCopy(int degX, int degY, int degZ, Vec3d origin) { double radX = degX * GameMath.DEG2RAD; double radY = degY * GameMath.DEG2RAD; double radZ = degZ * GameMath.DEG2RAD; double[] matrix = Mat4d.Create(); Mat4d.RotateX(matrix, matrix, radX); Mat4d.RotateY(matrix, matrix, radY); Mat4d.RotateZ(matrix, matrix, radZ); double[] pos = new double[] { 0, 0, 0, 1 }; //Vec3d origin = new Vec3d(0.5, 0.5, 0.5); double[] min = new double[] { X1 - origin.X, Y1 - origin.Y, Z1 - origin.Z, 1 }; double[] max = new double[] { X2 - origin.X, Y2 - origin.Y, Z2 - origin.Z, 1 }; min = Mat4d.MulWithVec4(matrix, min); max = Mat4d.MulWithVec4(matrix, max); double tmp; if (max[0] < min[0]) { tmp = max[0]; max[0] = min[0]; min[0] = tmp; } if (max[1] < min[1]) { tmp = max[1]; max[1] = min[1]; min[1] = tmp; } if (max[2] < min[2]) { tmp = max[2]; max[2] = min[2]; min[2] = tmp; } return(new Cuboidi( (int)(Math.Round(min[0]) + origin.X), (int)(Math.Round(min[1]) + origin.Y), (int)(Math.Round(min[2]) + origin.Z), (int)(Math.Round(max[0]) + origin.X), (int)(Math.Round(max[1]) + origin.Y), (int)(Math.Round(max[2] + origin.Z)) )); }