コード例 #1
0
ファイル: ZBuffer.cs プロジェクト: Manu343726/Motor3D_2.0
		public void Actualizar(ref Poliedro[] Poliedros, ref Camara3D Camara)
		{
			List<ElementoZBuffer> Objetos = new List<ElementoZBuffer>();
			List<Poligono2D> Representaciones = new List<Poligono2D>();
			System.DateTime T = DateAndTime.Now;
			int n = 0;
			if ((Poliedros != null)) {
				if (!Vacio) {
					for (int i = 0; i <= mObjetos.GetUpperBound(0); i++) {
						if (mObjetos[i].Indices[1] <= Poliedros.GetUpperBound(0) && mObjetos[i].Indices[2] < Poliedros[mObjetos[i].Indices[1]].NumeroCaras) {
							if (Poliedros[mObjetos[i].Indices[1]].CaraVisible[mObjetos[i].Indices[2], Camara]) {
								Objetos.Add(new ElementoZBuffer(Poliedros[mObjetos[i].Indices[1]].Caras[mObjetos[i].Indices[2]].BaricentroSRC.Z, n, mObjetos[i].Indices[1], mObjetos[i].Indices[2]));
								Representaciones.Add(new Poligono2D(Poliedros[mObjetos[i].Indices[1]].Caras[mObjetos[i].Indices[2]].Representacion[Poliedros[mObjetos[i].Indices[1]].Vertices]));
								Representaciones[Representaciones.Count - 1].Color = Poliedros[mObjetos[i].Indices[1]].Caras[mObjetos[i].Indices[2]].Color;
								Poliedros[mObjetos[i].Indices[1]].Caras[mObjetos[i].Indices[2]].CargadaEnBuffer = true;

								n += 1;
							} else {
								Poliedros[mObjetos[i].Indices[1]].Caras[mObjetos[i].Indices[2]].CargadaEnBuffer = false;
							}
						}
					}
				}

				for (int i = 0; i <= Poliedros.GetUpperBound(0); i++) {
					for (int j = 0; j <= Poliedros[i].NumeroCaras - 1; j++) {
						if (!Poliedros[i].Caras[j].CargadaEnBuffer) {
							if (Poliedros[i].CaraVisible[j, Camara]) {
								Objetos.Add(new ElementoZBuffer(Poliedros[i].Caras[j].BaricentroSRC.Z, n, i, j));
								Representaciones.Add(Poliedros[i].Representacion[j]);
								Poliedros[i].Caras[j].CargadaEnBuffer = true;

								n += 1;
							}
						}

					}
				}

				mObjetos = Objetos.ToArray();
				mRepresentaciones = Representaciones.ToArray();
				Reordenar();
			} else {
				mObjetos = null;
				mRepresentaciones = null;
			}

			mTiempo = (DateAndTime.Now - T).TotalMilliseconds;

			if (Modificado != null) {
				Modificado(this);
			}
		}
コード例 #2
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public bool EsVisible(Camara3D Camara)
		{
			if (!Camara.EsVisible(mCentroSUR)) {
				foreach (Vertice Vertice in mVertices) {
					if (!Camara.EsVisible(Vertice.CoodenadasSUR)) {
						return false;
					}
				}

				return true;
			} else {
				return false;
			}
		}
コード例 #3
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public void RecalcularRepresentaciones(Camara3D Camara)
		{
			for (int i = 0; i <= mVertices.GetUpperBound(0); i++) {
				mVertices[i].CoodenadasSRC = Camara.TransformacionSURtoSRC * mVertices[i].CoodenadasSUR;
				mVertices[i].Representacion = Camara.Proyeccion(mVertices[i].CoodenadasSRC, true);
			}

			if (NormalesCentro) {
				for (int i = 0; i <= mCaras.GetUpperBound(0); i++) {
					mCaras[i].RecalcularBaricentroSRC(mVertices);
					mCaras[i].NormalSRC = new Vector3D(mCentroSRC, mCaras[i].BaricentroSRC).VectorUnitario;
				}
			} else {
				for (int i = 0; i <= mCaras.GetUpperBound(0); i++) {
					mCaras[i].RecalcularBaricentroSRC(mVertices);
					mCaras[i].NormalSRC = Cara.VectorNormalSRC(mCaras[i], mVertices);
				}
			}

			mCentroSRC = Camara.TransformacionSURtoSRC * mCentroSUR;

			if (mAutoRecalcularCajas)
				mCajaSRC = ObtenerCajaSRC();
		}
コード例 #4
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public void Shading(Foco3D[] Focos, Camara3D Camara)
		{
			if ((Focos != null)) {
				for (int i = 0; i <= mCaras.GetUpperBound(0); i++) {
					mCaras[i].Shading(mConstantesShading, Focos, Camara);
				}
			} else {
				for (int i = 0; i <= mCaras.GetUpperBound(0); i++) {
					mCaras[i].ColorShading = Color.Black;
				}
			}
		}
コード例 #5
0
ファイル: Motor3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public void ObtenerReferenciaCamara(ref Camara3D Camara, int Indice)
		{
			if (Indice >= 0 && Indice <= mCamaras.GetUpperBound(0)) {
				Camara = mCamaras[Indice];
			}
		}
コード例 #6
0
ファイル: Motor3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public void QuitarCamara(ref Camara3D Camara)
		{
			if ((mCamaras != null) && mCamaras.Contains(Camara)) {
				if (mCamaras.GetUpperBound(0) > 0) {
					Camara3D[] Copia = new Camara3D[mCamaras.GetUpperBound(0) + 1];
					mCamaras.CopyTo(Copia, 0);

					mCamaras = new Camara3D[mCamaras.GetUpperBound(0)];

					for (int i = 0; i <= Copia.GetUpperBound(0); i++) {
						if (Copia[i] != Camara) {
							if (i <= mCamaras.GetUpperBound(0)) {
								mCamaras[i] = Copia[i];
							} else {
								mCamaras[i - 1] = Copia[i];
							}
						} else {
							if (mCamaraSeleccionada == Camara) {
								mCamaraSeleccionada = Copia[i + 1];
							}
						}
					}

					Camara.Modificado -= CamaraModificada;
				} else {
					mCamaras = null;
					if (Camara == mCamaraSeleccionada)
						mCamaraSeleccionada = null;
				}
			}
		}
コード例 #7
0
ファイル: Motor3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public void AñadirCamara(ref Camara3D Camara)
		{
			if ((mCamaras != null)) {
				Array.Resize(ref mCamaras, mCamaras.GetUpperBound(0) + 2);
			} else {
				mCamaras = new Camara3D[1];
			}

			mCamaras[mCamaras.GetUpperBound(0)] = Camara;
			if ((mCamaraSeleccionada != null))
				mCamaraSeleccionada.Modificado -= CamaraModificada;
			mCamaraSeleccionada = Camara;
			mCamaraSeleccionada.Modificado += CamaraModificada;
			CamaraModificada(ref mCamaraSeleccionada);
		}
コード例 #8
0
ファイル: Motor3D.cs プロジェクト: Manu343726/Motor3D_2.0
		private void CamaraModificada(ref Camara3D Sender)
		{
			if ((mPoliedros != null) && Sender == mCamaraSeleccionada) {
				for (int i = 0; i <= mPoliedros.GetUpperBound(0); i++) {
					mPoliedros[i].RecalcularRepresentaciones(Sender);
					mPoliedros[i].Shaded = false;
				}

				Buffer.Actualizar(ref mPoliedros, ref Sender);
				Shading();

				if (Modificado != null) {
					Modificado(this);
				}
			}
		}
コード例 #9
0
ファイル: Cara.cs プロジェクト: Manu343726/Motor3D_2.0
		public bool EsVisible(Camara3D Camara, Vertice[] Vertices)
		{
			if (mNormalSRC.Z <= 0.01 && Camara.Frustum.Pertenece(mBaricentroSRC)) {
				for (int i = 0; i <= mVertices.GetUpperBound(0); i++) {
					if (Camara.Pantalla.Pertenece(Vertices[mVertices[i]].Representacion)) {
						return true;
					}
				}

				return false;
			} else {
				return false;
			}
		}
コード例 #10
0
ファイル: Cara.cs プロジェクト: Manu343726/Motor3D_2.0
		public void Shading(PhongShader Constantes, Foco3D[] Focos, Camara3D Camara)
		{
			mColorShading = Constantes.EcuacionPhong(Focos, mNormalSUR, mBaricentroSUR, mColor, Camara);
		}