Ejemplo n.º 1
0
		public OctreeGrafico(int Niveles, Caja3D Caja)
		{
			if (Niveles > 1) {
				mNiveles = Niveles;

				mSectorRaiz = new SectorOctreeGrafico(Niveles, Caja);
			} else {
				throw new ExcepcionGeometrica3D("OctreeGrafico (NEW): Un OctreeGrafico debe tener al menos dos niveles:" + Constants.vbNewLine + "Niveles=" + Niveles);
			}
		}
Ejemplo n.º 2
0
		//SOLO PARA EL NODO RAIZ:
		public SectorOctreeGrafico(int Niveles, Caja3D Espacio)
		{
			if (Niveles > 1) {
				mNivel = 0;
				mNiveles = Niveles;
				mIndice = 0;
				mEspacio = Espacio;
				mPadre = null;
				mVacio = true;

				if (mNivel < mNiveles - 1) {
					mHijos = ObtenerSubSectores(this);
				}
			} else {
				throw new ExcepcionPrimitiva3D("SECTOROCTREEGRAFICO (NEW_RAIZ): Un octree necesita al menos dos niveles." + Constants.vbNewLine + "Niveles=" + Niveles.ToString());
			}
		}
Ejemplo n.º 3
0
		public static void InterseccionRecta(Recta3D Recta, SectorOctreeGrafico Sector, ref List<SectorOctreeGrafico> ListaRetorno)
		{
			if (!Sector.EsHoja) {
				foreach (SectorOctreeGrafico Hijo in Sector.Hijos) {
					if (Hijo.Espacio.Pertenece(Recta)) {
						InterseccionRecta(Recta, Hijo, ref ListaRetorno);
					}
				}
			} else {
				if (Sector.Espacio.Pertenece(Recta))
					ListaRetorno.Add(Sector);
			}
		}
Ejemplo n.º 4
0
		public SectorOctreeGrafico(ref SectorOctreeGrafico Padre, int Indice, ref Caja3D Caja)
		{
			if (Padre.Niveles > 1) {
				if (Nivel >= 0 && Nivel < Padre.Niveles) {
					if (Indice >= 0 && Indice <= 7) {
						mNivel = Padre.Nivel + 1;
						mNiveles = Padre.Niveles;
						mIndice = Indice;
						mEspacio = Caja;
						mPadre = Padre;
						mVacio = true;

						if (mNivel < mNiveles - 1) {
							mHijos = ObtenerSubSectores(this);
						}
					} else {
						throw new ExcepcionPrimitiva3D("SECTOROCTREEGRAFICO (NEW): El indice de un sector de Octree debe estar comprendido entre 0 y 7." + Constants.vbNewLine + "Indice=" + Indice.ToString());
					}

				} else {
					throw new ExcepcionPrimitiva3D("SECTOROCTREEGRAFICO (NEW): El nivel de un sector de Octree debe estar entre 0 y el número de niveles del Octree menos uno." + Constants.vbNewLine + "Niveles del Octree=" + Niveles.ToString() + Constants.vbNewLine + "Nivel del sector=" + Nivel.ToString());
				}

			} else {
				throw new ExcepcionPrimitiva3D("SECTOROCTREEGRAFICO (NEW): Un Octree debe tener al menos dos niveles." + Constants.vbNewLine + "Niveles del Octree=" + Niveles.ToString());
			}
		}
Ejemplo n.º 5
0
		public static int Pertenece(ref SectorOctreeGrafico Sector, ref Caja3D Caja)
		{
			if (!Sector.EsHoja && Caja.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(Caja)) {
						return i;
					}
				}
			} else {
				if (Caja.Dimensiones < Sector.Espacio.Dimensiones && Sector.Espacio.Colisionan(Caja)) {
					//LA CAJA PERTENECE AL SECTOR:
					return -1;
				} else {
					//LA CAJA NO PERTENECE AL SECTOR:
					return -2;
				}
			}
		}
Ejemplo n.º 6
0
		public static int Pertenece(ref SectorOctreeGrafico Sector, ref Recta3D Recta)
		{
			if (!Sector.EsHoja) {
				for (int i = 0; i <= 7; i++) {
					if (Sector.Hijos[i].Espacio.Pertenece(Recta)) {
						return i;
					}
				}
			} else {
				if (Sector.Espacio.Pertenece(Recta)) {
					return -1;
				} else {
					return -2;
				}
			}
		}
Ejemplo n.º 7
0
		public static SectorOctreeGrafico[] ObtenerSubSectores(SectorOctreeGrafico Sector)
		{
			if (Sector.Nivel < Sector.Niveles - 1) {
				SectorOctreeGrafico[] Retorno = new SectorOctreeGrafico[8];
				Vector3D Tamaño = new Vector3D(Sector.Espacio.Ancho / 2, Sector.Espacio.Largo / 2, Sector.Espacio.Alto / 2);

				//ABAJO:
				Retorno[0] = new SectorOctreeGrafico(Sector, 0, new Caja3D(Sector.Espacio.Posicion, Tamaño));
				Retorno[1] = new SectorOctreeGrafico(Sector, 1, new Caja3D(new Punto3D(Sector.Espacio.Left + Tamaño.X, Sector.Espacio.Top, Sector.Espacio.Down), Tamaño));
				Retorno[2] = new SectorOctreeGrafico(Sector, 2, new Caja3D(new Punto3D(Sector.Espacio.Left + Tamaño.X, Sector.Espacio.Top + Tamaño.Y, Sector.Espacio.Down), Tamaño));
				Retorno[3] = new SectorOctreeGrafico(Sector, 3, new Caja3D(new Punto3D(Sector.Espacio.Left, Sector.Espacio.Top + Tamaño.Y, Sector.Espacio.Down), Tamaño));
				//ARRIBA:
				Retorno[4] = new SectorOctreeGrafico(Sector, 4, new Caja3D(new Punto3D(Sector.Espacio.Left, Sector.Espacio.Top, Sector.Espacio.Down + Tamaño.Z), Tamaño));
				Retorno[5] = new SectorOctreeGrafico(Sector, 5, new Caja3D(new Punto3D(Sector.Espacio.Left + Tamaño.X, Sector.Espacio.Top, Sector.Espacio.Down + Tamaño.Z), Tamaño));
				Retorno[6] = new SectorOctreeGrafico(Sector, 6, new Caja3D(new Punto3D(Sector.Espacio.Left + Tamaño.X, Sector.Espacio.Top + Tamaño.Y, Sector.Espacio.Down + Tamaño.Z), Tamaño));
				Retorno[7] = new SectorOctreeGrafico(Sector, 7, new Caja3D(new Punto3D(Sector.Espacio.Left, Sector.Espacio.Top + Tamaño.Y, Sector.Espacio.Down + Tamaño.Z), Tamaño));

				return Retorno;
			} else {
				throw new ExcepcionGeometrica3D("SECTOROCTREEGRAFICO (NEW): No se pueden generar subsectores de un sector cuyo nivel es máximo." + Constants.vbNewLine + "Niveles del Octree=" + Sector.Niveles.ToString() + Constants.vbNewLine + "Nivel del sector=" + Sector.Niveles);
			}
		}