<commit_before>﻿using Microsoft.DirectX;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using TgcViewer;
using TgcViewer.Utils._2D;
using TgcViewer.Utils.Input;
using TgcViewer.Utils.TgcGeometry;
using TgcViewer.Utils.TgcSceneLoader;
using TgcViewer.Utils.TgcSkeletalAnimation;

namespace AlumnoEjemplos.MiGrupo
{
    class ArmaManager
    {



        static Size screenSize = GuiController.Instance.Panel3d.Size;
        static string path = GuiController.Instance.AlumnoEjemplosMediaDir;

        private TgcFpsMiCamara camara;

        private SoundManager soundManager;
        private TgcPickingRay pickingRay; //Encargado de chequear si los disparos dieron en el enemigo

        private TgcSprite sprite;
        private TgcMesh armaMesh;

        private EnemigosManager enemigosManager;
        private EscenarioManager escenarioManager;

        private Boolean hayZoom = true;
        private TgcTexture miraZoom  = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\sprites\\zoom.png");
        //private TgcTexture miraSimple  = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\sprites\\05.png");
        private TgcTexture sniper = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\sprites\\SpriteArma5.png");

        public ArmaManager(EnemigosManager enemigosManager, SoundManager soundManager, TgcFpsMiCamara camara, EscenarioManager escenarioManager)
        {
            //this.enemigosManager = enemigosManager;
            this.soundManager = soundManager;
            this.camara = camara;
            this.escenarioManager = escenarioManager;
            this.enemigosManager = enemigosManager;

            pickingRay = new TgcPickingRay();

            //Crear Sprite
            sprite = new TgcSprite();
            hacerZoom(0);
           
            //Cargo el arma
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\modelos\\arma\\arma.xml");
            armaMesh = scene.Meshes[0];
            armaMesh.Scale = new Vector3(0.005f, 0.005f, 0.005f);
    
        }


        public void update(float elapsedTime)
        {

            if (GuiController.Instance.D3dInput.keyDown(Microsoft.DirectX.DirectInput.Key.R))
            {
                soundManager.playSonidoRecarga();
            }

            if (GuiController.Instance.D3dInput.buttonDown(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_LEFT) == true)
            {
                manejarDisparo();
            }

            if (GuiController.Instance.D3dInput.buttonDown(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_RIGHT) == true)
            {
                hacerZoom(elapsedTime);
            }


            GuiController.Instance.Drawer2D.beginDrawSprite();
            sprite.render();
            GuiController.Instance.Drawer2D.endDrawSprite();

            if (!hayZoom)
            {
                actualizarPosicionArma();
                armaMesh.render();
            }
            
        }


        private float timeFromZoom = 100;
        private void hacerZoom(float elapsedTime)
        {
           
            hayZoom = !hayZoom;
            if (hayZoom)
            {
                sprite.Texture = miraZoom;
                //sprite.Scaling = new Vector2(0.7f, 0.38f);
            }
            else
            {
                sprite.Texture = sniper;
                //sprite.Texture = miraSimple;
                //sprite.Scaling = new Vector2(1f, 1f);
            }

            this.camara.hacerZoom();

            //Ubicarlo centrado en la pantalla
            Size screenSize = GuiController.Instance.Panel3d.Size;
            Size textureSize = sprite.Texture.Size;

            sprite.Scaling = new Vector2(ajustarTexturaAPantalla(screenSize.Width,textureSize.Width), ajustarTexturaAPantalla(screenSize.Height,textureSize.Height));

            sprite.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize.Height / 2, 0));
        
        }

        public float ajustarTexturaAPantalla(int pantallaParametro, int texturaParametro)
        {   
            //para poder hacer la divicion bien
            float pantalla = pantallaParametro;
            float textura = texturaParametro;
            return (pantalla / textura);
        }

        public TgcBoundingBox BoundinBox()
        {
            return armaMesh.BoundingBox;
        }

        public Vector3 posicionArma()
        {
            Vector3 pos = new Vector3();
            pos = armaMesh.Position;
            return pos;
        }

        public void actualizarPosArma()
        {
            //Hay que poner segun cada arma la distancia a la camara.
            Vector3 camaraPos = camara.getPosition();
            Vector3 mirandoA = camara.getLookAt();
            //armaMesh.Rotation = mirandoA;<commit_msg>Corrijo el sprite del arma<commit_after>﻿using Microsoft.DirectX;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using TgcViewer;
using TgcViewer.Utils._2D;
using TgcViewer.Utils.Input;
using TgcViewer.Utils.TgcGeometry;
using TgcViewer.Utils.TgcSceneLoader;
using TgcViewer.Utils.TgcSkeletalAnimation;

namespace AlumnoEjemplos.MiGrupo
{
    class ArmaManager
    {



        static Size screenSize = GuiController.Instance.Panel3d.Size;
        static string path = GuiController.Instance.AlumnoEjemplosMediaDir;

        private TgcFpsMiCamara camara;

        private SoundManager soundManager;
        private TgcPickingRay pickingRay; //Encargado de chequear si los disparos dieron en el enemigo

        private TgcSprite sprite;
        private TgcMesh armaMesh;

        private EnemigosManager enemigosManager;
        private EscenarioManager escenarioManager;

        private Boolean hayZoom = true;
        private TgcTexture miraZoom  = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\sprites\\zoom.png");
        //private TgcTexture miraSimple  = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\sprites\\05.png");
        private TgcTexture sniper = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\sprites\\SpriteArma5.png");

        public ArmaManager(EnemigosManager enemigosManager, SoundManager soundManager, TgcFpsMiCamara camara, EscenarioManager escenarioManager)
        {
            //this.enemigosManager = enemigosManager;
            this.soundManager = soundManager;
            this.camara = camara;
            this.escenarioManager = escenarioManager;
            this.enemigosManager = enemigosManager;

            pickingRay = new TgcPickingRay();

            //Crear Sprite
            sprite = new TgcSprite();
            hacerZoom(0);
           
            //Cargo el arma
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + EjemploAlumno.nombreGrupo + "\\modelos\\arma\\arma.xml");
            armaMesh = scene.Meshes[0];
            armaMesh.Scale = new Vector3(0.005f, 0.005f, 0.005f);
    
        }


        public void update(float elapsedTime)
        {

            if (GuiController.Instance.D3dInput.keyDown(Microsoft.DirectX.DirectInput.Key.R))
            {
                soundManager.playSonidoRecarga();
            }

            if (GuiController.Instance.D3dInput.buttonDown(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_LEFT) == true)
            {
                manejarDisparo();
            }

            if (GuiController.Instance.D3dInput.buttonDown(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_RIGHT) == true)
            {
                hacerZoom(elapsedTime);
            }


            GuiController.Instance.Drawer2D.beginDrawSprite();
            sprite.render();
            GuiController.Instance.Drawer2D.endDrawSprite();

            if (!hayZoom)
            {
                actualizarPosicionArma();
                //armaMesh.render();
            }
            
        }


        private float timeFromZoom = 100;
        private void hacerZoom(float elapsedTime)
        {
           
            hayZoom = !hayZoom;
            if (hayZoom)
            {
                sprite.Texture = miraZoom;
                //sprite.Scaling = new Vector2(0.7f, 0.38f);
            }
            else
            {
                sprite.Texture = sniper;
                //sprite.Texture = miraSimple;
                //sprite.Scaling = new Vector2(1f, 1f);
            }

            this.camara.hacerZoom();

            //Ubicarlo centrado en la pantalla
            Size screenSize = GuiController.Instance.Panel3d.Size;
            Size textureSize = sprite.Texture.Size;

            sprite.Scaling = new Vector2(ajustarTexturaAPantalla(screenSize.Width,textureSize.Width), ajustarTexturaAPantalla(screenSize.Height,textureSize.Height));

            //sprite.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize.Height / 2, 0));
            sprite.Position = new Vector2(0, 0);

        }

        public float ajustarTexturaAPantalla(int pantallaParametro, int texturaParametro)
        {   
            //para poder hacer la divicion bien
            float pantalla = pantallaParametro;
            float textura = texturaParametro;
            return (pantalla / textura);
        }

        public TgcBoundingBox BoundinBox()
        {
            return armaMesh.BoundingBox;
        }

        public Vector3 posicionArma()
        {
            Vector3 pos = new Vector3();
            pos = armaMesh.Position;
            return pos;
        }

        public void actualizarPosArma()
        {
            //Hay que poner segun cada arma la distancia a la camara.
            Vector3 camaraPos = camara.getPosition();
            Vector3 mirandoA = camara.getLookAt();
            //armaMesh.Rotation = mirandoA;
{'fraction_non_alphanumeric': 0.08253542703944848, 'fraction_numerical': 0.010436614324013788, 'mean_word_length': 2.0747718575213425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1740862', 'n_tokens_mistral': 3146, 'n_tokens_neox': 2967, 'n_words': 551}