示例#1
0
        private void UpdateViewSurface()
        {
            if (Constantes.escenario)
            {
                //whenever we want
                //draw onto our surface in memory
                using (Context cr = new Context(Constantes.viewSurface)) {
                    if (ventana.circulo.Active)
                    {
                        if (!Constantes.contiene(Logica.circulos, new Obstaculo(xo, yo, Constantes.distancia(xt, xo), 0, (int)ventana.intermitencia.Value)) && Constantes.distancia(xt, xo) != 0)
                        {
                            Logica.circulos.Add(new Obstaculo(xo, yo, Constantes.distancia(xt, xo), 0, (int)ventana.intermitencia.Value));
                        }
                        cr.LineWidth = 2;
                        cr.SetSourceRGBA(0, 0, 1, 1);
                        cr.Arc(xo, yo, Constantes.distancia(xt, xo), 0, Math.PI * 2);
                        cr.Stroke();
                    }
                    else if (ventana.linea.Active)
                    {
                        if (!Constantes.contiene(Logica.lineas, new Obstaculo(xo, yo, xt, yt, (int)ventana.intermitencia.Value)) && Constantes.distancia_dos_puntos(xo, yo, xt, yt) != 0)
                        {
                            Logica.lineas.Add(new Obstaculo(xo, yo, xt, yt, (int)ventana.intermitencia.Value));
                        }
                        cr.LineWidth = 2;
                        cr.SetSourceRGBA(0, 1, 0, 1);
                        cr.MoveTo(xo, yo);
                        cr.LineTo(xt, yt);
                        cr.Stroke();
                    }
                    else if (ventana.rectangulo.Active)
                    {
                        if (!Constantes.contiene(Logica.rectangulos, new Obstaculo(xo, yo, xt - xo, yt - yo, (int)ventana.intermitencia.Value)) && (Constantes.distancia(xt, xo) != 0 || Constantes.distancia(yt, yo) != 0))
                        {
                            Logica.rectangulos.Add(new Obstaculo(xo, yo, xt - xo, yt - yo, (int)ventana.intermitencia.Value));
                        }
                        cr.Rectangle(xo, yo, xt - xo, yt - yo);
                        cr.LineWidth = 2;
                        cr.SetSourceRGBA(1, 0, 0, 1);
                        cr.Stroke();
                    }
                    else if (ventana.puntoInicio.Active)
                    {
                        if (!Logica.puntos_inicio.Contains(new System.Drawing.Point(xo, yo)))
                        {
                            Logica.puntos_inicio.Add(new System.Drawing.Point(xo, yo));
                        }
                        cr.SetSourceRGBA(1, 0, 1, 0.8);
                        cr.Arc(xo, yo, 10, 0, 2 * Math.PI);
                        cr.Fill();
                        cr.Stroke();
                    }
                    else if (ventana.puntoObjetivo.Active)
                    {
                        int n = (int)ventana.nivel.Value;
                        if (ventana.nivel.Value == Constantes.max_nivel)
                        {
                            Logica.puntos_objetivo.Add(new Objetivo());
                            Constantes.max_nivel++;
                            ventana.nivel.SetRange(1, Constantes.max_nivel);
                        }
                        if (!Logica.puntos_objetivo [(int)ventana.nivel.Value - 1].contains(xo, yo))
                        {
                            Logica.puntos_objetivo [(int)ventana.nivel.Value - 1].add_objetivo(xo, yo);
                        }
                        cr.SetSourceRGBA(1, 0, 0, 0.6);
                        cr.Arc(xo, yo, Constantes.radio_objetivos, 0, 2 * Math.PI);
                        cr.Fill();
                        cr.Stroke();
                        cr.SetSourceRGB(0, 0, 0);
                        cr.SelectFontFace("Arial", FontSlant.Normal, FontWeight.Normal);
                        cr.SetFontSize(12);
                        TextExtents t = cr.TextExtents(n.ToString());
                        cr.MoveTo(xo - 4, yo + 4);
                        cr.ShowText(n.ToString());
                    }


                    cr.Dispose();
                }
            }
        }
示例#2
0
        private void play_simulacion_finita2(DrawingArea area, Cairo.Context cr)
        {
            int      n    = 0;
            TimeSpan temp = new TimeSpan(0);

            if (Logica.play)
            {
                if (Constantes.iteraciones_total >= 2000000000)
                {
                    Constantes.iteraciones_total = 0;
                }
                Constantes.iteraciones_total++;
                a1 = DateTime.Now;
                if (Constantes.iteraciones_lapso != 0 && Constantes.tiempo % Constantes.iteraciones_lapso == 0)
                {
                    Logica.add_boids_iteracion();
                }
                else if (Constantes.iteraciones_lapso == 0)
                {
                    Logica.add_boids_iteracion();
                }

                //PARA DETENER LA SIMULACION EN UNA ITERACION DETERMINADA!!
                if (Constantes.tiempo == 10000)
                {
                    Logica.play = false;
                }
                //-----------------------------------------------------------

                Constantes.tiempo++;
                if (Constantes.tiempo > 2000000000)
                {
                    Constantes.tiempo = 0;
                    Logica.reset_trayectorias();
                }
            }

            for (int i = 0; i < Logica.objects.Count; i++)
            {
                u = Logica.grilla.ubicacion_boid(Logica.objects[i]);
                coleccion.Clear();
                rectangulos.Clear();
                lineas.Clear();
                circulos.Clear();
                for (int x = u.X; x <= u.Width; x++)
                {
                    for (int y = u.Y; y <= u.Height; y++)
                    {
                        coleccion.Add(Logica.objects [0]);
                        coleccion.AddBoids(Logica.grilla.get_casillero(x, y).boids);
                        Constantes.addObstacles(Logica.grilla.get_casillero(x, y).circulos, circulos);
                        Constantes.addObstacles(Logica.grilla.get_casillero(x, y).lineas, lineas);
                        Constantes.addObstacles(Logica.grilla.get_casillero(x, y).rectangulos, rectangulos);
                    }
                }
                //				TimeSpan total = new TimeSpan (r2.Ticks - r1.Ticks);
                //				System.Console.WriteLine (total);
                if (Logica.play)
                {
                    if (n == 0 && Logica.mouse)
                    {
                        Logica.objects[i].calculateVelocity(Logica.objects, area);
                    }
                    else if (n != 0)
                    {
                        Logica.objects[i].calculateVelocity(coleccion, circulos, rectangulos, lineas);

                        if (Logica.objects[i].llego)
                        {
                            Logica.objects.RemoveAt(i);
                            i--;
                        }
                    }
                }

                n++;
            }
            r1 = DateTime.Now;
            n  = 0;
            foreach (Boid s in Logica.objects)
            {
                if (n != 0)
                {
                    rot = s.calculateRotation();
                    if (ventana.contorno.Active)
                    {
                        triangulo_contorno(cr, s.Location, rot);
                    }
                    else
                    {
                        triangulo(cr, s, rot);
                    }
                }
                n++;
            }

            r2    = DateTime.Now;
            temp += new TimeSpan(r2.Ticks - r1.Ticks);
            Constantes.r_acum += new TimeSpan(r2.Ticks - r1.Ticks);

            Logica.actualizar_posicion_boids();

            Logica.grilla.reclasificar(Logica.objects);


            if (Logica.play)
            {
                a2 = DateTime.Now;
                Constantes.a_acum               += new TimeSpan(a2.Ticks - a1.Ticks) - temp;
                ventana.render.Text              = "Tiempo de rendering: " + Constantes.r_acum.ToString() + "    ";
                ventana.algorithm.Text           = "Tiempo de algoritmo: " + Constantes.a_acum.ToString();
                ventana.etiquetaIteraciones.Text = "   Cantidad de iteraciones: " + Constantes.iteraciones_total.ToString();
            }
        }
示例#3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Constantes.ogre3d && !Constantes.sincronizar)
            {
                int n = 0;
                foreach (Boid b1 in Logica.objects)
                {
                    if (n != 0 && b1.ogreRef != IntPtr.Zero)
                    {
                        float g = (float)(b1.calculateRotationOgre());

                        ogreSceneWrap.rotateNode(b1.ogreRef, (float)(-b1.rotacion));

                        ogreSceneWrap.rotateNode(b1.ogreRef, g);

                        ogreSceneWrap.moveNode(b1.ogreRef, (float)(Constantes.mapearOgre(b1.Location.Y, Constantes.limites.Height)), 50, (float)(Constantes.mapearOgre(b1.Location.X, Constantes.limites.Width)));

                        b1.rotacion = g;
                    }
                    n++;
                }
            }
        }
示例#4
0
        private void button3_Click(object sender, EventArgs e)
        {
            //foreach (Obstaculo r in Logica.rectangulos)
            //{
            //    System.Console.WriteLine("Rectangulo 1");
            //    IntPtr boidRef = ogreSceneWrap.addWall("wall" + Convert.ToString(index), (float)(Constantes.mapearOgre((float)(Logica.mapeo(r.rectangle.Y)), Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(r.rectangle.X, Constantes.limites.Width)), 0.5f, 1.0f, 0.5f, 0);
            //    r.ogreRef = boidRef;
            //    index++;
            //}

            foreach (Obstaculo r in Logica.rectangulos)
            {
                float y = (float)((r.rectangle.Y) + (r.rectangle.Height / 2));
                float x = (float)((r.rectangle.X) + (r.rectangle.Width / 2));

                IntPtr boidRef = ogreSceneWrap.addWall("wall" + Convert.ToString(index), (float)(Constantes.mapearOgreObs(y, Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(r.rectangle.X, Constantes.limites.Width)), (float)r.rectangle.Height / 100, 1.0f, 0.1f, 0);
                r.ogreRef = boidRef;
                index++;

                boidRef   = ogreSceneWrap.addWall("wall" + Convert.ToString(index), (float)(Constantes.mapearOgreObs(r.rectangle.Y, Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(x, Constantes.limites.Width)), 0.1f, 1.0f, (float)r.rectangle.Width / 100, 0);
                r.ogreRef = boidRef;
                index++;

                float yh = (float)((r.rectangle.Y) + (r.rectangle.Height));
                float xw = (float)((r.rectangle.X) + (r.rectangle.Width));

                boidRef   = ogreSceneWrap.addWall("wall" + Convert.ToString(index), (float)(Constantes.mapearOgreObs(yh, Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(x, Constantes.limites.Width)), 0.1f, 1.0f, (float)r.rectangle.Width / 100, 0);
                r.ogreRef = boidRef;
                index++;

                boidRef   = ogreSceneWrap.addWall("wall" + Convert.ToString(index), (float)(Constantes.mapearOgreObs(y, Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(xw, Constantes.limites.Width)), (float)r.rectangle.Height / 100, 1.0f, 0.1f, 0);
                r.ogreRef = boidRef;
                index++;
            }

            foreach (Obstaculo c in Logica.circulos)
            {
                IntPtr boidRef = ogreSceneWrap.addObstacle("obs" + Convert.ToString(index), 1, (float)(Constantes.mapearOgreObs(c.rectangle.Y, Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(c.rectangle.X, Constantes.limites.Width)), (float)c.rectangle.Width / 30, 0.3f, (float)c.rectangle.Width / 30, 0);
                c.ogreRef = boidRef;
                index++;
            }

            foreach (Obstaculo l in Logica.lineas)
            {
                float line_size = (float)Constantes.distancia_dos_puntos((int)l.rectangle.X, (int)l.rectangle.Y, (int)l.rectangle.Width, (int)l.rectangle.Height);
                float pendiente = (float)((l.rectangle.Height - l.rectangle.Y) / (l.rectangle.Width - l.rectangle.X));

                float width  = (float)Math.Abs(l.rectangle.Width - l.rectangle.X);
                float height = (float)Math.Abs(l.rectangle.Height - l.rectangle.Y);

                float x;
                float y;

                if (l.rectangle.X <= l.rectangle.Width)
                {
                    x = (float)((l.rectangle.X) + (width / 2));
                    y = (float)((l.rectangle.Y) + (height / 2));
                    if (pendiente < 0)
                    {
                        y = (float)((l.rectangle.Y) - (height / 2));
                    }
                }
                else
                {
                    x = (float)((l.rectangle.Width) + (width / 2));
                    y = (float)((l.rectangle.Height) + (height / 2));
                    if (pendiente < 0)
                    {
                        y = (float)((l.rectangle.Height) - (height / 2));
                    }
                }


                Vector v = new Vector(l.rectangle.Width - l.rectangle.X, l.rectangle.Height - l.rectangle.Y);
                v.normalize();

                IntPtr boidRef = ogreSceneWrap.addWall("wall" + Convert.ToString(index), (float)(Constantes.mapearOgreObs(y, Constantes.limites.Height)), 0, (float)(Constantes.mapearOgre(x, Constantes.limites.Width)), 0.1f, 1.0f, line_size / 100, (float)Constantes.calculateRotationOgre(v));
                l.ogreRef = boidRef;
                index++;
            }
        }
示例#5
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            int n = 0;

            foreach (Boid b in Logica.objects)
            {
                if (n != 0)
                {
                    IntPtr boidRef = ogreSceneWrap.addBoid("boid" + Convert.ToString(index), (float)(Constantes.mapearOgre(b.Location.Y, Constantes.limites.Height)), 50, (float)(Constantes.mapearOgre(b.Location.X, Constantes.limites.Width)), 50.0f, 50.0f, 50.0f, 0);
                    b.ogreRef = boidRef;
                    System.Console.WriteLine("OgreRef " + n + ": " + boidRef);
                    index++;
                }
                n++;
            }
            Constantes.ogre3d = true;
        }