/// <summary> /// Presune hrace na startovani pozici (0,0,0) /// </summary> public static void MoveToStartPosition() { Vector3 pos = new Vector3(-3000, 0, -3000); pos += HeightOfEye; Camera cam = Camera.GetCameraInstance(); Vector3 dir = cam.GetVector3LookAt() - cam.GetVector3Position(); dir.Y = 0; RepairPositionInNonFreeLook(pos, ref pos); //if (freeLook) // pos += new Vector3(0, 1800, 0); cam.SetCameraPositionVector(pos); cam.SetCameraLookAtVector(pos + dir); }
/// <summary> /// Pohne s hracem o jeden krok ve smeru zadaneho uhlu /// </summary> /// <param name="angle">Uhel v radianech urcujici smer pohybu</param> public static void MoveByAngle(float angle) { Camera cam = Camera.GetCameraInstance(); Vector3 lookat = cam.GetVector3LookAt(); Vector3 position = cam.GetVector3Position(); Matrix rotation = Matrix.RotationY(angle); Vector3 dir = lookat - position; if (freeLook) { dir.Normalize(); dir.TransformCoordinate(rotation); dir.Normalize(); if (Math.Abs(angle - Math.PI) < 0.5) { dir.Y = -dir.Y; } else if (Math.Abs(angle - Math.PI / 2f) < 0.5 || Math.Abs(angle - Math.PI / 2f + Math.PI) < 0.5) { dir.Y = 0; } Vector3 newposition = position + (Speed * time) * dir; Vector3 newlookAt = lookat + (Speed * time) * dir; cam.SetCameraLookAtVector(newlookAt); cam.SetCameraPositionVector(newposition); return; } dir.Y = 0; dir.Normalize(); dir.TransformCoordinate(rotation); dir.Normalize(); Vector3 newPosition = position + (Speed * time) * dir; RepairPositionInNonFreeLook(position, ref newPosition); if (position == newPosition) { return; } Vector3 newLookAt = lookat + newPosition - position; cam.SetCameraLookAtVector(newLookAt); cam.SetCameraPositionVector(newPosition); if (player == null) { return; } dir = newLookAt - newPosition; dir.Y = 0; dir.Normalize(); Vector3 playerPosition = newPosition; playerPosition.Y -= HeightOfEye.Y; playerPosition -= HeightOfEye.Z * dir; player.SetPosition(playerPosition); }