コード例 #1
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public static Poliedro Esfera(int Pasos)
		{
			Vertice[] Vertices = new Vertice[(Math.Pow(Pasos, 2)) - Pasos + 2];
			Cara[] Caras = new Cara[(Math.Pow(Pasos, 2))];
			int cont = 0;
			int contc = 0;
			double Radio = 1;


			for (int i = 0; i <= Pasos - 1; i++) {
				Caras[i] = new Cara(3);
			}
			for (int i = Pasos; i <= (Math.Pow(Pasos, 2)) - Pasos - 1; i++) {
				Caras[i] = new Cara(4);
			}
			for (int i = (Math.Pow(Pasos, 2)) - Pasos; i <= (Math.Pow(Pasos, 2)) - 1; i++) {
				Caras[i] = new Cara(3);
			}

			cont = 1;
			contc = 0;

			Vertices[0] = new Vertice(new Punto3D(0, 0, 1));
			Vertices[Vertices.GetUpperBound(0)] = new Vertice(new Punto3D(0, 0, -1));

			for (double a = 0; a <= Math.PI; a += Math.PI / (Pasos / 1)) {
				if (a == 0 | a == Math.PI)
					continue;
				Radio = Math.Sin(a);
				for (double b = 0; b <= 2 * Math.PI; b += Math.PI / (Pasos / 2)) {
					if (b == 2 * Math.PI)
						continue;
					Vertices[cont] = new Vertice(new Punto3D(Radio * Math.Cos(b), Radio * Math.Sin(b), Math.Cos(a)));

					if (cont == Vertices.GetUpperBound(0))
						break; // TODO: might not be correct. Was : Exit For
					cont += 1;
				}
				if (cont == (Math.Pow(Pasos, 2)) - 1)
					break; // TODO: might not be correct. Was : Exit For
			}

			cont = 1;
			for (int i = 0; i <= Pasos - 1; i++) {
				Caras[i].Vertices[0] = 0;
				Caras[i].Vertices[1] = (cont + 1 <= Pasos - 0 ? cont + 1 : 1);
				Caras[i].Vertices[2] = cont;
				if (cont == Pasos)
					break; // TODO: might not be correct. Was : Exit For
				cont += 1;
			}

			cont = Vertices.GetUpperBound(0) - Pasos - 1;
			for (int i = Caras.GetUpperBound(0) - Pasos; i <= Caras.GetUpperBound(0); i++) {
				Caras[i].Vertices[0] = cont;
				Caras[i].Vertices[1] = (cont + 1 < Vertices.GetUpperBound(0) - 1 ? cont + 1 : Vertices.GetUpperBound(0) - Pasos - 1);
				Caras[i].Vertices[2] = Vertices.GetUpperBound(0);
				if (cont == Vertices.GetUpperBound(0) - 1)
					break; // TODO: might not be correct. Was : Exit For
				cont += 1;
			}

			for (int i = 1; i <= Pasos - 2; i++) {
				for (int j = 0; j <= Pasos - 1; j++) {
					Caras[(i * Pasos) + j].Vertices[0] = ((i - 1) * Pasos) + j + 1;
					Caras[(i * Pasos) + j].Vertices[1] = (j + 1 <= Pasos - 1 ? ((i - 1) * Pasos) + j + 2 : ((i - 1) * Pasos) + 1);
					Caras[(i * Pasos) + j].Vertices[2] = (j + 1 <= Pasos - 1 ? ((i) * Pasos) + j + 2 : ((i) * Pasos) + 1);
					Caras[(i * Pasos) + j].Vertices[3] = ((i) * Pasos) + j + 1;
				}
			}

			return new Poliedro(Vertices, Caras);
		}
コード例 #2
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public Poliedro(Vertice[] Vertices, Cara[] Caras)
		{
			if (Vertices.GetUpperBound(0) >= 3) {
				if (Caras.GetUpperBound(0) >= 3) {
					mCaras = Caras;

					for (int i = 0; i <= mCaras.GetUpperBound(0); i++) {
						mCaras[i].Color = Color.White;
					}

					mVertices = Vertices;
					mAutoRecalcularCajas = false;
					AutoReclcNorms = true;
					RecalcularCentro();
					CalcularCarasVertices();
					RecalcularDatosCaras();
					RecalcularNormalesVertices();
					mConstantesShading = new PhongShader();
					mVertical = new Vector3D(0, 1, 0);
				} else {
					throw new ExcepcionPrimitiva3D("POLIEDRO (NEW): Un poliedro debe tener al menos 4 caras" + Constants.vbNewLine + "Numero de caras=" + Vertices.GetUpperBound(0) + 1);
				}
			} else {
				throw new ExcepcionPrimitiva3D("POLIEDRO (NEW): Un poliedro debe tener al menos 4 vertices" + Constants.vbNewLine + "Numero de vertices=" + Vertices.GetUpperBound(0) + 1);
			}
		}