public void Draw(Matrix[] instanceTransformsPS, Matrix[] instanceTransformsSM, Camera.Camera camera) { //ps.DrawHardwareInstancing(instanceTransformsPS, ((FreeCamera)camera), Position); //smoke.DrawHardwareInstancing(instanceTransformsSM, ((FreeCamera)camera), Position); ps.Draw(camera.View, camera.Projection, camera.Transform.Up, camera.Transform.Right); smoke.Draw(camera.View, camera.Projection, camera.Transform.Up, camera.Transform.Right); }
public void Update(Camera.Camera camera) { timer++; if(timer % 100 == 0) foreach (GroundHitSystem dust in DustParticle) dust.Update(camera); }
public SkyDome(Game game, bool LowSky, Camera.Camera camera, GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; this.camera = camera; this.LowSky = LowSky; this.game = game; Initialize(); }
public void GetData(object[] obj) { foreach (object o in obj) { if (o is QuadTree) terrain = (QuadTree)o; if (o is Camera.Camera) camera = (Camera.Camera)o; } }
public SkyDomeSystem(Game game, Camera.Camera camera, GameTime gameTime, GraphicsDevice graphicsDevice) { this.game = game; this.camera = camera; this.graphicsDevice = graphicsDevice; this.gameTime = gameTime; realTime = false; parameters = new SkyDomeParameters(); quad = new QuadRenderComponent(game); game.Components.Add(quad); fTheta = 0.0f; fPhi = 0.0f; DomeN = 32; GeneratePermTex(); Initialize(); LoadContent(); }
public void CameraView(ref Camera.Camera camera) { float InitialAngleCam = (float)Math.Asin(1f); float CamRotSpeed = 0.05f; // 0.03f float returnSpeed = 0.08f; // 0.05f float error = CamRotSpeed; float returnError = returnSpeed; if (Keyboard.GetState().IsKeyDown(Keys.S)) { if (CamRotKey < MathHelper.Pi && CamRotKey > 0) CamRotKey += CamRotSpeed; else if ((CamRotKey > -MathHelper.Pi && CamRotKey < 0) || (CamRotKey >= MathHelper.Pi + error && CamRotKey <= 3 * MathHelper.PiOver2 + error)) CamRotKey -= CamRotSpeed; else CamRotKey = MathHelper.Pi; } else if (Keyboard.GetState().IsKeyDown(Keys.A)) { if ((CamRotKey <= MathHelper.PiOver2) || (CamRotKey >= MathHelper.Pi && CamRotKey <= 3 * MathHelper.PiOver2) || (CamRotKey <= MathHelper.Pi && CamRotKey > MathHelper.PiOver2 + error)) CamRotKey += CamRotSpeed; } else if (Keyboard.GetState().IsKeyDown(Keys.D)) { if ((CamRotKey <= 0 && CamRotKey >= -MathHelper.PiOver2 + error) || (CamRotKey >= 0 && CamRotKey < MathHelper.PiOver2 + error) || (CamRotKey >= MathHelper.Pi && CamRotKey <= 3 * MathHelper.PiOver2 + error)) CamRotKey -= CamRotSpeed; else if (CamRotKey <= MathHelper.Pi && CamRotKey > MathHelper.PiOver2) { CamRotKey -= CamRotSpeed; if (CamRotKey > MathHelper.PiOver2 - error && CamRotKey < MathHelper.PiOver2 + error) CamRotKey += CamRotSpeed; } } else if (Keyboard.GetState().IsKeyUp(Keys.D) && Keyboard.GetState().IsKeyUp(Keys.A) && Keyboard.GetState().IsKeyUp(Keys.S)) { if (CamRotKey < -returnError || CamRotKey >= 3 * MathHelper.PiOver2 - returnError) CamRotKey += returnSpeed; else if (CamRotKey > returnError) CamRotKey -= returnSpeed; else CamRotKey = 0f; if ((CamRotKey > MathHelper.PiOver2 && CamRotKey < 3 * MathHelper.PiOver2) || CamRotKey < -MathHelper.PiOver2) CamRotKey = 0; } if (CamRotKey >= MathHelper.Pi * 2) CamRotKey = 0; //Up-Down Inerty if (OldSpeed > speed) { RadiusCam += speed * 0.003f; if (RadiusCam >= MaxRadiusCam) RadiusCam = MaxRadiusCam; } else if (OldSpeed < speed) { RadiusCam -= speed * 0.004f; if (RadiusCam <= MinRadiusCam) RadiusCam = MinRadiusCam; } //Fix Up-Down Camera's Inerty if ((speed >= 0) && (speed <= 0.050f) && (OldSpeed >= speed) && (Keyboard.GetState().IsKeyUp(Keys.Up))) { if (RadiusCam < 1 - 0.001f) RadiusCam += 0.001f; else if (RadiusCam > 1 + 0.001f) RadiusCam -= 0.001f; else RadiusCam = 1; } test += 0.01f; CameraRotation.X = models[0].Rotation.Y; //CameraRotation.Z = test; CameraTarget.Y = models[0].Position.Y + 10; CameraTarget.X = models[0].Position.X + (float)Math.Cos(models[0].Rotation.Y - InitialAngleCam - CameraInerty - CamRotKey) * RadiusCam; CameraTarget.Z = models[0].Position.Z + (float)Math.Sin(-models[0].Rotation.Y + InitialAngleCam + CameraInerty + CamRotKey) * RadiusCam; float cameraRot = CameraRotation.X - CameraInerty - CamRotKey; camera = new FreeCamera(CameraTarget, cameraRot, 0, 1, 10000, graphicsDevice); camera.Update(); //camera = new Camera(this, CameraTarget, 0f, CameraRotation.X - CameraInerty, -2.5f, -1.5f, -2f, GraphicsDevice.Viewport.AspectRatio, 0.0002f, 1000f); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(graphicsDevice); // Effect cubeMapEffect = Content.Load<Effect>("Effects//AlphaBlending"); // cubeMapEffect.Parameters["LightDirection"].SetValue(LightDirection); // CubeMapReflectMaterial cubeMat = new CubeMapReflectMaterial(Content.Load<TextureCube>("textures//Skybox//SkyBoxTex")); camera = new FreeCamera(new Vector3(0, 5000, 0), 0, 0, 1f, 100000.0f, graphicsDevice); models.Add(new Models(Content, Content.Load<Model>("models//model1"), new Vector3(0, 0, 0), Vector3.Zero, new Vector3(20), graphicsDevice)); // models.Add(new Models(Content.Load<Model>("models//cone"), new Vector3(0, 0, 0), Vector3.Zero, new Vector3(20), graphicsDevice)); components = new Components(graphicsDevice); #region Terrain //BasicTerrain//heightmap terrain.InitializeTerrin(Qtree, (FreeCamera)camera, terrain, Content.Load<Texture2D>("textures//Terrain//terrain513"), WaterPos, Content, graphicsDevice); terrain.TerrainTextures(Qtree, new Texture2D[] { Content.Load<Texture2D>("textures//Terrain//grass//GrassMap"), Content.Load<Texture2D>("textures//Terrain//rock//RockMap"), Content.Load<Texture2D>("textures//Terrain//sand//SandMap"), Content.Load<Texture2D>("textures//Terrain//snow//SnowMap"), Content.Load<Texture2D>("textures//Terrain//rocks_sand//Rocks_SandMap"), Content.Load<Texture2D>("textures//Terrain//beach_sand//Beach_SandMap") }, new Texture2D[] { Content.Load<Texture2D>("textures//Terrain//grass//grass"), Content.Load<Texture2D>("textures//Terrain//rock//rock"), Content.Load<Texture2D>("textures//Terrain//sand//sand"), Content.Load<Texture2D>("textures//Terrain//snow//snow"), Content.Load<Texture2D>("textures//Terrain//rocks_sand//rocks_sand"), Content.Load<Texture2D>("textures//Terrain//beach_sand//beach_sand") }, new int[] { 1000, 100, 100, 1000, 1000, 500 }, Content); #endregion #region Sky //Sky sky = new SkyDome(game, false, camera, graphicsDevice); sky.GetData(new object[] { Qtree }); #endregion UpdateLight(); #region BillBoards tree = new BillboardsClass(Content, camera, graphicsDevice); tree.GetData(new object[] { Qtree, sky }); tree.Initialize(); #endregion //Water water = new Water.Water(WaveLength, WaveHeight, WaveSpeed, WaterPos, WaterSize, Content, graphicsDevice, LightDirection, LightColor, sky.sky.LightIntensity); worker.RunWorkerAsync(); renderer = new Renderer(game, graphicsDevice, Content, 800, 600); light = new LightingClass(); light.AddDirectionalLight(MathHelper.PiOver2, sky.Theta + MathHelper.PiOver2, 0, new Color(LightColor), sky.sky.Parameters.AmbientColor.W, 10000, 0.005f); #region Particles fire = new Fire(game); fire.AddFire(new Vector3(4500, Qtree.GetHeight(4500, -250), -250), new Vector2(10, 10), 200, new Vector2(20), new Vector2(1), 1, new Vector3(10, 0, 0), 1); fire.AddFire(new Vector3(543, Qtree.GetHeight(543, -250), -250), new Vector2(10, 10), 200, new Vector2(20), new Vector2(1), 1, new Vector3(0), 1); fire.AddLight(ref light); groundHit = new GroundHit(game); groundHit.AddDust(new Vector3(4000, Qtree.GetHeight(4000, -250), -250), new Vector2(10, 10), 30, new Vector2(20), new Vector2(1), 4, new Vector3(0), 0); #endregion Random random = new Random(); for (int i = 0; i < 0; i++) light.AddMovingPointLight(100, 1, new Color(((float)random.NextDouble() * 2 - 1) * 255, ((float)random.NextDouble() * 2 - 1) * 255, ((float)random.NextDouble() * 2 - 1) * 255), new Vector3(((float)random.NextDouble() * 2 - 1) * 1000, Qtree.GetHeight(((float)random.NextDouble() * 2 - 1) * 1000, ((float)random.NextDouble() * 2 - 1) * 1000) + 50, ((float)random.NextDouble() * 2 - 1) * 1000), new Vector3(((float)random.NextDouble() * 2 - 1) * 1000, Qtree.GetHeight(((float)random.NextDouble() * 2 - 1) * 1000, ((float)random.NextDouble() * 2 - 1) * 1000) + 50, ((float)random.NextDouble() * 2 - 1) * 1000), ((float)random.NextDouble() * 2 - 1) * 5); light.AddSpotLight(2000, 1, 30, MathHelper.PiOver4, -MathHelper.PiOver2 / 4, 0, new Color(255, 255, 255), new Vector3(0, 1000, 100), 0.0005f); light.AddSpotLight(2000, 1, 30, 5 * MathHelper.PiOver4, -MathHelper.PiOver2 / 4, 0, new Color(255, 255, 255), new Vector3(0, 1000, 0), 0.0005f); playerManager = new PlayerManager(game, graphicsDevice); playerManager.GetData(new object[] { Qtree, camera }); playerManager.Initialize(); lensFlare = new LensFlareComponent(game, graphicsDevice); lensFlare.LoadContent(); _postProcessingComponent = new PostProcessingComponent(); _postProcessingComponent.InitComponent(Content, renderer); _postProcessingComponent.MainLight = light.DirLight(); spriteFont = Content.Load<SpriteFont>("SpriteFont1"); renderCapture = new RenderCapture(graphicsDevice); postprocessor = new GaussianBlur(graphicsDevice, Content, 2f); depthEffect = Content.Load<Effect>("shaders//DepthEffect"); depthCapture = new RenderCapture(graphicsDevice, SurfaceFormat.HalfSingle); blurCapture = new RenderCapture(graphicsDevice, SurfaceFormat.Color); dof = new DepthOfField(graphicsDevice, Content); // Initialize our renderer DebugShapeRenderer.Initialize(GraphicsDevice); base.LoadContent(); }
public void PreDraw(Camera.Camera camera, GameTime gameTime) { renderRefraction(camera); renderReflection(camera); waterEffect.Parameters["Time"].SetValue((float)gameTime.TotalGameTime.TotalSeconds); }
public void Draw(Camera.Camera camera, GraphicsDevice graphicsDevice, Texture2D lightBuffer) { waterMesh.Draw(camera, graphicsDevice, lightBuffer); }
public void RenderToGBuffer(Camera.Camera camera, GraphicsDevice graphicsDevice) { waterMesh.RenderToGBuffer(camera, graphicsDevice); }
public void renderRefraction(Camera.Camera camera) { // Refract the camera's properties across the water plane Vector3 refractedCameraPosition = camera.Transform.Translation; Vector3 refractedCameraTarget = camera.Target; // Create a temporary camera to render the rafracted scene // Camera.Camera refractionCamera = new TargetCamera(refractedCameraPosition, refractedCameraTarget, camera.NearPlane, camera.FarPlane, graphics); // refractionCamera.Update(); // Set the reflection camera's view matrix to the water effect waterEffect.Parameters["RefractedView"].SetValue(camera.View); // Create the clip plane Vector4 clipPlane = new Vector4(0, 1, 0, waterMesh.Position.Y); // Set the render target graphics.SetRenderTarget(refractionTarg); graphics.Clear(new Color(0.10980f, 0.30196f, 0.49412f)); //(122, 144, 255) // Draw all objects with clip plane foreach (IRenderable renderable in Objects) { renderable.SetClipPlane(clipPlane); renderable.Draw(camera.View, camera.Projection, refractedCameraPosition); renderable.SetClipPlane(null); } graphics.SetRenderTarget(null); // Set the reflected scene to its effect parameter in the water effect waterEffect.Parameters["RefractionMap"].SetValue(refractionTarg); }
public Billboard(ContentManager content, Camera.Camera camera, GraphicsDevice graphicsDevice) { this.content = content; this.camera = camera; this.graphicsDevice = graphicsDevice; }
public void Draw(Matrix[] instanceTransformsPS, Camera.Camera camera) { rp.Draw(camera.View, camera.Projection, new Vector3(0, 1, 0), camera.Transform.Right); //rp.DrawHardwareInstancing(instanceTransformsPS, ((FreeCamera)camera), Position); }
public void Update(Camera.Camera camera) { //Add rocks for (int i = 0; i < nParticle * factor; i++) { // Generate a direction within 15 degrees of (0, 1, 0) Vector3 offset = new Vector3(MathHelper.ToRadians(20.0f)); Vector3 randAngle = Vector3.Up + randVec3(-offset, offset); // Generate a position between (-scale.X, 0, -scale.X) and (scale.X, 0, scale.X) Vector3 randPosition = randVec3(new Vector3(-scale.X, 0, -scale.X), new Vector3(scale.X, 0, scale.X)); float randSpeed = ((float)r.NextDouble() + 2) * scale.Y; rocks.AddParticle(randPosition + Position, randAngle, randSpeed * 2, new Vector2(0), 5f); rocks.Update(); } //Add smoke for (int i = 0; i < nParticle; i++) { // Generate a direction within 15 degrees of (0, 1, 0) Vector3 offset = new Vector3(MathHelper.ToRadians(50.0f)); Vector3 randAngle = Vector3.Up + randVec3(-offset, offset); // Generate a position between (-scale.X, 0, -scale.X) and (scale.X, 0, scale.X) Vector3 randPosition = randVec3(new Vector3(-scale.X, 0, -scale.X), new Vector3(scale.X, 0, scale.X)); float randSpeed = ((float)r.NextDouble() + 2) * scale.Y; dust.AddParticle(randPosition + Position, randAngle, randSpeed, ParticleScaleSpeed, 0); dust.Update(); } }
public void Draw(Camera.Camera camera) { dust.Draw(camera.View, camera.Projection, camera.Transform.Up, camera.Transform.Right); rocks.Draw(camera.View, camera.Projection, camera.Transform.Up, camera.Transform.Right); }
public void Update(Camera.Camera camera) { // Generate a direction within 15 degrees of (0, 1, 0) Vector3 offset = new Vector3(MathHelper.ToRadians(10.0f)); Vector3 randAngle = Vector3.Up + randVec3(-offset, offset); // Generate a position between (-400, 0, -400) and (400, 0, 400) Vector3 randPosition = randVec3(new Vector3(-scale.X, 0, -scale.X), new Vector3(scale.X, 0, scale.X)); float randSpeed = ((float)r.NextDouble() + 2) * scale.Y; ps.AddParticle(randPosition + Position, randAngle, randSpeed, new Vector2(0), 0); ps.Update(); smoke.AddParticle(randPosition + Position + new Vector3(0, scale.Y * 3, 0), randAngle, randSpeed * 2, ParticleScaleSpeed, 0); smoke.Update(); TransformMatrix(ref transformPS, Position, new Vector3(((FreeCamera)camera).Yaw, ((FreeCamera)camera).Pitch, 0)); TransformMatrix(ref transformSM, Position + new Vector3(0, scale.Y, 0), new Vector3(((FreeCamera)camera).Yaw, ((FreeCamera)camera).Pitch, 0)); }
/// <summary> /// Copy Constructor /// </summary> /// <param name="camera">The camera to copy</param> public Camera(Camera camera) { dt = camera.dt; mode = camera.mode; oldTarget = camera.oldTarget; target = camera.target; oldTargetPos = camera.oldTargetPos; targetPos = camera.targetPos; transitionPos = camera.transitionPos; transitionRemaining = camera.transitionRemaining; transitionTime = camera.transitionTime; lastFramePos = camera.lastFramePos; effects = new List<CameraEffect>(camera.effects); isTransformDirty = camera.isTransformDirty; transformMatrix = camera.transformMatrix; }
public void Update(Camera.Camera camera) { Generateparticle(); rp.Update(); }
public void renderReflection(Camera.Camera camera) { // Reflect the camera's properties across the water plane Vector3 reflectedCameraPosition = camera.Transform.Translation; reflectedCameraPosition.Y = -reflectedCameraPosition.Y + waterMesh.Position.Y * 2; Vector3 reflectedCameraTarget = ((FreeCamera)camera).Target; reflectedCameraTarget.Y = -reflectedCameraTarget.Y + waterMesh.Position.Y * 2; // Create a temporary camera to render the reflected scene Camera.Camera reflectionCamera = new TargetCamera(reflectedCameraPosition, reflectedCameraTarget, camera.NearPlane, camera.FarPlane, graphics); reflectionCamera.Update(); // Set the reflection camera's view matrix to the water effect waterEffect.Parameters["ReflectedView"].SetValue(reflectionCamera.View); // Create the clip plane Vector4 clipPlane = new Vector4(0, 1, 0, -waterMesh.Position.Y); // Set the render target graphics.SetRenderTarget(reflectionTarg); graphics.Clear(ClearOptions.Target, Color.CornflowerBlue, 1f, 0); // Draw all objects with clip plane foreach (IRenderable renderable in Objects) { renderable.SetClipPlane(clipPlane); renderable.Draw(reflectionCamera.View, reflectionCamera.Projection, reflectedCameraPosition); renderable.SetClipPlane(null); } graphics.SetRenderTarget(null); // Set the reflected scene to its effect parameter in // the water effect waterEffect.Parameters["ReflectionMap"].SetValue(reflectionTarg); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load<SpriteFont>("SpriteFont1"); camera = new FreeCamera(new Vector3(0, 200, 0), 0, 0, 1f, 1000000.0f, graphicsDevice); sky = new SkyDome(game, false, camera, graphicsDevice); components = new Components(graphicsDevice); terrain.InitializeTerrin(Qtree, (FreeCamera)camera, terrain, Content.Load<Texture2D>("textures//Terrain//BasicTerrain//heightmap"), Vector3.Zero, Content, graphicsDevice); terrain.TerrainTextures(Qtree, new Texture2D[] { Content.Load<Texture2D>("textures//Terrain//BasicTerrain//GroundMap"), }, new Texture2D[] { Content.Load<Texture2D>("textures//Terrain//grass//grass"), }, new int[] { 1000, 100, 100, 1000, 1000, 500 }, Content); fire = new Fire(game); //fire.AddFire(new Vector3(450, Qtree.GetHeight(0, 300), 300), new Vector2(10, 50), 100, new Vector2(50), 1f, new Vector3(0), 1); base.LoadContent(); }
public void Draw(Camera.Camera camera) { foreach (GroundHitSystem dust in DustParticle) dust.Draw(camera); }