示例#1
0
        public virtual void GerarGeometriaRadialVariante(int angulo, int raio_min, int raio_max, int lados)
        {
            Angulo = angulo;
            Random rnd = new Random(Environment.TickCount + lados);

            float rad = (float)(Math.PI * 2 / lados);

            for (int i = 0; i < lados + 1; i++)
            {
                if (i == lados)
                {
                    AdicionarVertice(Vertices[0]);
                }
                else
                {
                    float     raio = rnd.Next(raio_min, raio_max);
                    Vertice2D v    = new Vertice2D();
                    v.x    = (float)(Math.Sin(i * rad + Util.Angulo2Radiano(angulo)) * raio);
                    v.y    = (float)(Math.Cos(i * rad + Util.Angulo2Radiano(angulo)) * raio);
                    v.rad  = i * rad;
                    v.raio = raio;
                    AdicionarVertice(v);
                }
            }

            AtualizarRaio();
        }
示例#2
0
        public void GerarLuzPonto(float angulo, float raio, int lados = 20)
        {
            Angulo = angulo;
            Raio   = raio;
            float rad = (float)(Math.PI * 2 / lados);

            for (int i = 0; i < lados + 1; i++)
            {
                Vertice2D v = new Vertice2D();
                v.x    = (float)(Math.Sin(i * rad + Util.Angulo2Radiano(angulo)) * raio);
                v.y    = (float)(Math.Cos(i * rad + Util.Angulo2Radiano(angulo)) * raio);
                v.rad  = i * rad;
                v.raio = raio;
                AdicionarVertice(v);
            }
        }
示例#3
0
        protected void GerarGeometriaRadial(int angulo, int raio, int lados)
        {
            Angulo = angulo;
            Raio   = raio;
            float rad = (float)(Math.PI * 2 / lados);

            for (int i = 0; i < lados + 1; i++)
            {
                Vertice2D v = new Vertice2D();
                v.x    = (float)(Math.Sin(i * rad + Util.Angulo2Radiano(angulo)) * raio);
                v.y    = (float)(Math.Cos(i * rad + Util.Angulo2Radiano(angulo)) * raio);
                v.rad  = i * rad;
                v.raio = raio;
                AdicionarVertice(v);
            }
        }
示例#4
0
 /// <summary>
 /// Adiciona vértice ao objeto
 /// </summary>
 /// <param name="v"></param>
 public virtual void AdicionarVertice(Vertice2D v)
 {
     Array.Resize(ref Vertices, Vertices.Length + 1);
     Vertices[Vertices.Length - 1] = v;
     AtualizarXYMinMax();
 }
示例#5
0
        public Bitmap Renderizar()
        {
            TempoDelta  = DateTime.Now.Ticks - _tickRender; // Calcula o tempo delta (tempo de atraso)
            _tickRender = DateTime.Now.Ticks;

            if (ResWidth > 0 && ResHeigth > 0) // Janela não minimizada?
            {
                g.Clear(Color.Black);

                // Obtém o fator da câmera conforme sua posição
                fatorCam.X = (int)Pos.x - ResWidth / 2;
                fatorCam.Y = (int)Pos.y - ResHeigth / 2;

                for (int i = 0; i < engine.objetos.Count; i++)
                {
                    Objeto2DRenderizar obj = engine.objetos[i] as Objeto2DRenderizar;
                    if (obj != null)
                    {
                        #region ZOOM
                        if (!DesligarSistemaZoom)
                        {
                            obj = (Objeto2DRenderizar)obj.Clone();
                            Objeto2D objZoom    = ZoomEscalaObjeto2D(obj, ZoomCamera);
                            Objeto2D objPosZoom = ZoomPosObjeto2D(obj, ZoomCamera);
                            objZoom.Pos = objPosZoom.Pos;
                        }
                        #endregion

                        if (Objeto2DVisivel(obj))
                        {
                            if (obj.Mat_render.CorSolida.A > 0) // Pinta objeto materialmente visível
                            {
                                GraphicsPath preenche = new GraphicsPath(FillMode.Alternate);
                                preenche.AddLines(obj.Vertices.ToList().Select(ponto => new Point(
                                                                                   (int)(-fatorCam.X + obj.Pos.x + ponto.x),
                                                                                   (int)(-fatorCam.Y + obj.Pos.y + ponto.y))).ToArray());
                                g.FillPath(new SolidBrush(Color.FromArgb(obj.Mat_render.CorSolida.A, obj.Mat_render.CorSolida.R, obj.Mat_render.CorSolida.G, obj.Mat_render.CorSolida.B)), preenche);
                            }

                            // Materialização do objeto na Câmera
                            Material mat;
                            if (obj.Selecionado)
                            {
                                mat = obj.Mat_render_sel;
                            }
                            else
                            {
                                mat = obj.Mat_render;
                            }

                            if (mat.CorBorda.A > 0) // Desenha borda materialmente visível
                            {
                                // Cor da borda do objeto
                                pen.Color = Color.FromArgb(mat.CorBorda.A, mat.CorBorda.R, mat.CorBorda.G, mat.CorBorda.B);
                                pen.Width = mat.LarguraBorda;

                                for (int v = 1; v < obj.Vertices.Length; v++)
                                {
                                    Vertice2D v1 = obj.Vertices[v - 1]; // Ponto A
                                    Vertice2D v2 = obj.Vertices[v];     // Ponto B

                                    // Desenha as linhas entre as vértices na câmera
                                    pontoA.X = (int)(-fatorCam.X + obj.Pos.x + v1.x);
                                    pontoA.Y = (int)(-fatorCam.Y + obj.Pos.y + v1.y);
                                    pontoB.X = (int)(-fatorCam.X + obj.Pos.x + v2.x);
                                    pontoB.Y = (int)(-fatorCam.Y + obj.Pos.y + v2.y);

                                    g.DrawLine(pen, pontoA, pontoB);
                                }
                            }
                        }
                    }
                }

                // A iluminação deve ser renderizada após pintar todos os objetos.
                for (int i = 0; i < engine.objetos.Count; i++)
                {
                    Luz2DRenderizar luz = engine.objetos[i] as Luz2DRenderizar;
                    if (luz != null)
                    {
                        if (luz is LuzPonto)
                        {
                            if (Objeto2DVisivel(luz))
                            {
                                GraphicsPath preenche = new GraphicsPath();
                                preenche.AddLines(luz.Vertices.ToList().Select(ponto => new Point(
                                                                                   (int)(-fatorCam.X + luz.Pos.x + ponto.x),
                                                                                   (int)(-fatorCam.Y + luz.Pos.y + ponto.y))).ToArray());

                                PathGradientBrush pthGrBrush = new PathGradientBrush(preenche);
                                pthGrBrush.CenterColor = Color.FromArgb(luz.Cor.A, luz.Cor.R, luz.Cor.G, luz.Cor.B);
                                Color[] colors = { Color.FromArgb(0, 0, 0, 0) };
                                pthGrBrush.SurroundColors = colors;
                                g.FillPath(pthGrBrush, preenche);
                            }
                        }
                    }

                    // Sombras devem ser renderizadas após a renderização da iluminação
                    #region Sombras

                    #endregion
                }

                #region Exibe informações de depuração
                if (engine.Debug)
                {
                    g.DrawString(Nome.ToUpper(), font_debug, new SolidBrush(Color.Aquamarine), new Point(10, 10));
                    g.DrawString("FPS: " + FPS, font_debug, new SolidBrush(Color.Aquamarine), new Point(10, 30));
                }
                #endregion
            }

            #region Calcula o FPS
            if (Environment.TickCount - _tickFPS >= 1000)
            {
                _tickFPS = Environment.TickCount;
                FPS      = _fps;
                _fps     = 0;
            }
            else
            {
                _fps++;
            }
            #endregion

            #region Limita o FPS
            // TODO: Limitar o FPS
            #endregion

            return(render);
        }