public override void UpdateView() { if (effect != null) { FreeLook freelook = Demo.Freelook; effect.View = Matrix.CreateLookAt(MathHelper.Convert(freelook.Eye), MathHelper.Convert(freelook.Target), MathHelper.Convert(freelook.Up)); effect.View *= Matrix.CreateScale(-1, 1, 1); } }
protected override void Initialize() { basicEffect = new BasicEffect(GraphicsDevice); basicEffect.TextureEnabled = true; basicEffect.VertexColorEnabled = true; basicEffect.View = XNAMatrix.CreateLookAt( orgCameraPosition, XNAVector3.Zero, XNAVector3.Up ); basicEffect.Projection = XNAMatrix.CreatePerspectiveFieldOfView( XNAMathHelper.ToRadians(45.0f), (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height, 1.0f, 10000.0f ); basicEffect.Texture = null; dummyTexture = XNATexture.Load(GraphicsDevice, "./dummyTexture.png"); }
void UpdateCamera(Matrix transform) { float ox = transform.OffsetX; float oy = transform.OffsetY; float scale = transform.Elements.ElementAt(0); Console.WriteLine(string.Format("({0}, {1}), {2}", ox, oy, scale)); if (scale <= 0) { return; } XNAVector3 zoomCamPos = orgCameraPosition; zoomCamPos.Z /= scale; var zoomView = XNAMatrix.CreateLookAt( zoomCamPos, XNAVector3.Zero, XNAVector3.Up ); XNAVector3 offset = new XNAVector3(ox, oy, 0); XNAVector3 p0 = Unproject(XNAVector3.Zero, basicEffect.Projection, zoomView, XNAMatrix.Identity, zoomCamPos); XNAVector3 p1 = Unproject(offset, basicEffect.Projection, zoomView, XNAMatrix.Identity, zoomCamPos); cameraPosition = p0 - p1; cameraPosition.Z = zoomCamPos.Z; XNAVector3 targetPos = cameraPosition; targetPos.Z = 0; basicEffect.View = XNAMatrix.CreateLookAt( cameraPosition, targetPos, XNAVector3.Up ); }
/// <summary> /// Calculates the <see cref="ViewMatrix"/> by creating a look-at Matrix. /// </summary> /// <returns>A <see cref="Microsoft.Xna.Framework.Matrix"/> representing the View matrix of the CameraComponent.</returns> internal Matrix CalculateViewMatrix() { var forward = Vector3.Transform(Vector3.Forward, RotationQuaternion); var up = Vector3.Transform(Vector3.Up, RotationQuaternion); if (IsInitialized) { if (Target == null) { forward = WorldPosition + forward; } else { forward = Target.Position; } } return(Matrix.CreateLookAt( WorldPosition.MonoGameVector, forward.MonoGameVector, up.MonoGameVector )); }
public static Matrix CreateLookAt(Vector3 pos, Vector3 target, Vector3 up) { return(new Matrix(Matrix4x4.CreateLookAt(pos, target, up))); }