public void Update(TgcD3dInput Input)
        {
            efecto.SetValue("_Time", GameModel.time);
            efecto.SetValue("alturaEnY", GameLogic.cantidadZombiesMuertos * 10);

            #region chequeoDeColision

            //Si hacen clic con el mouse, ver si hay colision RayAABB
            if (Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
            {
                pickingRay.updateRay();

                //Testear Ray contra el AABB de todos los meshes
                foreach (var unaPlataforma in plataformas)//.Where(p => !p.ocupado).ToList())
                {
                    var aabb = unaPlataforma.mesh.BoundingBox;

                    //Ejecutar test, si devuelve true se carga el punto de colision collisionPoint
                    selected = TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, aabb, out collisionPoint);
                    if (selected)
                    {
                        plataformaSeleccionada = unaPlataforma;
                        unaPlataforma.mesh.BoundingBox.setRenderColor(Color.LightBlue);
                        break;
                    }
                }
            }
            #endregion
        }
        public void Update(TgcD3dInput Input)
        {
            #region chequeoDeColision

            //Si hacen clic con el mouse, ver si hay colision RayAABB
            if (Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
            {
                pickingRay.updateRay();

                //Testear Ray contra el AABB de todos los meshes
                foreach (var unItem in items)//.Where(p => !p.ocupado).ToList())
                {
                    var aabb = unItem.mesh.BoundingBox;

                    //Ejecutar test, si devuelve true se carga el punto de colision collisionPoint
                    selected = TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, aabb, out collisionPoint);
                    if (selected)
                    {
                        itemSeleccionado = unItem;
                        unItem.mesh.BoundingBox.setRenderColor(Color.LightBlue);
                        itemSeleccionado.manejarEvento();
                        break;
                    }
                }
            }
            #endregion
        }
Exemple #3
0
        /// <summary>
        /// Manejar eventos de Input
        /// </summary>
        private void handleInput()
        {
            TgcD3dInput input = GuiController.Instance.D3dInput;

            //Seleccionar modelo
            if (currentState == GuiState.SelectionMode)
            {
                //Picking con mouse Izquierdo
                if (input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    findSelectedMeshWithPicking();
                }
            }
            //Trasladar modelo seleccionado
            else if (currentState == GuiState.TranslateMode)
            {
                if (selectedMeshList.Count > 0)
                {
                    //Comenzar a trasladar
                    if (input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                    {
                        initGizmoDragging();
                    }
                    //Arrastrando gizmo
                    else if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                    {
                        doGizmoTranslate();
                    }
                    //Terminar el traslado
                    else if (input.buttonUp(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                    {
                        endGizmoDragging();
                    }
                }
            }
        }
        public void Update()
        {
            if (Invisible)
            {
                return;
            }

            if (FastUtils.IsNumberBetweenInterval(Input.Xpos, (Position.X, Position.X + Size.X)) &&
                FastUtils.IsNumberBetweenInterval(Input.Ypos, (Position.Y, Position.Y + Size.Y)))
            {
                IsMarked = true;
                if (Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    Action();
                }
            }
        public void Update(Ray ray, TgcMesh shark, float elapsedTime)
        {
            var speed        = Constants.MOVEMENT_SPEED;
            var director     = Camera.Direction.ToBulletVector3();
            var sideRotation = Camera.Latitude - prevLatitude;
            var sideDirector = TGCVector3.TransformCoordinate(Constants.PLANE_DIRECTOR, TGCMatrix.RotationY(sideRotation)).ToBulletVector3();

            Body.ActivationState = ActivationState.ActiveTag;
            Body.AngularVelocity = Vector3.Zero;

            if (IsOutOfWater)
            {
                Body.LinearVelocity = Vector3.Zero;
                Body.ApplyCentralImpulse(Vector3.UnitY * -100);
            }
            else if (IsInsideShip)
            {
                Movement(director, sideDirector, speed);
            }
            else
            {
                OutsideMovement(director, sideDirector, speed);
            }

            if (Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT) && HasWeapon && InHand)
            {
                Weapon.ActivateAtackMove();
                SoundManager.WeaponHit.play();
                AttackedShark = ray.IntersectsWithObject(shark.BoundingBox, 150);
                if (AttackedShark)
                {
                    SoundManager.HitToShark.play();
                }
            }

            RestartSpeedForKeyUp();

            Body.LinearVelocity += TGCVector3.Up.ToBulletVector3() * Gravity;
            Camera.Position      = new TGCVector3(Body.CenterOfMassPosition) + Constants.CAMERA_HEIGHT;

            if (InHand)
            {
                Weapon.Update(new TGCVector3(director), elapsedTime);
            }
        }
Exemple #6
0
        public override void Update(float deltaTime, TgcD3dInput input)
        {
            //si el mouse pasa por encima del boton:
            //si quieren usarlo solo como texto, no lo updateen y listo
            if (input.Xpos >= getBounds().X&&
                input.Xpos <= getBounds().X + getBounds().Width&&

                input.Ypos >= getBounds().Y&&
                input.Ypos <= getBounds().Y + getBounds().Height)
            {
                texto.Color = Color.Red;
                if (input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    accion();
                }
            }
            else
            {
                texto.Color = Color.White;
            }
        }
Exemple #7
0
        public override void update()
        {
            TgcD3dInput input = GuiController.Instance.D3dInput;

            switch (currentState)
            {
            case State.Init:

                selectedAxis = Axis.None;

                //Iniciar seleccion de eje
                if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    Control.PickingRay.updateRay();
                    Vector3 collP;

                    //Buscar colision con eje con Picking
                    if (TgcCollisionUtils.intersectRayAABB(Control.PickingRay.Ray, boxX.BoundingBox, out collP))
                    {
                        selectedAxis = Axis.X;
                    }
                    else if (TgcCollisionUtils.intersectRayAABB(Control.PickingRay.Ray, boxY.BoundingBox, out collP))
                    {
                        selectedAxis = Axis.Y;
                    }
                    else if (TgcCollisionUtils.intersectRayAABB(Control.PickingRay.Ray, boxZ.BoundingBox, out collP))
                    {
                        selectedAxis = Axis.Z;
                    }
                    else
                    {
                        selectedAxis = Axis.None;
                    }

                    //Si eligio un eje, iniciar dragging
                    if (selectedAxis != Axis.None)
                    {
                        currentState = State.Dragging;
                        initMouseP   = new Vector2(input.XposRelative, input.YposRelative);
                    }
                    else
                    {
                        if (input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                        {
                            bool additive = input.keyDown(Microsoft.DirectX.DirectInput.Key.LeftControl) || input.keyDown(Microsoft.DirectX.DirectInput.Key.RightControl);
                            Control.CurrentState = MeshCreatorControl.State.SelectObject;
                            Control.SelectionRectangle.doDirectSelection(additive);
                        }
                    }
                }
                //Hacer mouse over sobre los ejes
                else
                {
                    Control.PickingRay.updateRay();
                    Vector3 collP;

                    //Buscar colision con eje con Picking
                    if (TgcCollisionUtils.intersectRayAABB(Control.PickingRay.Ray, boxX.BoundingBox, out collP))
                    {
                        selectedAxis = Axis.X;
                    }
                    else if (TgcCollisionUtils.intersectRayAABB(Control.PickingRay.Ray, boxY.BoundingBox, out collP))
                    {
                        selectedAxis = Axis.Y;
                    }
                    else if (TgcCollisionUtils.intersectRayAABB(Control.PickingRay.Ray, boxZ.BoundingBox, out collP))
                    {
                        selectedAxis = Axis.Z;
                    }
                    else
                    {
                        selectedAxis = Axis.None;
                    }
                }

                break;

            case State.Dragging:

                //Mover
                if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    //Obtener vector 2D de movimiento relativo del mouse
                    Vector2 mouseScreenVec = new Vector2(input.XposRelative, input.YposRelative);
                    //mouseScreenVec.Normalize();

                    //Projectar vector 2D del eje elegido
                    TgcBox  currentAxisBox = getAxisBox(selectedAxis);
                    Vector2 axisScreenVec  = MeshCreatorUtils.projectAABBScreenVec(currentAxisBox.BoundingBox);

                    //Hacer DOT product entre ambos vectores para obtener la contribucion del mouse en esa direccion
                    float scaling = Vector2.Dot(axisScreenVec, mouseScreenVec);
                    scaling = MeshCreatorUtils.getMouseScaleIncrementSpeed(Control.Camera, currentAxisBox.BoundingBox, scaling);
                    Vector3 currentScale = new Vector3(0, 0, 0);

                    //Escala en eje X
                    if (selectedAxis == Axis.X)
                    {
                        currentScale.X = scaling;
                    }
                    //Escala en eje Y
                    else if (selectedAxis == Axis.Y)
                    {
                        currentScale.Y = scaling;
                    }
                    //Escala en eje Z
                    else if (selectedAxis == Axis.Z)
                    {
                        currentScale.Z = scaling;
                    }


                    //Escalar objetos
                    foreach (EditorPrimitive p in Control.SelectionList)
                    {
                        //Agregar scaling, controlando que no sea menor a cero
                        Vector3 scale  = p.Scale;
                        Vector3 oldMin = p.BoundingBox.PMin;

                        scale  += currentScale;
                        scale.X = scale.X < 0.01f ? 0.01f : scale.X;
                        scale.Y = scale.Y < 0.01f ? 0.01f : scale.Y;
                        scale.Z = scale.Z < 0.01f ? 0.01f : scale.Z;

                        p.Scale = scale;

                        //Si se escala para una sola direccion hay que desplazar el objeto
                        if (!Control.ScaleBothDirections)
                        {
                            p.move(oldMin - p.BoundingBox.PMin);
                        }
                    }

                    //TODO: Hay que ir estirando los ejes a medida que se agranda la escala

                    //Actualizar datos de modify
                    Control.updateModifyPanel();
                }

                //Soltar movimiento
                else if (input.buttonUp(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    currentState = State.Init;
                    selectedAxis = Axis.None;
                }


                break;
            }



            //Ajustar tamaño de ejes
            setAxisPositionAndSize();
        }
Exemple #8
0
        public void render(float elapsedTime)
        {
            TgcD3dInput d3dInput = GuiController.Instance.D3dInput;
            //Calcular proxima posicion de personaje segun Input
            float moveForward = 0f;
            float moveSide    = 0f;
            float rotateY     = 0;
            //float rotateX = 0;
            float jump      = 0;
            bool  moving    = false;
            bool  rotating  = false;
            bool  rotatingY = false;
            // bool rotatingX = false;
            bool   running         = false;
            bool   jumping         = false;
            string animationAction = "StandBy";

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

            mira.Enabled = false;

            TgcText2d hitCantTextY = new TgcText2d();

            hitCantTextY.Position = new Point(0, 0);
            hitCantTextY.Color    = Color.White;

            /*  TgcText2d hitCantTextX = new TgcText2d();
             * hitCantTextX.Position = new Point(0, 20);
             * hitCantTextX.Color = Color.White;
             */
            if (destroy)
            {
                goto Rendering;
            }

            //obtener velocidades de Modifiers
            float velocidadCaminar  = (float)GuiController.Instance.Modifiers["VelocidadCaminar"];
            float velocidadRotacion = (float)GuiController.Instance.Modifiers.getValue("VelocidadRotacion");

            //Detonar
            if (this.canExplode && d3dInput.keyDown(Key.K))
            {
                animationAction = "Talk";
                this.explosion.detonar();
                destroy = true;
            }

            //Adelante
            if (d3dInput.keyDown(Key.W))
            {
                if (!moving)
                {
                    moveForward = -velocidadCaminar;
                }
                else
                {
                    moveForward = -velocidadCaminar / 2;
                }
                moving = true;
            }


            //Atras
            if (d3dInput.keyDown(Key.S))
            {
                if (!moving)
                {
                    moveForward = velocidadCaminar;
                }
                else
                {
                    moveForward = velocidadCaminar / 2;
                }
                moving = true;
            }

            //Derecha
            if (d3dInput.XposRelative > 0 || d3dInput.keyDown(Key.RightArrow))
            {
                if (d3dInput.XposRelative > 0)
                {
                    rotateY = (velocidadRotacion / 2);
                }
                else
                {
                    rotateY = velocidadRotacion;
                }

                rotating  = true;
                rotatingY = true;
            }

            //Izquierda
            if (d3dInput.XposRelative < 0 || d3dInput.keyDown(Key.LeftArrow))
            {
                if (d3dInput.XposRelative < 0)
                {
                    rotateY = -(velocidadRotacion / 2);
                }
                else
                {
                    rotateY = -velocidadRotacion;
                }

                rotating  = true;
                rotatingY = true;
            }

            //Mover Derecha
            if (d3dInput.keyDown(Key.D))
            {
                if (!moving)
                {
                    moveSide = -velocidadCaminar;
                }
                else
                {
                    moveSide = -velocidadCaminar / 2;
                }
                moving = true;
            }


            //Mover Izquierda
            if (d3dInput.keyDown(Key.A))
            {
                if (!moving)
                {
                    moveSide = velocidadCaminar;
                }
                else
                {
                    moveSide = velocidadCaminar / 2;
                }
                moving = true;
            }

/*            //Arriba
 *          if (d3dInput.YposRelative < 0)
 *          {
 *              //if (camara.RotationX > -(Math.PI / 3))
 *              //{
 *                  rotateX = -velocidadRotacion;
 *                  rotating = true;
 *                  rotatingX = true;
 *              //}
 *          }
 *
 *          //Abajo
 *          if (d3dInput.YposRelative > 0)
 *          {
 *              //if (camara.RotationX < (Math.PI / 3))
 *              //{
 *                  rotateX = velocidadRotacion;
 *                  rotating = true;
 *                  rotatingX = true;
 *              //}
 *          }
 */
            //Jump

            /*if (d3dInput.keyDown(Key.Space))
             * {
             *  jump = 30;
             *  moving = true;
             * }*/

            //Run
            if (d3dInput.keyDown(Key.LeftShift))
            {
                running      = true;
                moveForward *= 1.5f;
            }

            if (d3dInput.keyDown(Key.E) || d3dInput.buttonDown(TgcD3dInput.MouseButtons.BUTTON_RIGHT))
            {
                mira.Enabled    = true;
                animationAction = "WeaponPos";
                if (d3dInput.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    this.fire();
                }
            }

            //Si hubo rotacion
            if (rotating)
            {
                if (rotatingY)
                {
                    //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware

                    float rotAngleY = Geometry.DegreeToRadian(rotateY * elapsedTime);
                    this.personaje.rotateY(rotAngleY);
                    this.camara.rotateY(rotAngleY);
                }

                /*  if (rotatingX)
                 * {
                 *  //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware
                 *  float rotAngleX = Geometry.DegreeToRadian(rotateX * elapsedTime);
                 *  this.camara.rotateX(rotAngleX);
                 *
                 * }*/
            }


            //Si hubo desplazamiento
            if (moving)
            {
                //Activar animacion de caminando
                if (running)
                {
                    this.personaje.playAnimation("Run", true);
                }
                else if (jumping)
                {
                    this.personaje.playAnimation("Jump", true);
                }
                else
                {
                    this.personaje.playAnimation("Walk", true);
                }
            }

            //Si no se esta moviendo, activar animationAction
            else
            {
                this.personaje.playAnimation(animationAction, true);
            }

            if (life <= 0)
            {
                this.personaje.playAnimation("Muerte", true);
            }


            //Vector de movimiento
            Vector3 movementVector = Vector3.Empty;

            if (moving)
            {
                //Aplicar movimiento, desplazarse en base a la rotacion actual del personaje
                //Grupo Kamikaze3D :: Se agrega también al desplazamiento sobre el eje x y eje z, el valor de desplazamiento lateral
                movementVector = new Vector3(
                    (FastMath.Sin(this.personaje.Rotation.Y) * moveForward) + (FastMath.Cos(this.personaje.Rotation.Y) * moveSide),
                    jump,
                    (FastMath.Cos(this.personaje.Rotation.Y) * moveForward) + (-FastMath.Sin(this.personaje.Rotation.Y) * moveSide)
                    );
            }


            //Mover personaje con detección de colisiones, sliding y gravedad
            Vector3 realMovement;

            if (collisionWithCharacters(movementVector))
            {
                realMovement = Vector3.Empty;
            }
            else
            {
                realMovement = collisionManager.moveCharacter(this.characterSphere, movementVector, this.objetosColisionables);
            }
            this.personaje.move(realMovement);

            //Actualizar valores de la linea de movimiento
            this.directionArrow.PStart = characterSphere.Center;
            this.directionArrow.PEnd   = characterSphere.Center + Vector3.Multiply(movementVector, 50);
            this.directionArrow.updateValues();

            //Caargar desplazamiento realizar en UserVar
            GuiController.Instance.UserVars.setValue("Movement", TgcParserUtils.printVector3(realMovement));

Rendering:

            //Render linea
            if (renderDirectionArrow)
            {
                this.directionArrow.render();
            }

            this.renderBullets();
            //Render personaje
            this.personaje.animateAndRender();

            //Iniciar dibujado de todos los Sprites de la escena (en este caso es solo uno)
            GuiController.Instance.Drawer2D.beginDrawSprite();

            //Dibujar sprite (si hubiese mas, deberian ir todos aquí)
            mira.render();

            //Finalizar el dibujado de Sprites
            GuiController.Instance.Drawer2D.endDrawSprite();

            //hitCantTextY.Text = "Y: " + camara.RotationY;
            //hitCantTextX.Text = "X: " + camara.RotationX;
            //hitCantTextY.render();
            //hitCantTextX.render();
        }
Exemple #9
0
        public override void update()
        {
            TgcD3dInput input = GuiController.Instance.D3dInput;

            switch (currentState)
            {
            case State.Init:

                acumMovement = Vector3.Empty;
                gizmoMesh.unSelect();

                //Iniciar seleccion de eje
                if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    //Buscar colision con ejes del gizmo
                    Control.PickingRay.updateRay();
                    gizmoMesh.selectAxisByPicking(Control.PickingRay.Ray);
                    if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.X)
                    {
                        initMouseP3d = Control.Grid.getPickingX(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                    }
                    else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.Y)
                    {
                        initMouseP3d = Control.Grid.getPickingY(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                    }
                    else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.Z)
                    {
                        initMouseP3d = Control.Grid.getPickingZ(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                    }
                    else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.XZ)
                    {
                        initMouseP3d = Control.Grid.getPickingXZ(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                    }
                    else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.XY)
                    {
                        initMouseP3d = Control.Grid.getPickingXY(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                    }
                    else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.YZ)
                    {
                        initMouseP3d = Control.Grid.getPickingYZ(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                    }

                    //Si eligio un eje, iniciar dragging
                    if (gizmoMesh.SelectedAxis != TranslateGizmoMesh.Axis.None)
                    {
                        currentState = State.Dragging;
                    }
                    else
                    {
                        if (input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                        {
                            bool additive = input.keyDown(Microsoft.DirectX.DirectInput.Key.LeftControl) || input.keyDown(Microsoft.DirectX.DirectInput.Key.RightControl);
                            Control.CurrentState = MeshCreatorControl.State.SelectObject;
                            Control.SelectionRectangle.doDirectSelection(additive);
                        }
                    }
                }
                //Hacer mouse over sobre los ejes
                else
                {
                    //Buscar colision con eje con Picking
                    Control.PickingRay.updateRay();
                    gizmoMesh.selectAxisByPicking(Control.PickingRay.Ray);
                }

                break;

            case State.Dragging:

                //Mover
                if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    Control.PickingRay.updateRay();
                    Vector3 endMouseP3d = initMouseP3d;

                    //Solo se mueve un eje
                    Vector3 currentMove = new Vector3(0, 0, 0);
                    if (gizmoMesh.isSingleAxis(gizmoMesh.SelectedAxis))
                    {
                        //Desplazamiento en eje X
                        if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.X)
                        {
                            endMouseP3d   = Control.Grid.getPickingX(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                            currentMove.X = endMouseP3d.X - initMouseP3d.X;
                        }
                        //Desplazamiento en eje Y
                        else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.Y)
                        {
                            endMouseP3d   = Control.Grid.getPickingY(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                            currentMove.Y = endMouseP3d.Y - initMouseP3d.Y;
                        }
                        //Desplazamiento en eje Z
                        else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.Z)
                        {
                            endMouseP3d   = Control.Grid.getPickingZ(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                            currentMove.Z = endMouseP3d.Z - initMouseP3d.Z;
                        }
                    }
                    //Desplazamiento en dos ejes
                    else
                    {
                        //Plano XZ
                        if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.XZ)
                        {
                            endMouseP3d   = Control.Grid.getPickingXZ(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                            currentMove.X = endMouseP3d.X - initMouseP3d.X;
                            currentMove.Z = endMouseP3d.Z - initMouseP3d.Z;
                        }
                        //Plano XY
                        else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.XY)
                        {
                            endMouseP3d   = Control.Grid.getPickingXY(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                            currentMove.X = endMouseP3d.X - initMouseP3d.X;
                            currentMove.Y = endMouseP3d.Y - initMouseP3d.Y;
                        }
                        //Plano YZ
                        else if (gizmoMesh.SelectedAxis == TranslateGizmoMesh.Axis.YZ)
                        {
                            endMouseP3d   = Control.Grid.getPickingYZ(Control.PickingRay.Ray, gizmoMesh.GizmoCenter);
                            currentMove.Y = endMouseP3d.Y - initMouseP3d.Y;
                            currentMove.Z = endMouseP3d.Z - initMouseP3d.Z;
                        }
                    }

                    //Actualizar pos del mouse 3D para proximo cuadro
                    initMouseP3d = endMouseP3d;

                    //Ajustar currentMove con Snap to grid
                    if (Control.SnapToGridEnabled)
                    {
                        snapMovementToGrid(ref currentMove.X, ref acumMovement.X, Control.SnapToGridCellSize);
                        snapMovementToGrid(ref currentMove.Y, ref acumMovement.Y, Control.SnapToGridCellSize);
                        snapMovementToGrid(ref currentMove.Z, ref acumMovement.Z, Control.SnapToGridCellSize);
                    }

                    //Mover objetos
                    foreach (EditorPrimitive p in Control.SelectionList)
                    {
                        p.move(currentMove);
                    }

                    //Mover ejes
                    gizmoMesh.moveGizmo(currentMove);

                    //Actualizar datos de modify
                    Control.updateModifyPanel();
                }

                //Soltar movimiento
                else if (input.buttonUp(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    currentState = State.Init;
                    gizmoMesh.unSelect();
                }


                break;
            }



            //Ajustar tamaño de ejes
            gizmoMesh.setCenter(gizmoMesh.GizmoCenter, Control.Camera);
        }
Exemple #10
0
        /// <summary>
        /// Construir caja
        /// </summary>
        public override void doCreation()
        {
            TgcD3dInput input = GuiController.Instance.D3dInput;

            switch (currentCreatingState)
            {
            case CreatingBoxState.DraggingSize:

                //Si hacen clic con el mouse, ver si hay colision con el suelo
                if (input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    //Determinar el size en XZ del box
                    Vector3 collisionPoint = Control.Grid.getPicking();

                    //Obtener extremos del rectángulo de selección
                    Vector3 min = Vector3.Minimize(initSelectionPoint, collisionPoint);
                    Vector3 max = Vector3.Maximize(initSelectionPoint, collisionPoint);
                    min.Y = initSelectionPoint.Y;
                    max.Y = initSelectionPoint.Y + 0.2f;

                    //Configurar BOX
                    mesh.setExtremes(min, max);
                    mesh.updateValues();
                }
                //Solto el clic del mouse, pasar a configurar el Height del box
                else if (input.buttonUp(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    //Tiene el tamaño minimo tolerado
                    Vector3 size = mesh.BoundingBox.calculateSize();
                    if (size.X > 1 && size.Z > 1)
                    {
                        currentCreatingState  = CreatingBoxState.DraggingHeight;
                        creatingBoxInitMouseY = input.Ypos;
                    }
                    //Sino, descartar
                    else
                    {
                        Control.CurrentState = MeshCreatorControl.State.CreatePrimitiveSelected;
                        mesh.dispose();
                        mesh = null;
                    }
                }

                break;

            case CreatingBoxState.DraggingHeight:

                //Si presiona clic, terminar de configurar la altura y generar box definitivo
                if (input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))
                {
                    //Guardar size original del Box para hacer Scaling
                    originalSize = mesh.BoundingBox.calculateSize();

                    //Dejar cargado para que se pueda crear un nuevo box
                    Control.CurrentState      = MeshCreatorControl.State.CreatePrimitiveSelected;
                    Control.CreatingPrimitive = new BoxPrimitive(Control);

                    //Agregar box a la lista de modelos
                    Control.addMesh(this);

                    //Seleccionar Box
                    Control.SelectionRectangle.clearSelection();
                    Control.SelectionRectangle.selectObject(this);
                    Control.updateModifyPanel();
                }
                //Determinar altura en base a la posicion Y del mouse
                else
                {
                    float heightY         = creatingBoxInitMouseY - input.Ypos;
                    float adjustedHeightY = MeshCreatorUtils.getMouseIncrementHeightSpeed(Control.Camera, this.BoundingBox, heightY);

                    Vector3 min = mesh.BoundingBox.PMin;
                    min.Y = initSelectionPoint.Y;
                    Vector3 max = mesh.BoundingBox.PMax;
                    max.Y = initSelectionPoint.Y + adjustedHeightY;

                    //Configurar BOX
                    mesh.setExtremes(min, max);
                    mesh.updateValues();
                }

                break;
            }
        }