public override void Dibujar() { if (textura == null) { textura = TexturaManager.Instance.CargarTextura(Data.NombresTexturas.OndaExpansiva); } Color c; float inicioTransparencia = duracionSegundos * 2 / 3; //Dibujo la onda con transparencia recien sobre el 1/3 final de su vida if (duracionTranscurrida >= inicioTransparencia) { float alpha = 1.0f - (duracionTranscurrida - inicioTransparencia) / (duracionSegundos - inicioTransparencia); alpha *= alpha; if (alpha < 0.05f) { alpha = 0.05f; } c = Color.FromArgb((int)(alpha * 255.0f), Color.White); } else { c = Color.White; } GraphicEngine.Instance.DrawRectangle(Centro, RotacionEnGrados, Tamanio, textura, c); }
/// <summary> /// Crea un mipmapping de la textura y la guarda en la BBDD /// </summary> /// <param name="orig">Textura original</param> /// <param name="nombre">Nombre de la imagen original </param> /// <param name="ancho">Ancho que debe tener la nueva imagen</param> /// <param name="alto">Alto que debe tener la nueva imagen</param> private void MipMapping(Texture2D orig, string nombre, int ancho, int alto) { //hacemos mipmapping //comprobamos si alguna de las imagenes mipmapping han sido borradas para restaurarlas string nombreaux = nombre; while (ancho > 64 && alto > 64) { nombreaux = nombre + " " + ancho.ToString() + " x " + alto.ToString(); byte[] data; TextureScale.Point(orig, ancho, alto); data = orig.EncodeToJPG(); var p = new Textura { Nombre = nombreaux, Ancho = ancho, Alto = alto, Image = data, Nmipmap = -1 }; _connection.Insert(p); alto = alto / 2; ancho = ancho / 2; } }
/// <summary> /// Añade las texturas de prueba a la tabla /// </summary> /// <param name="data"> Array de bytes con la informacion de la imagen</param> /// <param name="nombre">Nombre de la imagen</param> public void GuardarImagen(byte[] data, string nombre) { try { Texture2D bit = new Texture2D(2, 2, TextureFormat.ARGB32, false); bit.LoadImage(data); //Comprobamos que este mismo elemento no esté en la tabla y no lo añade Pair <Pair <int, int>, Pair <int, int> > anchoxalto = Potenciade2(bit.width, bit.height); string[] separador = nombre.Split('.'); string nombrecorrecto = separador[0]; if (this.TexturaEnBaseDeDatos(nombrecorrecto) == null) { var p = new Textura { Nombre = nombrecorrecto, Ancho = bit.width, Alto = bit.height, Image = data, //se guarda el numero de veces que se ha hecho mipmapping Nmipmap = Math.Min(anchoxalto.Second.First, anchoxalto.Second.Second) }; _connection.Insert(p); MipMapping(bit, nombrecorrecto, anchoxalto.First.First, anchoxalto.First.Second); } } catch { Debug.Log("fallo en la insercción de fotos"); } }
public override void Dibujar() { if (textura == null) { textura = TexturaManager.Instance.CargarTextura(Data.NombresTexturas.EstacionEspacial); } GraphicEngine.Instance.DrawRectangle(Centro, RotacionEnGrados, Tamanio, textura); }
public override void Dibujar() { if (Textura == null) { Textura = TexturaManager.Instance.CargarTextura(Data.NombresTexturas.AgujeroDeGusano); } GraphicEngine.Instance.DrawRectangle(Centro, RotacionEnGrados, Tamanio * 2.0f, Textura); }
/// <summary> /// Carga las texturas de los edificios que se guardaron /// </summary> public void CargarEdificios() { try { Buildings[] buildings = this.GetBuildings(); Transform[] trans = GameObject.Find("Canvas").GetComponentsInChildren <Transform>(true); Dictionary <string, string> map = null; foreach (Transform t in trans) { if (t.gameObject.name == "ButtonscrollList") { map = t.gameObject.GetComponent <ButtonListControl>().givemap(); } } Dictionary <string, string> aux = new Dictionary <string, string>(map); if (buildings.Length != 0) { for (int i = 0; i < buildings.Length; i++) { aux.Remove(buildings[i].rutabuild); GameObject gameobject = GameObject.Find(buildings[i].rutabuild); string nameText = buildings[i].nameImage; Textura Textur = _connection.Find <Textura>(d1 => d1.Nombre == nameText); if (Textur != null) { //Se añade la textura a la pared del edificio Texture2D texture = new Texture2D(2, 2, TextureFormat.ARGB32, false); texture.LoadImage(Textur.Image); texture.name = Textur.Nombre; gameobject.transform.GetComponent <MeshRenderer>().material.mainTexture = texture; } else { //en el caso de que no haya textura asociada (techo) se vuelve amarillo Renderer color = gameobject.GetComponent <Renderer>(); color.material.color = UnityEngine.Color.yellow; } } //en el caso de que no deba cargarse esta textura (techo por que no haya nada) volverlo a poner blanco GameObject cube = GameObject.Find("Cube"); foreach (var entry in aux) { GameObject go = GameObject.Find(entry.Key); go.transform.GetComponent <MeshRenderer>().material.mainTexture = cube.transform.GetComponent <MeshRenderer>().material.mainTexture; Renderer color = go.GetComponent <Renderer>(); color.material.color = UnityEngine.Color.white; } } } catch { Debug.Log("No hay datos de los edificios"); } }
/// <summary> /// Devuelve los elementos de la tabla texturas /// </summary> /// <returns>Elementos de la tabla</returns> public Textura[] GetTextures() { Textura[] vect = new Textura[this.GetTamtablaTexture()]; int cont = 0; foreach (var tex in _connection.Table <Textura>()) { vect[cont] = tex; cont++; } return(vect); }
private void cargar_texturas() { var archivos = Directory.GetFiles("Texturas", "*.jpg"); foreach (string ruta in archivos) { var t = new Textura(ruta, Path.GetFileNameWithoutExtension(ruta)); texturas.Add(t); Image imagen = Image.FromFile(ruta); var miniatura = new Bitmap(imagen, new Size(25, 25)); imagenes.Add(t.nombre, miniatura); } }
public Cuerpo(int centro_x, int centro_y, Textura tx) { tx_ = tx; if (centro_x >= 0 && centro_y >= 0) { if (centro_x < tx_.getSizeX() && centro_y < tx_.getSizeY()) { cent_ = new Offset(centro_x, centro_y); } else { cent_ = new Offset(); } } else { cent_ = new Offset(); } }
public override void Dibujar() { if (Textura == null) { Textura = TexturaManager.Instance.CargarTextura(Data.NombresTexturas.Nave); } //Nave if (faccion == null) { GraphicEngine.Instance.DrawRectangle(Centro, RotacionEnGrados, Tamanio, Textura); } else { GraphicEngine.Instance.DrawRectangle(Centro, RotacionEnGrados, Tamanio, Textura, Faccion.Color); } //Indicador de energia float porcentajeEnergia = 100.0f * Vida / MaxVida; float fromX = -Tamanio.X / 2.0f; float toX = -Tamanio.X / 2.0f + Tamanio.X * porcentajeEnergia / 100.0f; Color colorEnergia; if (porcentajeEnergia > 50) { colorEnergia = Color.Green; } else if (porcentajeEnergia > 30) { colorEnergia = Color.Yellow; } else { colorEnergia = Color.Red; } GraphicEngine.Instance.DrawRectangle(new Vector2(Centro.X - Tamanio.X / 2.0f + (toX - fromX) / 2.0f, Centro.Y - Tamanio.Y / 2.0f - 20.0f), 0, new Vector2(toX - fromX, 10), colorEnergia); //Nombre de la nave Graphics.GraphicEngine.Instance.DrawTextStrokeCenteredX(Centro.X, Centro.Y + Tamanio.Y / 2.0f + 75.0f, Color.White, 50.0f, Nombre); }
private void DibujarFrenteNebulosa() { if (nebulas != null) { InicializarRecursos(); if (texturaNebula == null) { texturaNebula = TexturaManager.Instance.CargarTextura(Data.NombresTexturas.Nebulosa); } Gl.glBindTexture(Gl.GL_TEXTURE_2D, texturaNebula.Id); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_COLOR); float porcentajeRecursosDisponibles = recursos[0].CantidadDisponible / recursos[0].MaximoDisponible; int transparencia = (int)(255.0f * porcentajeRecursosDisponibles); foreach (Nebula e in nebulas) { Graphics.GraphicEngine.Instance.SetColor(Color.FromArgb(transparencia, e.color)); Gl.glTranslatef(e.posicion.X, e.posicion.Y, GraphicEngine.zValue); Gl.glRotatef(e.rotacion, 0, 0, 1); Gl.glBegin(Gl.GL_QUADS); Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-e.radius, -e.radius, 1); Gl.glTexCoord2f(1, 0); Gl.glVertex3f(e.radius, -e.radius, 1); Gl.glTexCoord2f(1, 1); Gl.glVertex3f(e.radius, e.radius, 1); Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-e.radius, e.radius, 1); Gl.glEnd(); Gl.glRotatef(-e.rotacion, 0, 0, 1); Gl.glTranslatef(-e.posicion.X, -e.posicion.Y, -GraphicEngine.zValue); } Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor3f(1.0f, 1.0f, 1.0f); } }
private void DibujarTronco() { if (texturaTronco == null) { texturaTronco = new Textura(@"../../Imagenes/Texturas/Arbol/tronco_1.bmp", false); } Gl.glEnable(Gl.GL_TEXTURE_2D); float[] colorBrown = new float[4] { 124.0f / 255.0f, 87.0f / 255.0f, 59.0f / 255.0f, .15f }; Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE, colorBrown); Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, new float[] { 0f, 0f, 0f, 1.0f }); texturaTronco.Activate(); Glu.gluQuadricDrawStyle(quadraticCylinder, Glu.GLU_FILL); Glu.gluQuadricNormals(quadraticCylinder, Glu.GLU_SMOOTH); Glu.gluQuadricTexture(quadraticCylinder, Gl.GL_TRUE); Glu.gluCylinder(quadraticCylinder, this.radioBaseTronco, this.radioBaseTronco, this.longitudTronco, CANTIDAD_CARAS, 1); Gl.glDisable(Gl.GL_TEXTURE_2D); }
public Cubo() { cantidadDeVertices = GetVertices().Length / 5; cantidadDeIndices = GetIndices().Length; bufferDeVertices = new VerticesBuffer(GetVertices(), GetVertices().Length *sizeof(float)); bufferDeIndices = new IndicesBuffer(GetIndices(), GetIndices().Length); SetShader(); textura = new Textura("d:/ginno/Documents/Visual Studio 2017/Projects/Tarea1Grafica/Tarea1Grafica/Recursos/wall.png"); textura.Use(); arregloDeVertices = new VerticesArreglo(); arregloDeVertices.enlazar(); bufferDeVertices.enlazar(); bufferDeIndices.enlazar(); arregloDeVertices.añadirBuffer(bufferDeVertices, shader); CalcularMatrizModelo(); }
/// <summary> /// Obtiene las imagenes que esten en la carpeta Imagen del movil /// </summary> public void ObtenerDeImage() { string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("/Android")) + "/Imagen"; BetterStreamingAssets.Initialize(); if (Application.platform == RuntimePlatform.Android) { if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); string[] dirs = BetterStreamingAssets.GetFiles("Otratextura", "*.*"); foreach (string nombreimage in dirs) { if (!nombreimage.Contains(".meta")) { //Se almacena la imagen de prueba string[] subfile = nombreimage.Split('/'); Texture2D ss = new Texture2D(2, 2); byte[] b = BetterStreamingAssets.ReadAllBytes(nombreimage); ss.LoadImage(b); File.WriteAllBytes(path + "/Final.png", b); File.OpenRead(path + "/Final.png"); //Se fuerza un escaneo de la imagen de prueba using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic <AndroidJavaObject>("currentActivity")) using (AndroidJavaObject joContext = joActivity.Call <AndroidJavaObject>("getApplicationContext")) using (AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass("android.media.MediaScannerConnection")) using (AndroidJavaClass jcEnvironment = new AndroidJavaClass("android.os.Environment")) using (AndroidJavaObject joExDir = jcEnvironment.CallStatic <AndroidJavaObject>("getExternalStorageDirectory")) { jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path + "/Final.png" }, null, null); } } } //aviso de carpeta creada Menu_aviso.SetActive(true); GameObject aviso = GameObject.Find("Aviso"); aviso.GetComponent <Text>().text = "Agrege las fotos a la carpeta Imagen en tu galería y vuelve a pulsar"; } else { string[] dirs = System.IO.Directory.GetFiles(path); if (dirs.Length == 1) { //no hay fotos que añadir Menu_aviso.SetActive(true); GameObject aviso = GameObject.Find("Aviso"); aviso.GetComponent <Text>().text = "No hay fotos que agregar"; } else { bool ninguna_nueva = true; foreach (string nombreimage in dirs) { if (!nombreimage.Contains(".meta") && (nombreimage.Contains(".png") || nombreimage.Contains(".jpg")) && !nombreimage.Contains("Final.png")) { //Se comprueba si las fotos han sido ya guardadas en la BBDD string[] sub = nombreimage.Split('/'); string[] separador = sub[sub.Length - 1].Split('.'); string nombrecorrecto = separador[0]; Textura textura = ds.TexturaEnBaseDeDatos(nombrecorrecto); if (textura == null) { //si no llega aqui es que no habia nuevas fotos que añadir ninguna_nueva = false; byte[] b = File.ReadAllBytes(nombreimage); int valor = ds.GetTamtablaTexture(); ds.GuardarImagen(b, sub[sub.Length - 1].ToString()); Control.AñadirFoto(valor, ds); } } } Menu_aviso.SetActive(true); GameObject aviso = GameObject.Find("Aviso"); if (!ninguna_nueva) { aviso.GetComponent <Text>().text = "Se han añadido al menú de textura"; } else { aviso.GetComponent <Text>().text = "No habia ninguna nueva foto que añadir"; } } } } }
private void DibujarCopa() { Gl.glPushMatrix(); Gl.glRotated(90.0f, 1, 0, 0); if (texturaCopa == null) { texturaCopa = new Textura(@"../../Imagenes/Texturas/Arbol/copa.bmp", false); } Gl.glEnable(Gl.GL_TEXTURE_2D); texturaCopa.Activate(); float[] colorGray = new float[4] { .5f, .5f, .5f, .15f }; float[] colorNone = new float[4] { 0.0f, 0.0f, 0.0f, 0.0f }; Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT_AND_DIFFUSE, colorGray); Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, new float[] { 0f, 0f, 0f, 1.0f }); Punto[] posicionesTextura = new Punto[] { new Punto(0, 0, 0), new Punto(1, 0, 0), new Punto(0, 1, 0), new Punto(1, 1, 0) }; for (int i = 0; i < matrizPuntosCopa.Length - 2; i++) // por columnas duplicadas { int cicloPosicionTextura = 0; Punto posicionTextura = null; Gl.glBegin(Gl.GL_TRIANGLE_STRIP); for (int j = 0; j < matrizPuntosCopa[i].Length; j++) { double ancho = (matrizPuntosCopa[i + 1][j] - matrizPuntosCopa[i][j]).Modulo(); double alto = 1.0f; if (j < matrizPuntosCopa[i].Length - 1) { alto = (matrizPuntosCopa[i][j + 1] - matrizPuntosCopa[i][j]).Modulo(); } double anchoSobreAlto = ancho / alto; posicionTextura = posicionesTextura[cicloPosicionTextura]; cicloPosicionTextura = (cicloPosicionTextura + 1) % posicionesTextura.Length; Gl.glNormal3d(matrizPuntosCopa[i][j].NormalX, matrizPuntosCopa[i][j].NormalY, matrizPuntosCopa[i][j].NormalZ); Gl.glVertex3d(matrizPuntosCopa[i][j].X, matrizPuntosCopa[i][j].Y, matrizPuntosCopa[i][j].Z); Gl.glTexCoord2d(posicionTextura.X, posicionTextura.Y); posicionTextura = posicionesTextura[cicloPosicionTextura]; cicloPosicionTextura = (cicloPosicionTextura + 1) % posicionesTextura.Length; Gl.glNormal3d(matrizPuntosCopa[i + 1][j].NormalX, matrizPuntosCopa[i + 1][j].NormalY, matrizPuntosCopa[i + 1][j].NormalZ); Gl.glVertex3d(matrizPuntosCopa[i + 1][j].X, matrizPuntosCopa[i + 1][j].Y, matrizPuntosCopa[i + 1][j].Z); Gl.glTexCoord2d(posicionTextura.X, posicionTextura.Y); } Gl.glEnd(); } Gl.glDisable(Gl.GL_TEXTURE_2D); if (DIBUJAR_NORMALES) { Gl.glDisable(Gl.GL_LIGHTING); for (int i = 0; i < matrizPuntosCopa.Length - 2; i++) // por columnas duplicadas { for (int j = 0; j < matrizPuntosCopa[i].Length; j++) { Gl.glBegin(Gl.GL_LINES); Gl.glColor3d(1, 0, 0); Gl.glVertex3d(matrizPuntosCopa[i][j].X, matrizPuntosCopa[i][j].Y, matrizPuntosCopa[i][j].Z); Gl.glColor3d(.2, 0, 0); Gl.glVertex3d(matrizPuntosCopa[i][j].NormalX, matrizPuntosCopa[i][j].NormalY, matrizPuntosCopa[i][j].NormalZ); Gl.glEnd(); } } Gl.glEnable(Gl.GL_LIGHTING); } Gl.glPopMatrix(); }
public Cuerpo() { tx_ = new Textura(); cent_ = new Offset(); }