Esempio n. 1
0
        static void Main(string[] args)
        {
            Mundo window = Mundo.GetInstance(600, 600);

            window.Title = "CG-N2";
            window.Run(1.0 / 60.0);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Mundo window = new Mundo(600, 600);

            window.Title = "CG-N2_2";
            window.Run(1.0 / 60.0);
        }
 /// <summary>
 /// Verfica se o comando é para adicionar um poligono
 /// adicionando ou removendo vertices
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.NEW_POINT))
     {
         this.polygon.AddVertex(new Ponto4D()
         {
             X = Mouse.X, Y = Mouse.Y
         });
     }
     else if (command.Equals(Command.MOUSE_MOVE))
     {
         this.polygon.UpdateVertexLocation(this.polygon.VertexCount() - 1, Mouse.X, Mouse.Y);
     }
     else if (command.Equals(Command.FINALIZE_POLYGON))
     {
         this.polygon.RemoveVertex(this.polygon.VertexCount() - 1);
         if (this.polygon.VertexCount() < 2)
         {
             this.mundo.polygons.Remove(this.polygon);
         }
         else
         {
             this.polygon.primitive     = PrimitiveType.LineLoop;
             this.mundo.polygonSelected = this.polygon;
         }
         return(new MainState());
     }
     return(this);
 }
 /// <summary>
 /// Verifica qual ação deve tomar com base no comando recebido
 /// Podendo selecionar vertice, mover e deletar
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.SELECT_VERTEX))
     {
         mundo.polygonSelected.SelectNearestVertex(Mouse.X, Mouse.Y);
     }
     else if (command.Equals(Command.MOVE))
     {
         canMove = !canMove;
         if (canMove)
         {
             UpdateSelectedVertex(mundo);
         }
     }
     else if (command.Equals(Command.MOUSE_MOVE))
     {
         if (canMove)
         {
             UpdateSelectedVertex(mundo);
         }
     }
     else if (command.Equals(Command.DELETE))
     {
         RemoveSelectedVertex(mundo);
         return(new MainState());
     }
     else if (command.Equals(Command.ESCAPE))
     {
         mundo.polygonSelected.DeselectVertex();
         return(new MainState());
     }
     return(this);
 }
        /// <summary>
        /// O Construtor inicia uma Thread que verifica o teclado
        /// </summary>
        public EventObserver(Mundo mundo)
        {
            this.mundo = mundo;
            Thread t = new Thread(ObserverEvents);

            t.Start();
        }
        public Render(int width, int height) : base(width, height)
        {
            this.camera = new Camera(this);
            camera.InitOrtho(-400, 400, -400, 400);//camera

            this.mundo = new Mundo(camera);
        }
        /// <summary>
        /// Construtror Inicializa os valor iniciais do poligono
        /// </summary>
        /// <param name="mundo"></param>
        public RotatePolygonState(Mundo mundo)
        {
            var bbox = mundo.polygonSelected.GetBBox();

            this.initialX  = bbox.centerX;
            this.initialY  = bbox.centerY;
            this.lastAngle = 0;
        }
Esempio n. 8
0
 public static Mundo GetInstance(int width, int height)
 {
     if (instanciaMundo == null)
     {
         instanciaMundo = new Mundo(width, height);
     }
     return(instanciaMundo);
 }
Esempio n. 9
0
 public static Mundo getInstance(int width, int height)
 {
     if (instance == null)
     {
         instance = new Mundo(width, height);
     }
     return(instance);
 }
Esempio n. 10
0
 public static Mundo getInstance()
 {
     if (instance == null)
     {
         instance = new Mundo(600, 600);
     }
     return(instance);
 }
Esempio n. 11
0
 /// <summary>
 /// Altera a primitiva
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.CHANGE_PRIMITIVE))
     {
         if (mundo.polygonSelected.primitive == PrimitiveType.LineStrip)
         {
             mundo.polygonSelected.primitive = PrimitiveType.LineLoop;
         }
         else
         {
             mundo.polygonSelected.primitive = PrimitiveType.LineStrip;
         }
     }
     return(new MainState());
 }
 /// <summary>
 /// Verfica se o comando é para remover um poligono por completo.
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.DELETE))
     {
         mundo.polygons.Remove(mundo.polygonSelected);
         if (mundo.polygons.Count > 0)
         {
             mundo.polygonSelected = mundo.polygons[mundo.polygons.Count - 1];
         }
         else
         {
             mundo.polygonSelected = null;
         }
     }
     return(new MainState());
 }
Esempio n. 13
0
 /// <summary>
 /// Verifica se é o comando para alterar a cor
 /// altera a cor do poligono
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.CHANGE_COLOR_RED))
     {
         mundo.polygonSelected.color = Color.Red;
     }
     else if (command.Equals(Command.CHANGE_BLUE))
     {
         mundo.polygonSelected.color = Color.Blue;
     }
     else if (command.Equals(Command.CHANGE_GREEN))
     {
         mundo.polygonSelected.color = Color.Green;
     }
     return(new MainState());
 }
 /// <summary>
 /// Contrutor cira um poligono e adiciona ao mundo./
 /// </summary>
 /// <param name="mundo"></param>
 public CreatingPolygonState(Mundo mundo)
 {
     this.mundo = mundo;
     this.mundo.polygonSelected = null;
     this.polygon = new Polygon(new List <Ponto4D> {
         new Ponto4D()
         {
             X = Mouse.X, Y = Mouse.Y
         },
         new Ponto4D()
         {
             X = Mouse.X, Y = Mouse.Y
         }
     });
     mundo.AddPolygon(this.polygon);
 }
 /// <summary>
 /// Verifica se é para trocar a escala de um poligono
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.MOUSE_MOVE))
     {
         if (mundo.polygonSelected != null)
         {
             mundo.polygonSelected.Scale(this.getScale());
         }
         else
         {
             return(new MainState());
         }
     }
     else if (command.Equals(Command.SCALE))
     {
         return(new MainState());
     }
     else if (command.Equals(Command.ESCAPE))
     {
         return(new MainState().Perform(command, mundo));
     }
     return(this);
 }
        /// <summary>
        /// Atualiza a posição do vertice
        /// </summary>
        /// <param name="mundo"></param>
        private static void UpdateSelectedVertex(Mundo mundo)
        {
            var selectedVertex = mundo.polygonSelected.GetSelectedVertex();

            mundo.polygonSelected.UpdateVertexLocation(selectedVertex, Mouse.X, Mouse.Y);
        }
        /// <summary>
        /// Remove o vertice selecionado
        /// </summary>
        /// <param name="mundo"></param>
        private static void RemoveSelectedVertex(Mundo mundo)
        {
            var selectedVertex = mundo.polygonSelected.GetSelectedVertex();

            mundo.polygonSelected.RemoveVertex(selectedVertex);
        }
Esempio n. 18
0
 /// <summary>
 /// Constroi uma nova camera
 /// </summary>
 /// <param name="width">Largura da tela</param>
 /// <param name="height">Altura da tela</param>
 /// <param name="mundo">Mundo</param>
 /// <returns>Void</returns>
 public Camera(int width, int height, Mundo mundo) : base(width, height)
 {
     this.mundo         = mundo;
     this.eventObserver = new EventObserver(this.mundo);
 }
 /// <summary>
 /// Verifica qual ação deve tomar com base no comando recebido
 /// </summary>
 /// <param name="command"></param>
 /// <param name="mundo"></param>
 /// <returns></returns>
 public IState Perform(Command command, Mundo mundo)
 {
     if (command.Equals(Command.ESCAPE))
     {
         mundo.polygonSelected = null;
     }
     else if (command.Equals(Command.SELECT_POLYGON))
     {
         var selectedPolygon = PolygonSelector.GetSelected(mundo.polygons, Mouse.X, Mouse.Y);
         if (selectedPolygon != null)
         {
             mundo.polygonSelected = selectedPolygon;
         }
     }
     else if (command.Equals(Command.MOVE))
     {
         if (mundo.polygonSelected != null)
         {
             return(new TranslatePolygonState(mundo));
         }
     }
     else if (command.Equals(Command.SCALE))
     {
         if (mundo.polygonSelected != null)
         {
             return(new ScalePolygonState());
         }
     }
     else if (command.Equals(Command.ROTATE))
     {
         if (mundo.polygonSelected != null)
         {
             return(new RotatePolygonState(mundo));
         }
     }
     else if (command.Equals(Command.CHILD))
     {
         if (mundo.polygonSelected != null)
         {
             return(new ChildState(mundo));
         }
     }
     else if (command.Equals(Command.NEW_POINT))
     {
         return(new CreatingPolygonState(mundo));
     }
     else if (command.Equals(Command.SELECT_VERTEX))
     {
         if (mundo.polygonSelected != null)
         {
             return(new PointPolygonSelectedState().Perform(command, mundo));
         }
     }
     else if (command.Equals(Command.DELETE))
     {
         return(new DeletingPolygonState().Perform(command, mundo));
     }
     else if (command.Equals(Command.CHANGE_PRIMITIVE))
     {
         return(new PrimitiveState().Perform(command, mundo));
     }
     else if (
         command.Equals(Command.CHANGE_BLUE) ||
         command.Equals(Command.CHANGE_COLOR_RED) ||
         command.Equals(Command.CHANGE_GREEN)
         )
     {
         return(new ColorState().Perform(command, mundo));
     }
     return(this);
 }