示例#1
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);
			}
		}
示例#2
0
		public void Shading(PhongShader Constantes, Foco3D[] Focos, Camara3D Camara)
		{
			mColorShading = Constantes.EcuacionPhong(Focos, mNormalSUR, mBaricentroSUR, mColor, Camara);
		}
示例#3
0
		public void EstablecerConstantesShading(ref PhongShader Constantes)
		{
			mConstantesShading = Constantes;
		}
示例#4
0
		public static Color EcuacionPhong(Foco3D[] Focos, PhongShader Constantes, Vector3D NormalSUR, Punto3D PuntoSUR, Color Color, Camara3D Camara)
		{
			Vector3D Rayo = null;
			Vector3D Salida = null;
			Vector3D Vista = null;
			byte r = 0;
			byte g = 0;
			byte b = 0;
			long rr = 0;
			long gg = 0;
			long bb = 0;
			long trr = 0;
			long tgg = 0;
			long tbb = 0;
			double Escalar = 0;
			double Ambiente = 0;
			double Difusa = 0;
			double Especular = 0;

			double AmbienteR = 0;
			double DifusaR = 0;
			double EspecularR = 0;
			double AmbienteG = 0;
			double DifusaG = 0;
			double EspecularG = 0;
			double AmbienteB = 0;
			double DifusaB = 0;
			double EspecularB = 0;

			trr = 0;
			tgg = 0;
			tbb = 0;

			Vista = new Vector3D(Camara.Posicion, PuntoSUR);
			Vista.Normalizar();

			Ambiente = Constantes.Ambiente;
			NormalSUR.Normalizar();

			for (long i = 0; i <= Focos.GetUpperBound(0); i++) {
				Rayo = new Vector3D(Focos[i].Coordenadas, PuntoSUR);
				Rayo = !Rayo.VectorUnitario;
				Salida = (((2 * (NormalSUR * Rayo)) * NormalSUR) - Rayo).VectorUnitario;

				Difusa = Focos[i].Intensidad * (Constantes.Difusa * (NormalSUR * Rayo));
				Escalar = (Salida * Vista);
				if (Escalar < 0) {
					Especular = Math.Abs((Constantes.Especular * Math.Pow(Escalar, Constantes.ExponenteEspecular)));
				} else {
					Especular = 0;
				}

				AmbienteR = Ambiente * (Focos[i].Color.R / 255);
				DifusaR = Difusa * (Focos[i].Color.R / 255);
				EspecularR = Especular * (Focos[i].Color.R / 255);

				AmbienteG = Ambiente * (Focos[i].Color.G / 255);
				DifusaG = Difusa * (Focos[i].Color.G / 255);
				EspecularG = Especular * (Focos[i].Color.G / 255);

				AmbienteB = Ambiente * (Focos[i].Color.B / 255);
				DifusaB = Difusa * (Focos[i].Color.B / 255);
				EspecularB = Especular * (Focos[i].Color.B / 255);

				rr = Color.R * (AmbienteR + DifusaR);
				rr = rr + ((Focos[i].Color.R - rr) * EspecularR);

				gg = Color.G * (AmbienteG + DifusaG);
				gg = gg + ((Focos[i].Color.G - gg) * EspecularG);

				bb = Color.B * (AmbienteB + DifusaB);
				bb = bb + ((Focos[i].Color.B - bb) * EspecularB);

				if (rr < 0)
					rr = 0;
				if (gg < 0)
					gg = 0;
				if (bb < 0)
					bb = 0;

				trr += rr;
				tgg += gg;
				tbb += bb;
			}

			if (trr > 255)
				trr = 255;
			if (trr < 0)
				trr = 0;

			if (tgg > 255)
				tgg = 255;
			if (tgg < 0)
				tgg = 0;

			if (tbb > 255)
				tbb = 255;
			if (tbb < 0)
				tbb = 0;

			r = trr;
			g = tgg;
			b = tbb;

			return Color.FromArgb(255, r, g, b);
		}