/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here base.Initialize(); hpt.Start(); hpt.Stop(); camera = new Camera(Game); camera.CameraArc = -30; camera.CameraDistance = 50; quadRenderer = new QuadRenderComponent(Game); Game.Components.Add(camera); Game.Components.Add(quadRenderer); previousState = Keyboard.GetState(); spotLights = new List <SpotLight>(); { // graph code int n = 300; //GeneratePoints generates a random graph, implementation irrelevant pointList = new VertexPositionColor[n]; int height = 300; int minY = 0; for (int i = 0; i < n; i++) { pointList[i] = new VertexPositionColor() { Position = new Vector3(i * 10, 0, 0), Color = Color.Red } } ; //links the points into a list lineListIndices = new short[(n * 2) - 2]; for (int i = 0; i < n - 1; i++) { lineListIndices[i * 2] = (short)(i); lineListIndices[(i * 2) + 1] = (short)(i + 1); } worldMatrix = Matrix.Identity; viewMatrix = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up); projectionMatrix = Matrix.CreateOrthographicOffCenter(0, (float)GraphicsDevice.Viewport.Width, 0, (float)GraphicsDevice.Viewport.Height, 1.0f, 1000.0f); basicEffect = new BasicEffect(GraphicsDevice); basicEffect.World = worldMatrix; basicEffect.View = viewMatrix; basicEffect.Projection = projectionMatrix; basicEffect.VertexColorEnabled = true; //important for color } SpotLight spot = new SpotLight() { lightPosition = new Vector3(371, 290, -120), lightColor = Color.White, lightRadius = 500, lightIntensity = 2, lightDirection = new Vector3(-371, -290, 120), spotAngle = 15, decay = 1 }; spotLights.Add(spot); spot = new SpotLight() { lightPosition = new Vector3(-120, 290, 371), lightColor = Color.White, lightRadius = 500, lightIntensity = 2, lightDirection = new Vector3(120, -260, -371), spotAngle = 15, decay = 10 }; spotLights.Add(spot); }
/// <summary> /// Allows the game component to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { currentKeyboardState = Keyboard.GetState(); currentMouseState = Mouse.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); // TODO: Add your update code here hpt.Stop(); double milisec = hpt.Duration * 1000; if (playing) { float lerpammount = (float)(milisec - lastPlay); currentEntry = (int)Math.Floor(lerpammount * 0.01); lerpammount = lerpammount - (currentEntry * 100); if ((currentEntry + 1) < camcorder.entries.Count) { Vector2 xy = lerp(camcorder.entries[currentEntry].Item1, camcorder.entries[currentEntry + 1].Item1, lerpammount * 0.01f); xDifference = xy.X; yDifference = xy.Y; cameraPos = Vector3.Lerp(camcorder.entries[currentEntry].Item2, camcorder.entries[currentEntry + 1].Item2, lerpammount * 0.01f); } else { playing = false; } } float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.1f; if (yDifference > 360) { yDifference -= 360; } if (yDifference < 0) { yDifference += 360; } if (xDifference > 360) { xDifference -= 360; } if (xDifference < 0) { xDifference += 360; } float xMult = 1; if (yDifference > 180f) { xMult = -1; } if (yDifference < 0f) { xMult = -1; } if (recording && (milisec - lastRecord) >= 100) { lastRecord = milisec; camcorder.entries.Add(new Tuple <Vector2, Vector3>( new Vector2(xDifference, yDifference), cameraPos)); } cameraView = Matrix.CreateFromYawPitchRoll(MathHelper.ToRadians(90 - xDifference), MathHelper.ToRadians(90 - yDifference), 0); camForward = cameraView.Forward; camCenter = cameraPos + camForward; camUp = cameraView.Up; Matrix.CreateLookAt(ref cameraPos, ref camCenter, ref camUp, out view); if (!playing) { if (currentMouseState != previousMouseState) { if (Game.IsActive) { if (currentMouseState.RightButton == ButtonState.Pressed) { xDifference += xMult * ((currentMouseState.X - previousMouseState.X) * time); yDifference += ((currentMouseState.Y - previousMouseState.Y) * time); Mouse.SetPosition(previousMouseState.X, previousMouseState.Y); } } if (currentMouseState.RightButton == ButtonState.Released) { previousMouseState = currentMouseState; } } //if (currentKeyboardState.IsKeyDown(Keys.Up)) // yDifference -= time; //if (currentKeyboardState.IsKeyDown(Keys.Down)) // yDifference += time; //if (currentKeyboardState.IsKeyDown(Keys.Right)) // xDifference += time; //if (currentKeyboardState.IsKeyDown(Keys.Left)) // xDifference -= time; if (!currentKeyboardState.IsKeyDown(Keys.LeftControl)) { if (currentKeyboardState.IsKeyDown(Keys.W)) { cameraPos += cameraView.Forward * time; } if (currentKeyboardState.IsKeyDown(Keys.S)) { cameraPos -= cameraView.Forward * time; } if (currentKeyboardState.IsKeyDown(Keys.D)) { cameraPos += cameraView.Right * time; } if (currentKeyboardState.IsKeyDown(Keys.A)) { cameraPos -= cameraView.Right * time; } if (currentKeyboardState.IsKeyDown(Keys.E)) { cameraPos.Y += time; } if (currentKeyboardState.IsKeyDown(Keys.Q)) { cameraPos.Y -= time; } if (currentKeyboardState.IsKeyDown(Keys.R)) { cameraPos = new Vector3(179.8928f, 202.3825f, -135.3956f); xDifference = -44.78f; yDifference = 104.37f; } } } if (currentKeyboardState.IsKeyDown(Keys.LeftControl) && currentKeyboardState.IsKeyDown(Keys.S) && previousKeyboardState.IsKeyUp(Keys.S)) { recording = !recording; if (!recording) { camcorder.WritePos(); } else { lastRecord = milisec; camcorder.entries.Clear(); } } if (currentKeyboardState.IsKeyDown(Keys.LeftControl) && currentKeyboardState.IsKeyDown(Keys.L) && previousKeyboardState.IsKeyUp(Keys.L)) { if (!playing) { camcorder.entries.Clear(); camcorder.Read(); if (camcorder.entries.Count > 0) { xDifference = camcorder.entries[0].Item1.X; yDifference = camcorder.entries[0].Item1.Y; cameraPos = camcorder.entries[0].Item2; } playing = !playing; currentEntry = 0; lastPlay = milisec; DeferredLighting.DeferredRenderer.drinstance.frameCount = 0; DeferredLighting.DeferredRenderer.drinstance.framesTime = 0; } else { playing = !playing; } } if (currentKeyboardState.IsKeyDown(Keys.LeftControl) && currentKeyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z)) { camcorder.WriteLights(); } float aspectRatio = (float)Game.Window.ClientBounds.Width / (float)Game.Window.ClientBounds.Height; projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, nearPlaneDistance, farPlaneDistance); previousKeyboardState = currentKeyboardState; base.Update(gameTime); }