Exemplo n.º 1
0
        public static bool avoid_circulo(double newx, double newy, Vector velocity, Cairo.Rectangle circulo, Vector location)
        {
            double dSiguiente = Constantes.distancia_dos_puntos((int)newx, (int)newy, (int)circulo.X, (int)mapeo((int)circulo.Y));
            double dActual = Constantes.distancia_dos_puntos((int)location.X, (int)location.Y, (int)circulo.X, (int)mapeo((int)circulo.Y));
            double velX, velY;

            if ((dActual >= circulo.Width + 10 && dSiguiente <= circulo.Width + 10))
            {
                Vector n = new Vector(newx - circulo.X, newy - mapeo(circulo.Y));
                n.normalize();
                Vector d = new Vector(velocity.X, velocity.Y);

                double escalar = 2 * (d.escalar(n));
                Vector r       = new Vector(d.X - (escalar * n.X), d.Y - (escalar * n.Y));
                velX = r.X;
                velY = r.Y;
                newx = location.X + velX;
                newy = location.Y + velY;

                double dNueva = Constantes.distancia_dos_puntos((int)newx, (int)newy, (int)circulo.X, (int)mapeo((int)circulo.Y));
                if (dNueva <= circulo.Width + 10)
                {
                    velX = velocity.X * -1;
                    velY = velocity.Y * -1;
                }

                velocity.X = velX;
                velocity.Y = velY;

                Constantes.reboto = true;
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
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();
                }
            }
        }
Exemplo n.º 3
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++;
            }
        }