public PositionTrigger(CurveRasterization curve, int index, bool preventReverse, bool keepProgress) : base(curve) { this.triggerPointIndex = index; this.preventReverse = preventReverse; this.keepProgress = keepProgress; }
public override void Initialize() { checkpointRasterization = raceTrack.GetCurveRasterization(checkpoints); List<AbstractTrigger> checkpointTriggers = new List<AbstractTrigger>(); for (int i = 0; i < checkpoints; i++) { PositionTrigger trigger = new PositionTrigger(checkpointRasterization, i, true, true); string outputDebug = "Passing checkpoint " + i; trigger.Triggered += (sender, e) => { Console.WriteLine(outputDebug); var now = DateTime.Now; if (lastCheckpointPass != DateTime.MinValue) gameInstance.GetService<HUDComponent>().ShowTextNotification(Color.BurlyWood, (now - lastCheckpointPass).ToString(@"m\:ss\:ff")); lastCheckpointPass = now; var current = states[CurrentState]; var aTrigger = sender as AbstractTrigger; if (e.Object == car && current.Triggers.ContainsKey(aTrigger)) current.Triggers[aTrigger] = e; AudioEngineManager.PlaySound("passfinishline"); }; string checkpointID = "checkpoint" + i; gameInstance.GetService<TriggerManager>().Triggers.Add(checkpointID, trigger); checkpointTriggers.Add(trigger); addedTriggers.Add(checkpointID); } // Keep track of times when passing goal line var goalTrigger = checkpointTriggers[0]; goalTrigger.Triggered += (sender, e) => { goalLineTimes.Add(e.Time.TotalGameTime); var player = gameInstance.GetService<Player>(); string notification = (++player.Lap) > laps ? "Race finished!" : "Lap " + (player.Lap); gameInstance.GetService<HUDComponent>().ShowTextNotification(Color.Teal, notification); }; for (int i = 0; i < laps; i++) { List<AbstractTrigger> lapTriggers = new List<AbstractTrigger>(); lapTriggers.AddRange(checkpointTriggers); states.Add(new GameModeState(lapTriggers)); } // Add state for passing the finish line states.Add(new GameModeState(checkpointTriggers.GetRange(index: 0, count: 1))); }
public SimpleRaceMode(GameManager gameInstance, int laps, int noOfCheckpoints, RaceTrack raceTrack, Car localCar) : base(gameInstance) { this.laps = laps; this.checkpoints = noOfCheckpoints; this.raceTrack = raceTrack; this.car = localCar; this.placementRasterization = raceTrack.GetCurveRasterization(100); PlayerPlace = 1; GameStarted = false; TotalRaceTime = TimeSpan.Zero; var player = gameInstance.GetService<Player>(); player.Lap = 0; players.Add(player); Initialize(); }
private bool IsInFrontOf(Vector3 position, CurveRasterization.CurvePoint point) { var relativePosition = Vector3.Normalize(position - point.Position); return Vector3.Dot(relativePosition, point.Heading) > 0; }
protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Overlay component, used to draw the pause menu and game over menu overlayComponent = new OverlayComponent(Game, spriteBatch); Game.Components.Add(overlayComponent); projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 50000); directionalLight = new DirectionalLight( new Vector3(-1.25f, -2f, 5.0f), // Direction new Vector3(.1f, .1f, .1f),//new Vector3(.15f, .14f, .29f), // Ambient new Vector3(.46f, .33f, .75f)); // Diffuse Game.AddService(typeof(DirectionalLight), directionalLight); #region Level terrain generation int heightMapSize = terrainSegmentsCount * terrainSegmentSize + 1; float halfHeightMapSize = heightMapSize / 2f; HeightMap heightmapGenerator = new HeightMap(heightMapSize); var heightMap = heightmapGenerator.Generate(); var roadMap = new float[heightMapSize, heightMapSize]; raceTrack = new RaceTrack(heightMapSize, terrainScale); navMesh = new NavMesh(GraphicsDevice, raceTrack.Curve, //1500, roadWidth, terrainScale); 750, roadWidth, terrainScale); Vector3 lastPosition = raceTrack.Curve.GetPoint(.01f) / terrainScale; for (float t = 0; t < 1; t += .0002f) { var e = raceTrack.Curve.GetPoint(t) / terrainScale; for (float j = -roadFalloff; j <= roadFalloff; j++) { var pos = e + j * Vector3.Normalize(Vector3.Cross(lastPosition - e, Vector3.Up)); // Indices int x = (int)(pos.X + halfHeightMapSize), z = (int)(pos.Z + halfHeightMapSize); float height = e.Y; if (Math.Abs(j) <= roadWidth) { heightMap[x, z] = height; roadMap[x, z] = 1; } else { float amount = (Math.Abs(j) - roadWidth) / (roadFalloff - roadWidth); heightMap[x, z] = MathHelper.Lerp(height, heightMap[x, z], amount); roadMap[x, z] = amount / 10f; } } lastPosition = e; } heightmapGenerator.Smoothen(); heightmapGenerator.Perturb(30f); for (int i = 0; i < 5; i++) { heightmapGenerator.Smoothen(); } terrainEffect = content.Load<Effect>(@"Effects\TerrainShading"); //terrainEffect.Parameters["TextureMap0"].SetValue(content.Load<Texture2D>(@"Terrain\sand")); #region TEXTURE RENDERING //var unprocessedGrassTexture = content.Load<Texture2D>(@"Terrain\grass"); //var grassTexture = new RenderTarget2D(GraphicsDevice, unprocessedGrassTexture.Width, unprocessedGrassTexture.Height); //GraphicsDevice.SetRenderTarget(grassTexture); //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); //spriteBatch.Draw(unprocessedGrassTexture, new Rectangle(0, 0, unprocessedGrassTexture.Width, unprocessedGrassTexture.Height), Color.White); //spriteBatch.Draw(content.Load<Texture2D>(@"Particles\fire"), new Rectangle(0, 0, unprocessedGrassTexture.Width, unprocessedGrassTexture.Height), Color.White); //spriteBatch.End(); //GraphicsDevice.SetRenderTarget(null); //terrainEffect.Parameters["TextureMap1"].SetValue(grassTexture); #endregion terrainEffect.Parameters["TextureMap0"].SetValue(content.Load<Texture2D>(@"Terrain\road")); terrainEffect.Parameters["TextureMap1"].SetValue(content.Load<Texture2D>(@"Terrain\grass")); terrainEffect.Parameters["TextureMap2"].SetValue(content.Load<Texture2D>(@"Terrain\rock")); terrainEffect.Parameters["TextureMap3"].SetValue(content.Load<Texture2D>(@"Terrain\snow")); terrainEffect.Parameters["RoadNormalMap"].SetValue(content.Load<Texture2D>(@"Terrain\road_n")); terrainEffect.Parameters["Projection"].SetValue(projectionMatrix); // Creates a terrainmodel around Vector3.Zero terrainSegments = new TerrainModel[terrainSegmentsCount, terrainSegmentsCount]; float terrainStart = -.5f * heightMapSize; for (int z = 0; z < terrainSegmentsCount; z++) { for (int x = 0; x < terrainSegmentsCount; x++) { terrainSegments[x, z] = new TerrainModel(GraphicsDevice, terrainSegmentSize, terrainSegmentsCount, terrainStart, x * terrainSegmentSize, z * terrainSegmentSize, terrainScale, heightMap, roadMap, terrainEffect, directionalLight); } } #endregion #region Car Car = MakeCar(); gameInstance.AddService(typeof(Car), Car); Player localPlayer = gameInstance.GetService<ServerClient>().LocalPlayer; gameInstance.GetService<CarControlComponent>().Cars[localPlayer] = Car; gameInstance.AddService(typeof(Player), localPlayer); #endregion #region Lights // Load model to represent our lightsources var pointLightModel = content.Load<Model>(@"Models\light"); //spotLightModel = content.Load<Model>(@"Models\Cone"); Vector3 pointLightOffset = new Vector3(0, 250, 0); var cr = new CurveRasterization(raceTrack.Curve, 50); float colorOffset = 0f; foreach (var point in cr.Points) { Random r = UniversalRandom.GetInstance(); Vector3 color = new Vector3(0f,0f,0f); PointLight pl = new PointLight(point.Position + pointLightOffset + Vector3.Transform(50 * Vector3.Up, Matrix.CreateRotationZ(MathHelper.TwoPi * (float)UniversalRandom.GetInstance().NextDouble())), color, 450) { Model = pointLightModel, ColorTimeOffset = colorOffset }; pointLights.Add(pl); GraphicalObjects.Add(pl); colorOffset += 100 / cr.Points.Count; } #endregion dustEmitter = new ParticleEmitter(dustSystem, 150, Car.Position); #region SkySphere skyBoxModel = content.Load<Model>(@"Models/skybox"); skyBoxEffect = content.Load<Effect>(@"Effects/SkyBox"); skyMap = new TextureCube(GraphicsDevice, 2048, false, SurfaceFormat.Color); string[] cubemapfaces = { @"SkyBoxes/PurpleSky/skybox_right1", @"SkyBoxes/PurpleSky/skybox_left2", @"SkyBoxes/PurpleSky/skybox_top3", @"SkyBoxes/PurpleSky/skybox_bottom4", @"SkyBoxes/PurpleSky/skybox_front5", @"SkyBoxes/PurpleSky/skybox_back6_2" }; //cubeMap = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color); //string[] cubemapfaces = { // @"SkyBoxes/StormyDays/stormydays_ft", // @"SkyBoxes/StormyDays/stormydays_bk", // @"SkyBoxes/StormyDays/stormydays_up", // @"SkyBoxes/StormyDays/stormydays_dn", // @"SkyBoxes/StormyDays/stormydays_rt", // @"SkyBoxes/StormyDays/stormydays_lf" //}; //cubeMap = new TextureCube(GraphicsDevice, 1024, false, SurfaceFormat.Color); //string[] cubemapfaces = { // @"SkyBoxes/Miramar/miramar_ft", // @"SkyBoxes/Miramar/miramar_bk", // @"SkyBoxes/Miramar/miramar_up", // @"SkyBoxes/Miramar/miramar_dn", // @"SkyBoxes/Miramar/miramar_rt", // @"SkyBoxes/Miramar/miramar_lf" //}; for (int i = 0; i < cubemapfaces.Length; i++) LoadCubemapFace(skyMap, cubemapfaces[i], (CubeMapFace)i); skyBoxEffect.Parameters["SkyboxTexture"].SetValue(skyMap); foreach (var mesh in skyBoxModel.Meshes) foreach (var part in mesh.MeshParts) part.Effect = skyBoxEffect; #endregion #region Weather thunderBoltGenerator = new ThunderBoltGenerator(gameInstance, thunderParticleSystem); gameInstance.Components.Add(thunderBoltGenerator); #endregion #region GameObjects OakTree.LoadMaterial(content); BirchTree.LoadMaterial(content); Stone.LoadMaterial(content); int numObjects = 75; for (int i = 0; i < numObjects; i++) { var t = navMesh.triangles[UniversalRandom.GetInstance().Next(navMesh.triangles.Length)]; float v = (float)UniversalRandom.GetInstance().NextDouble(); //float u = (float) (UniversalRandom.GetInstance().NextDouble() - 1/2f); //if (u < 0) // u -= .5f; //else // u += 1.5f; float u = 0; if (UniversalRandom.GetInstance().NextDouble() <= .5) u = -.5f - .3f * (float)(-UniversalRandom.GetInstance().NextDouble()); else u = (float)(1.5f + .3f * UniversalRandom.GetInstance().NextDouble()); var pos = (t.vertices[0] + u * t.ab + v * t.ac) / terrainScale; //var treePos = new Vector3(-halfHeightMapSize + (float)UniversalRandom.GetInstance().NextDouble() * (heightMapSize-50), 0, // -halfHeightMapSize + (float)UniversalRandom.GetInstance().NextDouble() * (heightMapSize-50)); float X = pos.X + heightMapSize / 2f, Z = pos.Z +heightMapSize / 2f; float Xlerp = X % 1f, Zlerp = Z % 1f; int x0 = (int)X, z0 = (int)Z, x1 = x0 + 1, z1 = z0 + 1; float height; float k; if (Xlerp + Zlerp > 1) { float h1 = MathHelper.Lerp(heightMap[x0, z1], heightMap[x1, z1], Xlerp); float h2 = MathHelper.Lerp(heightMap[x1, z0], heightMap[x1, z1], Zlerp); k = h2 / h1; height = MathHelper.Lerp(h1, h2, .5f); } else { float h1 = MathHelper.Lerp(heightMap[x0, z0], heightMap[x1, z0], Xlerp), h2 = MathHelper.Lerp(heightMap[x0, z0], heightMap[x0, z1], Zlerp); k = h2 / h1; height = MathHelper.Lerp(h1, h2, .5f); } pos.Y = height - 0.002f; if (k > 1.02 ) continue; GameObject obj; switch(UniversalRandom.GetInstance().Next(0, 3)) { case 0: obj = new OakTree(gameInstance); obj.Scale = 3 + 3 * (float)UniversalRandom.GetInstance().NextDouble(); FireflyCandidates.Add(obj); break; case 1: obj = new BirchTree(gameInstance); obj.Scale = 3 + 3 * (float)UniversalRandom.GetInstance().NextDouble(); FireflyCandidates.Add(obj); break; default: obj = new Stone(gameInstance); obj.Scale = 0.5f + (float)(.25 * UniversalRandom.GetInstance().NextDouble()); break; } obj.Position = terrainScale * pos; obj.Rotation = new Vector3(0, MathHelper.Lerp(0, MathHelper.Pi * 2, (float)UniversalRandom.GetInstance().NextDouble()), 0); GraphicalObjects.Add(obj); ShadowCasterObjects.Add(obj); } for (int i = 0; i < FireflyCandidates.Count; i+=5) { ParticleEmitter emitter = new ParticleEmitter(fireflySystem, 80, FireflyCandidates[i].Position); emitter.Origin = FireflyCandidates[i].Position + Vector3.Up * 500; fireflyEmitter.Add(emitter); } #endregion //foreach (GameObject obj in GraphicalObjects) //{ // pointLights.Add(new PointLight(obj.Position + Vector3.Up * 500, new Vector3(0.7f, 0.7f, 0.7f), 450) // { // Model = pointLightModel // }); //} //GraphicalObjects.AddRange(pointLights); //List<FireObject> list = new List<FireObject>(); //foreach (PointLight p in pointLights) //{ // FireObject obj = new FireObject(gameInstance, content, p.Position, p.Position + Vector3.Up * 10); // list.Add(obj); //} //pointLights.AddRange(list); //GraphicalObjects.AddRange(list); #region Cameras var input = gameInstance.GetService<InputComponent>(); gameInstance.GetService<CameraComponent>().AddCamera(new DebugCamera(new Vector3(-11800, 3000, -8200), input)); Camera c; gameInstance.GetService<CameraComponent>().AddCamera(c = new ThirdPersonCamera(Car, input)); gameInstance.GetService<CameraComponent>().CurrentCamera = c; #endregion #region DynamicEnvironment // TODO: CARMOVE environmentCubeMap = new RenderTargetCube(this.GraphicsDevice, 256, true, SurfaceFormat.Color, DepthFormat.Depth16); Car.EnvironmentMap = skyMap; #endregion #region PostProcess postProcessingComponent = new PostProcessingComponent(Game); Game.Components.Add(postProcessingComponent); postProcessTexture = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, true, SurfaceFormat.Color, DepthFormat.Depth24); #endregion // Adding a prelighingrenderer as a service prelightingRenderer = new PrelightingRenderer(GraphicsDevice, content); Game.AddService(typeof(PrelightingRenderer), prelightingRenderer); #region ShadowMapEffect shadowMapEffect = content.Load<Effect>(@"Effects\ShadowMap"); #endregion #region Gameplay Trigger Manager (with sample) /// <summary> /// Gets the triggermanager /// Add new PositionTrigger /// Hook up to listener => when hit, use the thunderBoltGenerator and spawn a flash /// Adds it to triggers. /// </summary> //var triggerManager = gameInstance.GetService<TriggerManager>(); //int noOfCheckpoints = 10; //for (int i = 0; i < noOfCheckpoints; i++) //{ // var trigger = new PositionTrigger(raceTrack.CurveRasterization, (int)(((float)i / noOfCheckpoints) * raceTrack.CurveRasterization.Points.Count), true, true); // string cp = "Checkpoint " + i; // trigger.Triggered += (sender, e) => // { // Console.WriteLine(cp); // }; // triggerManager.Triggers.Add("checkpoint"+i, trigger); //} #endregion #region Game Mode if (gameInstance.GetService<ServerClient>().connected) { foreach (var player in gameInstance.GetService<ServerClient>().Players.Values) { gameInstance.GetService<CarControlComponent>().AddCar(player, null, this); } var carList = gameInstance.GetService<CarControlComponent>().Cars.OrderBy(pc => pc.Key.ID).Select(pc => pc.Value).ToList(); SetCarsAtStart(carList); } int cp = 6; if (gameModeChoice == GameModeChoice.SimpleRace) this.mode = new SimpleRaceMode(gameInstance, 3, cp, raceTrack, Car); else if (gameModeChoice == GameModeChoice.Multiplayer) this.mode = new MultiplayerRaceMode(gameInstance, 3, cp, raceTrack, Car); else throw new Exception("Stop choosing weird game modes"); gameInstance.AddService(typeof(GameplayMode), mode); #endregion #region Checkpoint lights for (int i=0; i<cp; i++) { var point = raceTrack.GetCurveRasterization(cp).Points[i]; var pl = new CheckpointLight(point.Position + 500 * Vector3.Up) { Model = pointLightModel }; pointLights.Add(pl); GraphicalObjects.Add(pl); #region Fire int halfnumberoffire = 5; for (int o = -halfnumberoffire + 1; o < halfnumberoffire; o++) { Vector3 side = Vector3.Cross(Vector3.Normalize(raceTrack.Curve.GetPoint((i) / (float)cp + .001f) - point.Position), Vector3.Up); var fire = new FireObject(content, fireSystem, fireSmokeSystem, point.Position + side * 100 * o - Vector3.Up * 400 + Vector3.Up * 650 * (float)Math.Cos(o/(float)halfnumberoffire), Vector3.Up * 10); pointLights.Add(fire); GraphicalObjects.Add(fire); } #endregion } #endregion #region BackgroundSound loopSoundManager.AddNewSound("forestambient"); #endregion prelightingRenderer.GameObjects = GraphicalObjects; init = true; }
public override void Update(GameTime gameTime) { this.mode.Update(gameTime, this); if (this.mode.GameOver) gameOverMenu.Enabled = true; InputComponent input = gameInstance.GetService<InputComponent>(); if (input.GetPressed(Input.Exit)) pauseMenu.Enabled = !pauseMenu.Enabled; var hudComponent = Game.GetService<HUDComponent>(); var cameraComponent = Game.GetService<CameraComponent>(); var carControlComponent = Game.GetService<CarControlComponent>(); carControlComponent.Enabled = mode.GameStarted; if (pauseMenu.Enabled || gameOverMenu.Enabled) { if (cameraComponent.Enabled) cameraComponent.Enabled = false; hudComponent.Visible = false; //GameState state = pauseMenu.UpdateState(gameTime); //if (state == GameState.Gameplay) // Paused = false; //else if (state != GameState.PausedGameplay) //{ // // Exit // Game.Exit(); // return; //} } else { if (!cameraComponent.Enabled) cameraComponent.Enabled = true; hudComponent.Visible = true; /*if (input.GetPressed(Input.ChangeController)) { if (input.CurrentController == Controller.Keyboard) { input.CurrentController = Controller.GamePad; Console.WriteLine("CurrentController equals GamePad"); } else { input.CurrentController = Controller.Keyboard; Console.WriteLine("CurrentController equals Keyboard"); } }*/ if (input.GetPressed(Input.Console)) gameInstance.GetService<HUDConsoleComponent>().Toggle(); //Apply changes to car Car.Update(); #region Ray bool onTrack = false; for (int i = 0; i < navMesh.triangles.Length; i++) { var triangle = navMesh.triangles[i]; if (CollisionCheck(triangle)) { lastTriangle = i; onTrack = true; //break; } } if (!onTrack) { // Project car.Pos on lastTriangle. var t = navMesh.triangles[lastTriangle]; float coord = Vector3.Dot(Car.Position - t.vertices[0], t.ac) / t.ac.LengthSquared(); bool trans = false; if (coord < 0) { trans = true; lastTriangle += (lastTriangle % 2 == 0 ? -2 : 2); } else if (coord > 1) { trans = true; lastTriangle += (lastTriangle % 2 == 0 ? 2 : -2); } if (lastTriangle < 0) lastTriangle += navMesh.triangles.Length; if (lastTriangle >= navMesh.triangles.Length) lastTriangle -= navMesh.triangles.Length; if (!trans) { Car.Position = coord * t.ac + t.vertices[0]; } else if (!CollisionCheck(navMesh.triangles[lastTriangle])) { t = navMesh.triangles[lastTriangle]; coord = MathHelper.Clamp(Vector3.Dot(Car.Position - t.vertices[0], t.ac) / t.ac.LengthSquared(), 0, 1); Car.Position = coord * t.ac + t.vertices[0]; Car.Normal = t.normal; Car.Speed *= 0.8f; } } #endregion #region View frustum // Update the view frustum Matrix view = gameInstance.GetService<CameraComponent>().View; viewFrustum = new BoundingFrustum(view * projectionMatrix); #endregion foreach (GameObject obj in GraphicalObjects) { if (obj.BoundingSphere.Intersects(viewFrustum)) obj.Update(gameTime); } } #region Audio // Spawn random audios if (gameTime.TotalGameTime.Milliseconds % 7000 < 10 && UniversalRandom.GetInstance().NextDouble() > 0.5) { AudioEngineManager.PlaySound("randomambient"); } #endregion #region Particle emission // Particles should continue to spawn regardless of the pause state // Rain system for (int x = -4; x < 4; x++) { for (int z = -4; z < 4; z++) { rainSystem.AddParticle(Car.Position + new Vector3( (float)UniversalRandom.GetInstance().NextDouble() * x * 150, 500 * (float)UniversalRandom.GetInstance().NextDouble(), (float)UniversalRandom.GetInstance().NextDouble() * z * 150), new Vector3(-1, -1, -1));//Vector3.Down); } } // Smoke emission on part of track smokeTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (smokeTime > 0.35) { CurveRasterization cr = new CurveRasterization(raceTrack.Curve, 150); for(int i = 25 ; i < 55; i += 3){ smokeSystem.AddParticle(cr.Points[i].Position + new Vector3( (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 1100, 450 * (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()), (float)UniversalRandom.GetInstance().NextDouble() * 1100), Vector3.Down); } smokeTime = 0; } //if (smokeTime > 0.2) //{ // smokeSystem.AddParticle(Car.Position + Car.Heading * 500 + // new Vector3( // (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 500, // 500 * (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()), // (float)UniversalRandom.GetInstance().NextDouble() * 500), // Vector3.Up); // smokeTime = 0; //} foreach (ParticleEmitter emitter in fireflyEmitter) { emitter.Update(gameTime, emitter.Origin + new Vector3( (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 200, (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 200, (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 200)); } if (Car.Speed > 10) { dustEmitter.Update(gameTime, dustEmitter.Origin + new Vector3( (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 40, 0, (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 40)); dustEmitter.Origin = Car.Position; } #endregion #region Countdown Lights // Update all lights to represent the countdown state. Red - Orange - Yellow - Green if (countdownTimeGo.TotalSeconds < 1) { foreach (PointLight light in pointLights) { light.Diffuse = countdownColors[mode.CountDownState].ToVector3(); } if (mode.CountDownState == 3) { countdownTimeGo += gameTime.ElapsedGameTime; } } #endregion //Vector3 originalDiffuse = new Vector3(.46f, .33f, .75f); Vector3 newDiffuse = new Vector3(.65f, .4f, .7f); Vector3 originalDiffuse = new Vector3(.7f, .6f, .8f); //float amount = (float)(Math.Sin(gameTime.TotalGameTime.TotalSeconds * 2) + 1) * 0.5f * 0.4f; float amount = (float)(Math.Sin(gameTime.TotalGameTime.TotalSeconds * 2)); directionalLight.DefaultDiffuse = new Vector3( MathHelper.Lerp(originalDiffuse.X, newDiffuse.X, amount), MathHelper.Lerp(originalDiffuse.Y, newDiffuse.Y, amount), MathHelper.Lerp(originalDiffuse.Z, newDiffuse.Z, amount)); //directionalLight.Direction = Vector3.Transform( // directionalLight.Direction, // Matrix.CreateRotationY( // (float)gameTime.ElapsedGameTime.TotalSeconds)); //Vector3 pointLightOffset = new Vector3(0, 250, 0), rotationAxis = new Vector3(0,-100,0); //int index = 0; //foreach (var point in raceTrack.CurveRasterization.Points) //{ // pointLights[index++].Position = terrainScale * point.Position + pointLightOffset + // Vector3.Transform(rotationAxis, Matrix.CreateFromAxisAngle(point.Heading, 7 * (float)gameTime.TotalGameTime.TotalSeconds)); //} //yellowSystem.AddParticle(new Vector3(-200, 1500, 2000), Vector3.Up); //redSystem.AddParticle(new Vector3(1500, 1500, 2000), Vector3.Up); //plasmaSystem.AddParticle(new Vector3(-200, 1500, 4000), Vector3.Up); //greenSystem.AddParticle(new Vector3(1500, 1500, 4000), Vector3.Up); //airParticles.AddParticle(Car.Position + Car.Forward * (float)UniversalRandom.GetInstance().NextDouble() * 5000 + // new Vector3( // (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()) * 500, // 500 * (-1f + 2 * (float)UniversalRandom.GetInstance().NextDouble()), // (float)UniversalRandom.GetInstance().NextDouble() * 500), // Vector3.Up); base.Update(gameTime); }
public NavMesh(GraphicsDevice device, datx02_rally.GameLogic.Curve curve, int resolution, float width, Vector3 terrainScale) { this.device = device; #region Vertices //vertices = new NavMeshTriangleVertex[2 * resolution]; vertices = new VertexPositionColor[2 * resolution]; { int i = 0; var curveRasterization = new CurveRasterization(curve, resolution).Points; foreach (var point in curveRasterization) { vertices[i++] = new VertexPositionColor(10 * Vector3.Up + point.Position - (terrainScale * width * point.Side), Color.White); vertices[i++] = new VertexPositionColor(10 * Vector3.Up + point.Position + (terrainScale * width * point.Side), Color.White); } } #endregion #region Indicies int[] indices = new int[6 * resolution]; int[] offsets = { 0, 1, 2, 2, 1, 0 }; for (int i = 0; i < indices.Length; i++) { int v = i / 3 + offsets[i % 6]; if (v >= vertices.Length) v -= vertices.Length; indices[i] = v; } #endregion #region Triangles triangles = new NavMeshTriangle[2 * resolution]; for (int i = 0; i < indices.Length; i += 3) { triangles[i / 3] = new NavMeshTriangle(vertices[indices[i]].Position, vertices[indices[i + 1]].Position, vertices[indices[i + 2]].Position); } // Smoothen out normals for (int i = 1; i < triangles.Length; i += 2) { int j = i - 1, c = i - 2, d = j - 2; if (c < 0) { c += triangles.Length; d += triangles.Length; } Vector3 normal = Vector3.Lerp(triangles[i].normal, triangles[j].normal, .5f); Vector3 others = Vector3.Lerp(triangles[c].normal, triangles[d].normal, .5f); normal = Vector3.Lerp(normal, others, .6f); triangles[i].normal = triangles[j].normal = normal; } #endregion #region Buffers indexBuffer = new IndexBuffer(device, typeof(int), indices.Length, BufferUsage.None); indexBuffer.SetData(indices); indexBuffer.SetData(indices, 0, 6); vertexbuffer = new VertexBuffer(device, typeof(VertexPositionColor), vertices.Length, BufferUsage.None); vertexbuffer.SetData(vertices); vertexbuffer.SetData(vertices, 0, 6); #endregion Effect = new BasicEffect(device); }
public AbstractTrigger(CurveRasterization curve) : this() { Curve = curve; }