public override void UpdateCamera(float elapsedTime) { var moveVector = actualizarMoveVector(); #region actualizarTransformacion //Solo rotar si se esta aprentando el boton izq del mouse if (Input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT)) { leftrightRot -= -Input.XposRelative * RotationSpeed; updownRot -= Input.YposRelative * RotationSpeed; cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot); // cameraRotation = TGCMatrix.RotationY(leftrightRot); } var cameraRotatedPositionEye = TGCVector3.TransformNormal(moveVector * elapsedTime, cameraRotation); positionEye += cameraRotatedPositionEye; //Calculamos el target de la camara, segun su direccion inicial y las rotaciones en screen space x,y. var cameraRotatedTarget = TGCVector3.TransformNormal(directionView, cameraRotation); var cameraFinalTarget = positionEye + cameraRotatedTarget; //Se calcula el nuevo vector de up producido por el movimiento del update. var cameraOriginalUpVector = DEFAULT_UP_VECTOR; var cameraRotatedUpVector = TGCVector3.TransformNormal(cameraOriginalUpVector, cameraRotation); #endregion base.SetCamera(positionEye, cameraFinalTarget, cameraRotatedUpVector); }
private void InitializePlanes() { var baldosas = TgcTexture.createTexture(MediaDir + "Texturas\\baldosasceramica.jpg"); var lisa = TgcTexture.createTexture(MediaDir + "Texturas\\paredLisa.jpg"); List <TgcPlane> planeCollection = new List <TgcPlane> { new TgcPlane(new TGCVector3(-500.0f, 0f, -500.0f), new TGCVector3(1000f, 1f, 1000f), TgcPlane.Orientations.XZplane, baldosas, 10f, 10f), new TgcPlane(new TGCVector3(500.0f, 0f, -500.0f), new TGCVector3(0f, 400f, 1000f), TgcPlane.Orientations.YZplane, lisa, 23.2f, 16.8f), new TgcPlane(new TGCVector3(500.0f, 0f, -500.0f), new TGCVector3(0f, 400f, 1000f), TgcPlane.Orientations.YZplane, lisa, 23.2f, 16.8f), new TgcPlane(new TGCVector3(-500.0f, 0f, -500.0f), new TGCVector3(1000f, 400f, 0f), TgcPlane.Orientations.XYplane, lisa, 23.2f, 16.8f), new TgcPlane(new TGCVector3(-500.0f, 0f, -500.0f), new TGCVector3(1000f, 400f, 0f), TgcPlane.Orientations.XYplane, lisa, 23.2f, 16.8f), }; planeCollection.ForEach(plane => plane.updateValues()); int index = 0; planes = planeCollection.ConvertAll(plane => { index++; return(plane.toMesh("plane" + index.ToString())); }); // Orient the planes to the center of the scene planes[0].Transform = TGCMatrix.RotationX(FastMath.PI) * planes[0].Transform; planes[1].Transform = TGCMatrix.RotationY(FastMath.PI) * planes[1].Transform; planes[3].Transform = TGCMatrix.RotationY(FastMath.PI) * planes[3].Transform; planes.ForEach(plane => { plane.Effect = effect; plane.Technique = "Wall"; }); planes[0].Technique = "Blinn"; }
private void Rotation() { Latitude -= -Input.XposRelative * Constants.ROTATION_SPEED; Longitude -= Input.YposRelative * Constants.ROTATION_SPEED; Longitude = FastMath.Clamp(Longitude, Constants.LIMIT_MIN, Constants.LIIMIT_MAX); CameraRotation = TGCMatrix.RotationX(Longitude) * TGCMatrix.RotationY(Latitude); }
/// <summary> /// Crear una nueva camara /// </summary> public MamutCamara(TgcD3dInput input) { this.Input = input; this.directionView = new TGCVector3(0, 0, 75); this.RotationSpeed = 1f; this.leftrightRot = FastMath.PI_HALF; this.updownRot = -FastMath.PI / 10.0f; this.cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot); resetValues(); }
public TGCMatrix CalculateCameraRotation() { if (ConsideringInput) { leftrightRot += Input.XposRelative * RotationSpeed; updownRot = FastMath.Clamp(updownRot - Input.YposRelative * RotationSpeed, -FastMath.PI_HALF, FastMath.PI_HALF); } return(TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot)); }
/// <summary> /// Genera la proxima matriz de view, sin actualizar aun los valores internos /// </summary> /// <param name="pos">Futura posicion de camara generada</param> /// <param name="targetCenter">Futuro centro de camara a generada</param> public void CalculatePositionTarget(float rotX, float rotY) { //alejarse, luego rotar y lueg ubicar camara en el centro deseado var m = TGCMatrix.Translation(0, OffsetHeight, OffsetForward) * TGCMatrix.RotationX(rotX) * TGCMatrix.RotationY(rotY) * TGCMatrix.Translation(Target); //Extraer la posicion final de la matriz de transformacion NextPos = new TGCVector3(m.M41, m.M42, m.M43); }
/// <summary> /// Realiza un update de la camara a partir del elapsedTime, actualizando Position,LookAt y UpVector. /// Presenta movimientos basicos a partir de input de teclado W, A, S, D, Espacio, Control y rotraciones con el mouse. /// </summary> /// <param name="elapsedTime"></param> public override void UpdateCamera(float elapsedTime) { var moveVector = TGCVector3.Empty; if (Input.keyPressed(Key.Escape)) { LockCam = !lockCam; //habiaSalido = true; } if ((Input.buttonPressed(TgcD3dInput.MouseButtons.BUTTON_LEFT))) { LockCam = !lockCam; //habiaSalido = false; } if (lockCam) { leftrightRot -= -Input.XposRelative * RotationSpeed; updownRot -= Input.YposRelative * RotationSpeed; if (updownRot > 1.5) { updownRot = 1.5f; } if (updownRot < -1.5) { updownRot = -1.5f; } //Se actualiza matrix de rotacion, para no hacer este calculo cada vez y solo cuando en verdad es necesario. cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot); } if (lockCam) { Cursor.Position = mouseCenter; } //Calculamos la nueva posicion del ojo segun la rotacion actual de la camara. var cameraRotatedPositionEye = TGCVector3.TransformNormal(moveVector * elapsedTime, cameraRotation); positionEye += cameraRotatedPositionEye; //Calculamos el target de la camara, segun su direccion inicial y las rotaciones en screen space x,y. var cameraRotatedTarget = TGCVector3.TransformNormal(directionView, cameraRotation); var cameraFinalTarget = positionEye + cameraRotatedTarget; //Se calcula el nuevo vector de up producido por el movimiento del update. var cameraOriginalUpVector = DEFAULT_UP_VECTOR; var cameraRotatedUpVector = TGCVector3.TransformNormal(cameraOriginalUpVector, cameraRotation); base.SetCamera(positionEye, cameraFinalTarget, cameraRotatedUpVector); }
public void Render(TGCMatrix matrizAuto, Luz luz) { Mesh.Effect.SetValue("lightColor", TGCVector3.TGCVector3ToFloat3Array(new TGCVector3(luz.Color.R, luz.Color.G, luz.Color.B))); Mesh.Effect.SetValue("lightPosition", TGCVector3.TGCVector3ToFloat3Array(luz.Translation)); Mesh.Effect.SetValue("Ka", .65f); Mesh.Effect.SetValue("Kd", .3f); Mesh.Effect.SetValue("Ks", 0); Mesh.Effect.SetValue("shininess", 0); Mesh.Effect.SetValue("reflection", 0); mesh.Transform = TGCMatrix.Scaling(new TGCVector3(scale)) * TGCMatrix.RotationX(rotacion) * TGCMatrix.Translation(new TGCVector3(translation)) * matrizAuto; mesh.Render(); }
public void Move(TgcMesh mesh, float movimiento) { moved++; if (moved <= movingRange) { director = new TGCVector3(0, 0, -movimiento); } else { director = new TGCVector3(0, 0, movimiento); } //mesh.Transform = TGCMatrix.Translation(director*100); //mesh.Move(director); var orbitaDeRotacion = 2.5f; //Muevo las plataformas var Mover = TGCMatrix.Translation(0, 0, -10); var Mover2 = TGCMatrix.Translation(0, 0, 65); //Punto por donde va a rotar var Trasladar = TGCMatrix.Translation(0, 0, 10); var Trasladar2 = TGCMatrix.Translation(0, 0, -10); //Aplico la rotacion var Rot = TGCMatrix.RotationX(orbitaDeRotacion); //Giro para que la caja quede derecha var RotInversa = TGCMatrix.RotationX(-orbitaDeRotacion); var transformacionBox = Mover * Trasladar * Rot * Trasladar * RotInversa; //transformacionBox2 = Mover2 * Trasladar2 * RotInversa * Trasladar2 * Rot; mesh.Transform = transformacionBox; mesh.UpdateMeshTransform(); //plataforma1.Update(transformacionBox); //plataforma2.Update(transformacionBox2); if (moved == movingRange * 2) { moved = 0; } }
/// <summary> /// Constructor de la camara a partir de un TgcD3dInput el cual ya tiene por default el positionEye (0,0,0), el mouseCenter a partir del centro del a pantalla, RotationSpeed 1.0f, /// MovementSpeed y JumpSpeed 500f, el directionView (0,0,-1) /// </summary> /// <param name="input"></param> public CamaraExploradora(TgcD3dInput input) { this.Input = input; this.positionEye = TGCVector3.Empty; this.mouseCenter = new Point(D3DDevice.Instance.Device.Viewport.Width / 2, D3DDevice.Instance.Device.Viewport.Height / 2); this.RotationSpeed = 0.1f; this.MovementSpeed = 500f; this.JumpSpeed = 500f; this.directionView = new TGCVector3(0, 0, -1); this.leftrightRot = FastMath.PI_HALF; this.updownRot = -FastMath.PI / 10.0f; this.cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot); }
private void InitializeFloor() { var floor = TgcTexture.createTexture(MediaDir + "Texturas\\tierra.jpg"); var planeSize = new TGCVector3(200f, 0f, 200f); var planeMesh = new TgcPlane(TGCVector3.Scale(planeSize, -0.5f), planeSize, TgcPlane.Orientations.XZplane, floor, 5f, 5f); planeMesh.updateValues(); plane = planeMesh.toMesh("floor"); plane.Transform = TGCMatrix.RotationX(FastMath.PI) * plane.Transform; plane.Effect = effect; plane.Technique = "Blinn"; }
/// <summary> /// Constructor de la camara a partir de un TgcD3dInput el cual ya tiene por default el eyePosition (0,0,0), el mouseCenter a partir del centro del a pantalla, RotationSpeed 1.0f, /// MovementSpeed y JumpSpeed 500f, el directionView (0,0,-1) /// </summary> public Camera() { cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot); down = new TgcRay(); horx = new TgcRay(); horz = new TgcRay(); down.Direction = new TGCVector3(0, -1, 0); horx.Direction = new TGCVector3(1, 0, 0); horz.Direction = new TGCVector3(0, 0, 1); g.camera = this; g.hands = new Hands(); }
public CamaraPersonal(TgcD3dInput input) { #region inicializarVariables this.Input = input; this.positionEye = TGCVector3.Empty; this.mouseCenter = new Point(D3DDevice.Instance.Device.Viewport.Width / 2, D3DDevice.Instance.Device.Viewport.Height / 2); this.RotationSpeed = 0.1f; this.MovementSpeed = 500f; this.JumpSpeed = 500f; this.directionView = new TGCVector3(0, 0, -1); // this.directionView = new TGCVector3(0.8f, -0.8f, -1); this.leftrightRot = FastMath.PI_HALF; this.updownRot = -FastMath.PI / 10.0f; this.cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot);///*TGCMatrix.RotationX(updownRot) **/ TGCMatrix.RotationY(leftrightRot); #endregion }
public override void Init() { drawer2D = new Drawer2D(); //Crear Sprite sprite = new CustomSprite(); sprite.Bitmap = new CustomBitmap(MediaDir + "\\Texturas\\LogoTGC.png", D3DDevice.Instance.Device); //Ubicarlo centrado en la pantalla var textureSize = sprite.Bitmap.Size; sprite.Position = new TGCVector2(FastMath.Max(D3DDevice.Instance.Width / 2 - textureSize.Width / 2, 0), FastMath.Max(D3DDevice.Instance.Height / 2 - textureSize.Height / 2, 0)); //Crear Sprite animado animatedSprite = new AnimatedSprite(MediaDir + "\\Texturas\\Sprites\\Explosion.png", //Textura de 256x256 new Size(64, 64), //TamaƱo de un frame (64x64px en este caso) 16, //Cantidad de frames, (son 16 de 64x64px) 10); //Velocidad de animacion, en cuadros x segundo, //Ubicarlo centrado en la pantalla var textureSizeAnimado = animatedSprite.Bitmap.Size; animatedSprite.Position = new TGCVector2(D3DDevice.Instance.Width / 2 - textureSizeAnimado.Width / 2, D3DDevice.Instance.Height / 2 - textureSizeAnimado.Height / 2); //Modifiers para variar parametros del sprite positionModifier = AddVertex2f("position", TGCVector2.Zero, new TGCVector2(D3DDevice.Instance.Width, D3DDevice.Instance.Height), sprite.Position); scalingModifier = AddVertex2f("scaling", TGCVector2.Zero, new TGCVector2(4, 4), sprite.Scaling); rotationModifier = AddFloat("rotation", 0, 360, 0); //Modifiers para variar parametros del sprite frameRateAnimatedModifier = AddFloat("frameRateAnimated", 1, 30, 10); positionAnimatedModifier = AddVertex2f("positionAnimated", TGCVector2.Zero, new TGCVector2(D3DDevice.Instance.Width, D3DDevice.Instance.Height), animatedSprite.Position); scalingAnimatedModifier = AddVertex2f("scalingAnimated", TGCVector2.Zero, new TGCVector2(4, 4), animatedSprite.Scaling); rotationAnimatedModifier = AddFloat("rotationAnimated", 0, 360, 0); //Creamos un Box3D para que se vea como el Sprite es en 2D y se dibuja siempre arriba de la escena 3D box = TGCBox.fromSize(new TGCVector3(10, 10, 10), TgcTexture.createTexture(MediaDir + "\\Texturas\\pasto.jpg")); box.Transform = TGCMatrix.RotationX(FastMath.QUARTER_PI); //Hacer que la camara se centre en el box3D Camara = new TgcRotationalCamera(box.BoundingBox.calculateBoxCenter(), box.BoundingBox.calculateBoxRadius() * 2, Input); }
public override void Update() { PreUpdate(); // Los movimientos de teclado no validan que la mesh se atraviecen, solo modifican el angulo o traslacion. if (Input.keyDown(Key.W)) { ang += VELOCIDAD_ANGULAR * ElapsedTime; } else if (Input.keyDown(Key.S)) { ang -= VELOCIDAD_ANGULAR * ElapsedTime; } if (Input.keyDown(Key.A)) { pos += 5f * ElapsedTime; } else if (Input.keyDown(Key.D)) { pos -= 5f * ElapsedTime; } angHelice += ElapsedTime * VELOCIDAD_ANGULAR; escalaAvion = TGCMatrix.Scaling(lengthAvion); escalaHelice = TGCMatrix.Scaling(lengthHelice); var T1 = TGCMatrix.Translation(pos, pos, 0); var R1 = TGCMatrix.RotationZ(ang); transformacionAvion = R1 * T1; var T2 = TGCMatrix.Translation(lengthAvion.X / 2 + lengthHelice.X / 2, 0, 0); var R3 = TGCMatrix.RotationX(angHelice); transformacionHelice = R3 * T2 * transformacionAvion; PostUpdate(); }
private void UpdatePlayerLookDirection() { TgcD3dInput input = player.GameInstance.Input; // MOVER LOOK DIRECTION CON MOVIMIENTO DEL MOUSE if (player.GameInstance.FocusInGame) { mousePositionY -= -input.XposRelative * mouseSensibility; // ENTENDER PORQUE TENGO QUE INVERTIR LAS X CON Y if (mousePositionX >= 0) // Para que no se haga gimball lock en la camara, limito el maximo que se puede llegar hasta arriba y abajo { mousePositionX = FastMath.Min(mousePositionX - input.YposRelative * mouseSensibility, maxUpDownView); } else { mousePositionX = FastMath.Max(mousePositionX - input.YposRelative * mouseSensibility, -maxUpDownView); } } TGCMatrix cameraRotationMatrix = TGCMatrix.RotationX(mousePositionX) * TGCMatrix.RotationY(mousePositionY); player.LookDirection = TGCVector3.TransformNormal(player.InitialLookDirection, cameraRotationMatrix); }
public override void Update() { //Muevo las plataformas var Mover = TGCMatrix.Translation(0, 0, -15); var Mover2 = TGCMatrix.Translation(0, 0, 65); //Punto por donde va a rotar var Trasladar = TGCMatrix.Translation(0, 0, 10); var Trasladar2 = TGCMatrix.Translation(0, 0, -10); //Aplico la rotacion var Rot = TGCMatrix.RotationX(orbitaDeRotacion); //Giro para que la caja quede derecha var RotInversa = TGCMatrix.RotationX(-orbitaDeRotacion); transformacionBox = Mover * Trasladar * Rot * Trasladar * RotInversa; transformacionBox2 = Mover2 * Trasladar2 * RotInversa * Trasladar2 * Rot; plataforma1.Update(); plataforma1.transformacion = transformacionBox; plataforma1.Movete(); plataforma2.Update(); plataforma2.transformacion = transformacionBox2; plataforma2.Movete(); base.Update(); //foreach (Caja caja in cajas) //{ // Console.WriteLine(String.Format("CAJAS : ", caja.ToString())); //} }
private void InvertNormals(TGCVector3 vector) { TGCVector3 p = mesh.BoundingBox.calculateBoxCenter(); if (vector.X > 0) { mesh.Transform = TGCMatrix.Translation(-p); mesh.Transform = mesh.Transform * TGCMatrix.RotationY(FastMath.ToRad(180)); mesh.Transform = mesh.Transform * TGCMatrix.Translation(p); } else if (vector.Y > 0) { mesh.Transform = TGCMatrix.Translation(-p); mesh.Transform = mesh.Transform * TGCMatrix.RotationX(FastMath.ToRad(180)); mesh.Transform = mesh.Transform * TGCMatrix.Translation(p); } else if (vector.Z < 0) { mesh.Transform = TGCMatrix.Translation(-p); mesh.Transform = mesh.Transform * TGCMatrix.RotationY(FastMath.ToRad(180)); mesh.Transform = mesh.Transform * TGCMatrix.Translation(p); } }
/// <summary> /// Rota la rueda sobre si misma /// </summary> public void RotateX(float velocidad) { this.rotationX = TGCMatrix.RotationX(velocidad * 0.01f) * this.rotationX; }
/// <summary> /// Actualiza los valores de la camara. /// </summary> public override void UpdateCamera(float elapsedTime) { //Obtener variacion XY del mouse var mouseX = 0f; var mouseY = 0f; if (Input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT)) { mouseX = Input.XposRelative; mouseY = Input.YposRelative; DiffX += mouseX * elapsedTime * RotationSpeed; DiffY += mouseY * elapsedTime * RotationSpeed; } else { DiffX += mouseX; DiffY += mouseY; } //Calcular rotacion a aplicar var rotX = -DiffY / FastMath.PI; var rotY = DiffX / FastMath.PI; //Truncar valores de rotacion fuera de rango if (rotX > FastMath.PI * 2 || rotX < -FastMath.PI * 2) { DiffY = 0; rotX = 0; } //Invertir Y de UpVector segun el angulo de rotacion if (rotX < -FastMath.PI / 2 && rotX > -FastMath.PI * 3 / 2) { UpVector = DEFAULT_DOWN; } else if (rotX > FastMath.PI / 2 && rotX < FastMath.PI * 3 / 2) { UpVector = DEFAULT_DOWN; } else { UpVector = DEFAULT_UP_VECTOR; } //Determinar distancia de la camara o zoom segun el Mouse Wheel if (Input.WheelPos != 0) { DiffZ += ZoomFactor * Input.WheelPos * -1; } var distance = -CameraDistance * DiffZ; //Limitar el zoom a 0 if (distance > 0) { distance = 0; } //Realizar Transformacion: primero alejarse en Z, despues rotar en X e Y y despues ir al centro de la cmara var m = TGCMatrix.Translation(0, 0, -distance) * TGCMatrix.RotationX(rotX) * TGCMatrix.RotationY(rotY) * TGCMatrix.Translation(CameraCenter); //Extraer la posicion final de la matriz de transformacion NextPos = new TGCVector3(m.M41, m.M42, m.M43); //Hacer efecto de Pan View if (Input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_RIGHT)) { var dx = -Input.XposRelative; var dy = Input.YposRelative; var panSpeedZoom = PanSpeed * FastMath.Abs(distance); var d = CameraCenter - NextPos; d.Normalize(); var n = TGCVector3.Cross(d, UpVector); n.Normalize(); var up = TGCVector3.Cross(n, d); var desf = TGCVector3.Scale(up, dy * panSpeedZoom) - TGCVector3.Scale(n, dx * panSpeedZoom); NextPos = NextPos + desf; CameraCenter = CameraCenter + desf; } //asigna las posiciones de la camara. base.SetCamera(NextPos, CameraCenter, UpVector); }
/// <summary> /// Realiza un update de la camara a partir del elapsedTime, actualizando Position,LookAt y UpVector. /// Presenta movimientos basicos a partir de input de teclado W, A, S, D, Espacio, Control y rotraciones con el mouse. /// </summary> /// <param name="elapsedTime"></param> public override void UpdateCamera(float elapsedTime) { var moveVector = TGCVector3.Empty; //Forward if (Input.keyDown(Key.W)) { moveVector += new TGCVector3(0, 0, -1) * MovementSpeed; } //Backward if (Input.keyDown(Key.S)) { moveVector += new TGCVector3(0, 0, 1) * MovementSpeed; } //Strafe right if (Input.keyDown(Key.D)) { moveVector += new TGCVector3(-1, 0, 0) * MovementSpeed; } //Strafe left if (Input.keyDown(Key.A)) { moveVector += new TGCVector3(1, 0, 0) * MovementSpeed; } //Jump if (Input.keyDown(Key.Space)) { moveVector += TGCVector3.Up * JumpSpeed; } //Crouch if (Input.keyDown(Key.LeftControl)) { moveVector += TGCVector3.Down * JumpSpeed; } if (Input.keyPressed(Key.L) || Input.keyPressed(Key.Escape)) { LockCam = !lockCam; } //Solo rotar si se esta aprentando el boton izq del mouse if (lockCam || Input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_LEFT)) { leftrightRot -= -Input.XposRelative * RotationSpeed; updownRot -= Input.YposRelative * RotationSpeed; //Se actualiza matrix de rotacion, para no hacer este calculo cada vez y solo cuando en verdad es necesario. cameraRotation = TGCMatrix.RotationX(updownRot) * TGCMatrix.RotationY(leftrightRot); } if (lockCam) { Cursor.Position = mouseCenter; } //Calculamos la nueva posicion del ojo segun la rotacion actual de la camara. var cameraRotatedPositionEye = TGCVector3.TransformNormal(moveVector * elapsedTime, cameraRotation); positionEye += cameraRotatedPositionEye; //Calculamos el target de la camara, segun su direccion inicial y las rotaciones en screen space x,y. var cameraRotatedTarget = TGCVector3.TransformNormal(directionView, cameraRotation); var cameraFinalTarget = positionEye + cameraRotatedTarget; //Se calcula el nuevo vector de up producido por el movimiento del update. var cameraOriginalUpVector = DEFAULT_UP_VECTOR; var cameraRotatedUpVector = TGCVector3.TransformNormal(cameraOriginalUpVector, cameraRotation); base.SetCamera(positionEye, cameraFinalTarget, cameraRotatedUpVector); }
/// <summary> /// Actualiza los valores de la camara /// </summary> public void updateCamera(float elapsedTime) { if (!Enable) { return; } //Obtener variacion XY del mouse var mouseX = 0f; var mouseY = 0f; if (Input.keyDown(Key.LeftAlt) && Input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_MIDDLE)) { mouseX = Input.XposRelative; mouseY = Input.YposRelative; diffX += mouseX * elapsedTime * RotationSpeed; diffY += mouseY * elapsedTime * RotationSpeed; } else { diffX += mouseX; diffY += mouseY; } //Calcular rotacion a aplicar var rotX = -diffY / FastMath.PI + BaseRotX; var rotY = diffX / FastMath.PI + BaseRotY; //Truncar valores de rotacion fuera de rango if (rotX > FastMath.PI * 2 || rotX < -FastMath.PI * 2) { diffY = 0; rotX = 0; } //Invertir Y de UpVector segun el angulo de rotacion if (rotX < -FastMath.PI / 2 && rotX > -FastMath.PI * 3 / 2) { upVector.Y = -1; } else if (rotX > FastMath.PI / 2 && rotX < FastMath.PI * 3 / 2) { upVector.Y = -1; } else { upVector.Y = 1; } //Determinar distancia de la camara o zoom segun el Mouse Wheel if (Input.WheelPos != 0) { diffZ += ZoomFactor * Input.WheelPos * -1; } var distance = -CameraDistance * diffZ; //Limitar el zoom a 0 if (distance > 0) { distance = 0; } //Realizar Transformacion: primero alejarse en Z, despues rotar en X e Y y despues ir al centro de la cmara var m = TGCMatrix.Translation(0, 0, -distance) * TGCMatrix.RotationX(rotX) * TGCMatrix.RotationY(rotY) * TGCMatrix.Translation(CameraCenter); //Extraer la posicion final de la matriz de transformacion nextPos.X = m.M41; nextPos.Y = m.M42; nextPos.Z = m.M43; //Hacer efecto de Pan View if (!Input.keyDown(Key.LeftAlt) && Input.buttonDown(TgcD3dInput.MouseButtons.BUTTON_MIDDLE)) { var dx = -Input.XposRelative; var dy = Input.YposRelative; var panSpeedZoom = PanSpeed * FastMath.Abs(distance); var d = CameraCenter - nextPos; d.Normalize(); var n = TGCVector3.Cross(d, upVector); n.Normalize(); var up = TGCVector3.Cross(n, d); var desf = TGCVector3.Scale(up, dy * panSpeedZoom) - TGCVector3.Scale(n, dx * panSpeedZoom); nextPos = nextPos + desf; CameraCenter = CameraCenter + desf; } //Obtener ViewTGCMatrix haciendo un LookAt desde la posicion final anterior al centro de la camara viewTGCMatrix = TGCMatrix.LookAtLH(nextPos, CameraCenter, upVector); }