public FPSCameraController(Camera camera, GraphicsDevice device) { this.camera = camera; this.device = device; // Calculate heading and pitch from camera's current position and target Vector3 delta = camera.Target - camera.Position; this.heading = (float)Math.Atan2(delta.Z, delta.X); this.pitch = (float)Math.Atan2(delta.Y, Math.Sqrt(delta.X * delta.X + delta.Z * delta.Z)); }
protected override void Initialize() { camera = new Camera(); base.Initialize(); }
protected override void Initialize() { content = new ContentManager(Services, "Content"); // Load all trees in the Content/Trees folder string[] files = Directory.GetFiles("Content/Trees", "*.xnb", SearchOption.TopDirectoryOnly); foreach (string filename in files) { string assetName = filename.Substring("Content/".Length, filename.Length - "Content/.xnb".Length); Profiles.Add(content.Load<TreeProfile>(assetName)); ProfileNames.Add(Path.GetFileName(assetName)); } profileIndex = 0; // Create the wind animator wind = new WindStrengthSin(); animator = new TreeWindAnimator(wind); // Create the ground plane and an effect for it groundPlane = new Quad(GraphicsDevice, 10000, 10000); groundEffect = new BasicEffect(GraphicsDevice, new EffectPool()); groundEffect.Texture = content.Load<Texture2D>("Textures/Grass"); groundEffect.TextureEnabled = true; // Create a camera Camera = new Camera(); Camera.Position = new Vector3(4000, 4000, 4000); Camera.Target = new Vector3(0, 2000, 0); Camera.AspectRatio = GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height; CameraOrbitAngle = 0.0f; CameraPitchAngle = -10.0f; CameraDistance = 5000.0f; // Enable mipmaps GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Linear; // Store the initial renderstate block = new StateBlock(GraphicsDevice); block.Capture(); Initialized = true; UpdateTree(); Application.Idle += new EventHandler(Application_Idle); }