/// <summary> /// Correctly adjust the position in accordance with the fruit element's rotation and rotationOrigin (compare ShapeTesselator.TesselateShapeElements()) /// </summary> private double[] Rotate(double[] pos, ShapeElement element, double[] matrix, double[] triple) { Mat4d.Identity(matrix); Mat4d.Translate(matrix, matrix, (element.RotationOrigin[0]) / 16, (element.RotationOrigin[1]) / 16, (element.RotationOrigin[2]) / 16); if (element.RotationX != 0) { triple[0] = 1; triple[1] = 0; triple[2] = 0; Mat4d.Rotate(matrix, matrix, element.RotationX * GameMath.DEG2RAD, triple); } if (element.RotationY != 0) { triple[0] = 0; triple[1] = 1; triple[2] = 0; Mat4d.Rotate(matrix, matrix, element.RotationY * GameMath.DEG2RAD, triple); } if (element.RotationZ != 0) { triple[0] = 0; triple[1] = 0; triple[2] = 1; Mat4d.Rotate(matrix, matrix, element.RotationZ * GameMath.DEG2RAD, triple); } Mat4d.Translate(matrix, matrix, (element.From[0] - element.RotationOrigin[0]) / 16, (element.From[1] - element.RotationOrigin[1]) / 16, (element.From[2] - element.RotationOrigin[2]) / 16); return Mat4d.MulWithVec4(matrix, pos); }
public static Vec3d Project(Vec3d pos, double[] projection, double[] view, int viewportWidth, int viewportHeight) { double[] outmat = new double[16]; Mat4d.Mul(outmat, projection, view); double[] outpos = Mat4d.MulWithVec4(outmat, new double[] { pos.X, pos.Y, pos.Z, 1 }); return(new Vec3d( (outpos[0] / outpos[3] + 1) * (viewportWidth / 2), (outpos[1] / outpos[3] + 1) * (viewportHeight / 2), outpos[2] )); }