public void renderReflection(GameTime gameTime) { // Reflect the camera's properties across the water plane Vector3 reflectedCameraPosition = myGame.camera.Position; reflectedCameraPosition.Y = -reflectedCameraPosition.Y + position.Y * 2; Vector3 reflectedCameraTarget = myGame.camera.Target; reflectedCameraTarget.Y = -reflectedCameraTarget.Y + position.Y * 2; // Create a temporary camera to render the reflected scene TargetCamera reflectionCamera = new TargetCamera(myGame, reflectedCameraPosition, reflectedCameraTarget); 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, -position.Y); // Set the render target myGame.GraphicsDevice.SetRenderTarget(reflectionTarg); myGame.GraphicsDevice.Clear(Color.Black); // Draw all objects with clip plane Camera oldCamera = myGame.camera; myGame.camera = reflectionCamera; foreach (IRenderable renderable in Objects) { renderable.SetClipPlane(clipPlane); renderable.Draw(); //reflectionCamera.View, // reflectionCamera.Projection, // reflectedCameraPosition); renderable.SetClipPlane(null); } myGame.camera = oldCamera; myGame.GraphicsDevice.SetRenderTarget(null); // Set the reflected scene to its effect parameter in // the water effect waterEffect.Parameters["ReflectionMap"].SetValue(reflectionTarg); }
public void renderReflection(Camera camera) { // Reflect the camera's properties across the water plane Vector3 reflectedCameraPosition = ((FreeCamera)camera).Position; 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 reflectionCamera = new TargetCamera( reflectedCameraPosition, reflectedCameraTarget, 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(Color.Black); // 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); }
public void renderReflection(GameTime gameTime) { // Reflect the camera's properties across the water plane Vector3 reflectedCameraPosition = myGame.camera.Position; reflectedCameraPosition.Y = -reflectedCameraPosition.Y + position.Y * 2; Vector3 reflectedCameraTarget = myGame.camera.Target; reflectedCameraTarget.Y = -reflectedCameraTarget.Y + position.Y * 2; // Create a temporary camera to render the reflected scene TargetCamera reflectionCamera = new TargetCamera(myGame,reflectedCameraPosition,reflectedCameraTarget); 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, -position.Y); // Set the render target myGame.GraphicsDevice.SetRenderTarget(reflectionTarg); myGame.GraphicsDevice.Clear(Color.Black); // Draw all objects with clip plane Camera oldCamera = myGame.camera; myGame.camera = reflectionCamera; foreach (IRenderable renderable in Objects) { renderable.SetClipPlane(clipPlane); renderable.Draw(); //reflectionCamera.View, // reflectionCamera.Projection, // reflectedCameraPosition); renderable.SetClipPlane(null); } myGame.camera = oldCamera; myGame.GraphicsDevice.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); models.Add(new CModel(Content.Load <Model>("Ship"), new Vector3(1000, 1000, 1000), Vector3.Zero, new Vector3(0.4f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("jula"), new Vector3(1000, 1000, 1000), Vector3.Zero, new Vector3(0.4f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("ground"), new Vector3(0, 0, 0), Vector3.Zero, new Vector3(10f), GraphicsDevice)); PhongEffect = Content.Load <Effect>("MultiSpotLightEffect"); GouraudEffect = Content.Load <Effect>("MultiSpotLightEffectGouraud"); effect = PhongEffect; chaseLight = new ChaseLight(new Vector3(0, 200, -100), new Vector3(0, 200, 0), new Vector3(0, 0, 0)); mat = new MultiSpotLightMaterial(chaseLight); Random rand = new Random(); for (int i = -1; i < 2; i += 2) { for (int j = -1; j < 2; j += 2) { Vector3 additionalRotation = Vector3.Zero; if (i > 0) { additionalRotation += new Vector3(0, 1, 0) * (rand.Next() % 100 * .025f); } else { additionalRotation += new Vector3(0, -1, 0) * (rand.Next() % 100 * .025f); } models.Add(new CModel(Content.Load <Model>("deer"), new Vector3(0 + i * 4000, 0, 0 + j * 4000), Vector3.Zero + additionalRotation, Vector3.One, GraphicsDevice)); } } models.Add(new CModel(Content.Load <Model>("moon"), new Vector3(0, 10000, 10000), new Vector3(1.05f, 0, 1), new Vector3(500f), GraphicsDevice)); models.Add(new CModel(Content.Load <Model>("fireplace"), new Vector3(1000, 100, 1000), new Vector3(1.05f, 0, 1), new Vector3(50f), GraphicsDevice)); for (int i = -1; i < 2; i += 2) { for (int j = -1; j < 2; j += 2) { models.Add(new CModel(Content.Load <Model>("ball"), new Vector3(2000 * 1, 100, 2000 * j), new Vector3(1.05f, 0, 1), new Vector3(500f), GraphicsDevice)); } } for (int i = -1; i < 2; i++) { for (int j = -1; j < 2; j++) { Vector3 additionalRotation = Vector3.Zero; float scale = 2; if (i > 0) { additionalRotation += new Vector3(0, 1, 0) * (rand.Next() % 100 * .025f); } else { additionalRotation += new Vector3(0, -1, 0) * (rand.Next() % 100 * .025f); } models.Add(new CModel(Content.Load <Model>("AlanTree"), new Vector3(0 + i * 6000, 0, 0 + j * 6000), Vector3.Zero + additionalRotation, new Vector3(scale, scale, scale), GraphicsDevice)); } } foreach (CModel cm in models) { cm.Material = mat; cm.SetModelEffect(effect, true); } cam1 = new ChaseCamera(new Vector3(0, 200, 2500), new Vector3(0, 200, 0), new Vector3(0, 0, 0), GraphicsDevice); cam2 = new TargetCamera( new Vector3(100, 15000, 100), Vector3.Zero, GraphicsDevice); cam3 = new TargetCamera( new Vector3(100, 15000, 100), Vector3.Zero, GraphicsDevice); switch (cameraChosen) { case 1: camera = cam1; break; case 2: camera = cam2; break; case 3: camera = cam3; break; default: throw new InvalidDataException("Z³y numer kamery"); } lastMouseState = Mouse.GetState(); }