1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
| public Plane(Point3D p0, Point3D p1, Point3D p2) { Vector3D e1 = p1 - p0; Vector3D e2 = p2 - p1; this.normal = Vector3D.CrossProduct(e1, e2); Vector3D n = normal/normal.Length; this.d = Vector3D.DotProduct(e1, n);
}
public Point[] MapTextureCoordinates(Point3D[] vertices, Vector3D max, Vector3D min) { Vector3D size = max - min; Plane plane = new Plane(vertices[0], vertices[2], vertices[1]);
double cross_X = Vector3D.DotProduct(plane.Normal, new Vector3D(1, 0, 0)); double cross_Y = Vector3D.DotProduct(plane.Normal, new Vector3D(0, 1, 0)); double cross_Z = Vector3D.DotProduct(plane.Normal, new Vector3D(0, 0, 1));
Point[] tmp = new Point[3]; if ((Math.Abs(cross_X) > Math.Abs(cross_Y)) && (Math.Abs(cross_X) > Math.Abs(cross_Z))) { for (int i = 0; i < 3; i++) { tmp[i].X = ((vertices[i].Z - max.Z) / size.Z); tmp[i].Y = ((vertices[i].Y - min.Y) / size.Y); } } if ((Math.Abs(cross_Y) > Math.Abs(cross_X)) && (Math.Abs(cross_Y) > Math.Abs(cross_Z))) { for (int i = 0; i < 3; i++) { tmp[i].X = ((vertices[i].X - max.X) / size.X); tmp[i].Y = ((vertices[i].Z - min.Z) / size.Z); } } if ((Math.Abs(cross_Z) > Math.Abs(cross_X)) && (Math.Abs(cross_Z) > Math.Abs(cross_Y))) { for (int i = 0; i < 3; i++) { tmp[i].X = ((vertices[i].X - max.X) / size.X); tmp[i].Y = ((vertices[i].Y - min.Y) / size.Y); } } return tmp; } |