Exemplo n.º 1
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);
			}
		}
Exemplo n.º 2
0
		public static int Pertenece(ref SectorOctree Sector, ref Poliedro Poliedro, bool CajaSUR = false)
		{
			if (CajaSUR) {
				if (!Sector.EsHoja && Poliedro.CajaSUR.Dimensiones < Sector.Espacio.Dimensiones / 2) {
					//LA CAJA PERTENECE A ALGUNO DE LOS HIJOS DEL SECTOR:
					for (int i = 0; i <= 7; i++) {
						if (Sector.Hijos[i].Espacio.Colisionan(Poliedro.CajaSUR)) {
							return i;
						}
					}
				} else {
					if (Poliedro.CajaSUR.Dimensiones < Sector.Espacio.Dimensiones && Sector.Espacio.Colisionan(Poliedro.CajaSUR)) {
						//LA CAJA PERTENECE AL SECTOR:
						Sector.AñadirPoliedro(ref Poliedro);
						return -1;
					} else {
						//LA CAJA NO PERTENECE AL SECTOR:
						return -2;
					}
				}
			} else {
				if (!Sector.EsHoja && Poliedro.CajaSRC.Dimensiones < Sector.Espacio.Dimensiones / 2) {
					//LA CAJA PERTENECE A ALGUNO DE LOS HIJOS DEL SECTOR:
					for (int i = 0; i <= 7; i++) {
						if (Sector.Hijos[i].Espacio.Colisionan(Poliedro.CajaSRC)) {
							return i;
						}
					}
				} else {
					if (Poliedro.CajaSRC.Dimensiones < Sector.Espacio.Dimensiones && Sector.Espacio.Colisionan(Poliedro.CajaSRC)) {
						//LA CAJA PERTENECE AL SECTOR:
						Sector.AñadirPoliedro(ref Poliedro);
						return -1;
					} else {
						//LA CAJA NO PERTENECE AL SECTOR:
						return -2;
					}
				}
			}

		}
Exemplo n.º 3
0
		public int Pertenece(ref Poliedro Poliedro, bool CajaSUR = false)
		{
			return Pertenece(ref this, ref Poliedro, CajaSUR);
		}
Exemplo n.º 4
0
		public bool AñadirPoliedro(ref Poliedro Poliedro)
		{
			if (mObjetos == null) {
				mObjetos = new Poliedro[1];
				mObjetos[0] = Poliedro;
			} else {
				if (!mObjetos.Contains(Poliedro)) {
					Array.Resize(ref mObjetos, mObjetos.GetUpperBound(0) + 2);
					mObjetos[mObjetos.GetUpperBound(0)] = Poliedro;
				} else {
					return false;
				}
			}

			return true;
		}
Exemplo n.º 5
0
		public static Poliedro AplicarTransformacion(Poliedro Poliedro, Traslacion Traslacion)
		{
			Poliedro.AplicarTransformacion(Traslacion);
			return Poliedro;
		}
Exemplo n.º 6
0
		public void ObtenerReferenciaPoliedro(ref Poliedro Poliedro, int Indice)
		{
			if (Indice >= 0 && Indice <= mPoliedros.GetUpperBound(0)) {
				Poliedro = mPoliedros[Indice];
			}
		}
Exemplo n.º 7
0
		public void QuitarPoliedro(ref Poliedro Poliedro)
		{
			if ((mPoliedros != null) && mPoliedros.Contains(Poliedro)) {
				if (mPoliedros.GetUpperBound(0) > 0) {
					Poliedro[] Copia = new Poliedro[mPoliedros.GetUpperBound(0) + 1];
					mPoliedros.CopyTo(Copia, 0);

					mPoliedros = new Poliedro[mPoliedros.GetUpperBound(0)];

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

					Poliedro.Modificado -= PoliedroModificado;
				} else {
					mPoliedros = null;
				}

				Buffer.Actualizar(ref mPoliedros, ref mCamaraSeleccionada);
				if (Modificado != null) {
					Modificado(this);
				}
			}
		}
Exemplo n.º 8
0
		public void AñadirPoliedro(ref Poliedro Poliedro)
		{
			if ((mPoliedros != null)) {
				Array.Resize(ref mPoliedros, mPoliedros.GetUpperBound(0) + 2);
			} else {
				mPoliedros = new Poliedro[1];
			}

			mPoliedros[mPoliedros.GetUpperBound(0)] = Poliedro;

			Poliedro.Modificado += PoliedroModificado;

			PoliedroModificado(ref Poliedro);
		}
Exemplo n.º 9
0
		private void PoliedroModificado(ref Poliedro Sender)
		{
			if (!mModificandoEscena) {
				Sender.RecalcularRepresentaciones(mCamaraSeleccionada);
				//Sender.RecalcularCoordenadasSRC(mCamaraSeleccionada)
				Sender.Shaded = false;

				Buffer.Actualizar(ref mPoliedros, ref mCamaraSeleccionada);
				Shading(Array.IndexOf(mPoliedros, Sender));

				if (Modificado != null) {
					Modificado(this);
				}
			}
		}
Exemplo n.º 10
0
		public SectorOctree Sector(Poliedro Poliedro, bool CajaSUR = false)
		{
			return Sector(this, ref Poliedro, CajaSUR);
		}
Exemplo n.º 11
0
		public static SectorOctree Sector(Octree Octree, ref Poliedro Poliedro, bool CajaSUR = false)
		{
			int Resultado = Octree.SectorRaiz.Pertenece(ref Poliedro, CajaSUR);
			SectorOctree S = Octree.SectorRaiz;

			//PARA ENTENDER EL ALGORITMO, IR A FUNCION PERTENECE DE SECTORQUADTREE.
			if (Resultado != -2) {
				if (Resultado == -1) {
					return Octree.SectorRaiz;
				} else {
					do {
						if (Resultado != -2) {
							if (Resultado == -1) {
								return S;
							} else {
								S = S.Hijos[Resultado];
							}
						} else {
							return S.Padre;
						}
						Resultado = S.Pertenece(ref Poliedro, CajaSUR);
					} while (Resultado != -2 && Resultado != -1);

					return S;
				}
			} else {
				throw new ExcepcionGeometrica3D("OCTREE (PERTENECE): El poliedro especificado no pertenece al espacio dominado por el quadtree." + Constants.vbNewLine + "Poliedro=" + Poliedro.ToString() + Constants.vbNewLine + "Espacio=" + Octree.Espacio.ToString());
			}
		}
Exemplo n.º 12
0
		public static Poliedro AplicarTransformacion(Poliedro Poliedro, Escalado Escalado)
		{
			Poliedro.AplicarTransformacion(Escalado);
			return Poliedro;
		}