コード例 #1
0
ファイル: Octree.cs プロジェクト: Manu343726/Motor3D_2.0
		public Octree(int Niveles, Caja3D Caja)
		{
			if (Niveles > 1) {
				mNiveles = Niveles;

				mSectorRaiz = new SectorOctree(Niveles, Caja);
			} else {
				throw new ExcepcionGeometrica3D("OCTREE (NEW): Un octree debe tener al menos dos niveles:" + Constants.vbNewLine + "Niveles=" + Niveles);
			}
		}
コード例 #2
0
ファイル: Segmento3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public Segmento3D(Punto3D P1, Punto3D P2)
		{
			mExtremoInicial = P1;
			mExtremoFinal = P2;

			mLongitud = Math.Sqrt((Math.Pow((P1.X + P2.X), 2)) + (Math.Pow((P1.Y + P2.Y), 2)));
			mRecta = new Recta3D(P1, P2);

			mCaja = new Caja3D(P1, new Vector3D(P2.X - P1.X, P2.Y - P1.Y, P2.Z - P1.Z));
		}
コード例 #3
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());
			}
		}
コード例 #4
0
		public static int Pertenece(ref SectorOctree 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;
				}
			}
		}
コード例 #5
0
		//SOLO PARA EL NODO RAIZ:
		public SectorOctree(int Niveles, Caja3D Espacio)
		{
			if (Niveles > 1) {
				mNivel = 0;
				mNiveles = Niveles;
				mIndice = 0;
				mEspacio = Espacio;
				mPadre = null;

				if (mNivel < mNiveles - 1) {
					mSubSectores = ObtenerHijos(this);
				}
			} else {
				throw new ExcepcionGeometrica3D("SECTOROCTREE (NEW_RAIZ): Un octree necesita al menos dos niveles." + Constants.vbNewLine + "Niveles=" + Niveles.ToString());
			}
		}
コード例 #6
0
		public SectorOctree(ref SectorOctree Padre, int Indice, 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;

						if (mNivel < mNiveles - 1) {
							mSubSectores = ObtenerHijos(this);
						}
					} else {
						throw new ExcepcionGeometrica3D("SECTOROCTREE (NEW): El indice de un sector de Octree debe estar comprendido entre 0 y 3." + Constants.vbNewLine + "Indice=" + Indice.ToString());
					}

				} else {
					throw new ExcepcionGeometrica3D("SECTOROCTREE (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 ExcepcionGeometrica3D("SECTOROCTREE (NEW): Un Octree debe tener al menos dos niveles." + Constants.vbNewLine + "Niveles del Octree=" + Niveles.ToString());
			}
		}
コード例 #7
0
		public int Pertenece(ref Caja3D Caja)
		{
			return Pertenece(ref this, Caja);
		}
コード例 #8
0
ファイル: Camara3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public void EstablecerAltoFrustum(double Alto)
		{
			mFrustum = new Caja3D(-(mFrustum.Ancho / 2), -mFrustum.Largo / 2, mDistancia, mFrustum.Ancho, mFrustum.Largo, Alto);
			if (Modificado != null) {
				Modificado(this);
			}
		}
コード例 #9
0
ファイル: Octree.cs プロジェクト: Manu343726/Motor3D_2.0
		public SectorOctree Sector(Caja3D Caja)
		{
			return Sector(this, Caja);
		}
コード例 #10
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public void RecalcularCajaSRC()
		{
			mCajaSRC = ObtenerCajaSRC();
		}
コード例 #11
0
ファイル: Camara3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public void EstablecerLargoFrustum(double Largo)
		{
			mFrustum = new Caja3D(-(mFrustum.Ancho / 2), -Largo / 2, mDistancia, mFrustum.Ancho, Largo, mFrustum.Alto);
			mRelacionAspecto = new Punto2D(mResolucionPantalla.X / mFrustum.Ancho, mResolucionPantalla.Y / mFrustum.Largo);
			if (Modificado != null) {
				Modificado(this);
			}
		}
コード例 #12
0
ファイル: Caja3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public bool Colisionan(Caja3D Caja)
		{
			return Colisionan(this, Caja);
		}
コード例 #13
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		private void CalculoTransformacion()
		{
			mVertical = mVertical.VectorUnitario;
			RecalcularCentro();
			RecalcularDatosCaras();
			if (mAutoRecalcularCajas)
				mCajaSUR = ObtenerCajaSUR();
			if (AutoReclcNorms)
				RecalcularNormalesVertices();

			if (Modificado != null) {
				Modificado(this);
			}
			if (TransformacionCompletada != null) {
				TransformacionCompletada(this);
			}
		}
コード例 #14
0
ファイル: Caja3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public static Punto3D PuntoCorteRecta(Caja3D Caja, Recta3D Recta)
		{
			if (Recta.VectorDirector.X == 0) {
				if (Recta.VectorDirector.Y == 0) {
					return Recta.ObtenerPunto(Caja.Centro.Z, EnumEjes.EjeZ);
				} else {
					return Recta.ObtenerPunto(Caja.Centro.Y, EnumEjes.EjeY);
				}
			} else {
				return Recta.ObtenerPunto(Caja.Centro.X, EnumEjes.EjeX);
			}
		}
コード例 #15
0
ファイル: Caja3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public static bool Pertenece(Caja3D Caja, Recta3D Recta)
		{
			double PosicionA = Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[0]);
			double PosicionB = 0;
			bool PlanoA = false;

			if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[1])) {
				if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[2])) {
					if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[3])) {
						if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[4])) {
							if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[5])) {
								if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[6])) {
									if (PosicionA == Recta.PrimerPlano.SignoPosicionRelativa(Caja.Vertices[7])) {
										return false;
									} else {
										PlanoA = true;
									}
								} else {
									PlanoA = true;
								}
							} else {
								PlanoA = true;
							}
						} else {
							PlanoA = true;
						}
					} else {
						PlanoA = true;
					}
				} else {
					PlanoA = true;
				}
			} else {
				PlanoA = true;
			}

			if (PlanoA) {
				PosicionB = Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[0]);

				if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[1])) {
					if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[2])) {
						if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[3])) {
							if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[4])) {
								if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[5])) {
									if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[6])) {
										if (PosicionB == Recta.SegundoPlano.SignoPosicionRelativa(Caja.Vertices[7])) {
											return false;
										} else {
											return true;
										}
									} else {
										return true;
									}
								} else {
									return true;
								}
							} else {
								return true;
							}
						} else {
							return true;
						}
					} else {
						return true;
					}
				} else {
					return true;
				}
			} else {
				return false;
			}
		}
コード例 #16
0
ファイル: Caja3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public static bool Colisionan(Caja3D C1, Caja3D C2)
		{
			Caja3D R = new Caja3D(C1.Posicion.X - C2.Ancho, C1.Posicion.Y - C2.Largo, C1.Posicion.Z - C2.Alto, C1.Ancho + C2.Ancho, C1.Largo + C2.Largo, C1.Alto + C2.Alto);

			return Pertenece(R, C2.Posicion);
		}
コード例 #17
0
ファイル: Caja3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public static bool Pertenece(Caja3D Caja, Punto3D Punto)
		{
			return (Punto.X >= Caja.Left && Punto.X <= Caja.Right && Punto.Y >= Caja.Top && Punto.Y <= Caja.Bottom && Punto.Z >= Caja.Down && Punto.Z <= Caja.Up);
		}
コード例 #18
0
ファイル: Camara3D.cs プロジェクト: Manu343726/Motor3D_2.0
		public Camara3D()
		{
			mTransformacion = new Transformacion3D();
			mInversa = new Transformacion3D();
			mPosicion = new Punto3D();
			mPuntodeMira = new Punto3D(0, 0, 1);
			mVectorDireccion = new Vector3D(0, 0, 1);
			mDistancia = 1000;
			mFrustum = new Caja3D(-50000, -50000, 1000, 100000, 100000, 100000);
			mResolucionPantalla = new Punto2D(800, 600);
			mRelacionAspecto = new Punto2D(mResolucionPantalla.X / mFrustum.Ancho, mResolucionPantalla.Y / mFrustum.Largo);
			mPantalla = new Caja2D(-ResolucionPantalla.X / 2, -ResolucionPantalla.Y / 2, ResolucionPantalla.X, ResolucionPantalla.Y);
		}
コード例 #19
0
ファイル: Poliedro.cs プロジェクト: Manu343726/Motor3D_2.0
		public void RecalcularCajaSUR()
		{
			mCajaSUR = ObtenerCajaSUR();
		}
コード例 #20
0
ファイル: Segmento3D.cs プロジェクト: Manu343726/Motor3D_2.0
		private void RecalcularDatos()
		{
			mRecta = new Recta3D(mExtremoInicial, mExtremoFinal);
			mCaja = new Caja3D(mExtremoInicial, new Vector3D(mExtremoFinal.X - mExtremoInicial.X, mExtremoFinal.Y - mExtremoInicial.Y, mExtremoFinal.Z - mExtremoInicial.Z));
			mLongitud = Math.Sqrt((Math.Pow((mExtremoInicial.X + mExtremoFinal.X), 2)) + (Math.Pow((mExtremoInicial.Y + mExtremoFinal.Y), 2)));
		}
コード例 #21
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();
		}
コード例 #22
0
ファイル: Octree.cs プロジェクト: Manu343726/Motor3D_2.0
		public static SectorOctree Sector(Octree Octree, Caja3D Caja)
		{
			int Resultado = Octree.SectorRaiz.Pertenece(ref Caja);
			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 Caja);
					} while (Resultado != -2 && Resultado != -1);

					return S;
				}
			} else {
				throw new ExcepcionGeometrica3D("OCTREE (PERTENECE): La caja especificada no pertenece al espacio dominado por el quadtree." + Constants.vbNewLine + "Caja=" + Caja.ToString() + Constants.vbNewLine + "Espacio=" + Octree.Espacio.ToString());
			}
		}