private Vector2 GetScreenPosition(MySolarSystemMapCamera camera, Vector3 worldPosition) { Vector3 target = SharpDXHelper.ToXNA(MyCamera.Viewport.Project(SharpDXHelper.ToSharpDX(worldPosition), SharpDXHelper.ToSharpDX(camera.GetProjectionMatrix()), SharpDXHelper.ToSharpDX(camera.GetViewMatrixAtZero()), SharpDXHelper.ToSharpDX(Matrix.Identity))); Vector2 projected2Dpoint = new Vector2(target.X, target.Y); return(MyGuiManager.GetNormalizedCoordinateFromScreenCoordinate(projected2Dpoint)); }
public static void Draw() { // We can fill vertex buffer only when in Draw LoadInDraw(); RasterizerState.CullClockwise.Apply(); DepthStencilState.None.Apply(); BlendState.Opaque.Apply(); if (MyRender.CurrentRenderSetup.BackgroundColor != null) { MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, SharpDXHelper.ToSharpDX(MyRender.CurrentRenderSetup.BackgroundColor.Value), 1, 0); } else { MyEffectBackgroundCube effect = MyRender.GetEffect(MyEffects.BackgroundCube) as MyEffectBackgroundCube; effect.SetViewProjectionMatrix(MyCamera.ViewMatrixAtZero * m_backgroundProjectionMatrix); effect.SetBackgroundTexture(m_textureCube); effect.SetBackgroundColor(MySector.SunProperties.BackgroundColor); MyMinerGame.Static.GraphicsDevice.VertexDeclaration = MyVertexFormatPositionTexture3.VertexDeclaration; MyMinerGame.Static.GraphicsDevice.SetStreamSource(0, m_boxVertexBuffer, 0, MyVertexFormatPositionTexture3.Stride); effect.Begin(); MyMinerGame.Static.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, BOX_TRIANGLES_COUNT); effect.End(); MyPerformanceCounter.PerCameraDraw.TotalDrawCalls++; } }
/// <summary> /// Updates emitter position, forward, up and velocity /// </summary> public static void UpdateValues(this Emitter emitter, ref Vector3 position, ref Vector3 forward, ref Vector3 up, ref Vector3 velocity) { emitter.Position = SharpDXHelper.ToSharpDX(position); emitter.OrientFront = SharpDXHelper.ToSharpDX(forward); emitter.OrientTop = SharpDXHelper.ToSharpDX(up); emitter.Velocity = SharpDXHelper.ToSharpDX(velocity); }
static Vector3 CalculateProjectedPosition() { Vector3 directionFromSunNormalized = -MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); // Tell the lensflare component where our camera is positioned. m_view = MyCamera.ViewMatrix; m_projection = MyCamera.ProjectionMatrix; // The sun is infinitely distant, so it should not be affected by the // position of the camera. Floating point math doesn't support infinitely // distant vectors, but we can get the same result by making a copy of our // view matrix, then resetting the view translation to zero. Pretending the // camera has not moved position gives the same result as if the camera // was moving, but the light was infinitely far away. If our flares came // from a local object rather than the sun, we would use the original view // matrix here. Matrix infiniteView = m_view; infiniteView.Translation = Vector3.Zero; // Project the light position into 2D screen space. Viewport viewport = MyMinerGame.Static.GraphicsDevice.Viewport; Vector3 projectedPosition = SharpDXHelper.ToXNA(viewport.Project(SharpDXHelper.ToSharpDX(-directionFromSunNormalized), SharpDXHelper.ToSharpDX(m_projection), SharpDXHelper.ToSharpDX(infiniteView), SharpDXHelper.ToSharpDX(Matrix.Identity))); return(projectedPosition); return(Vector3.Zero); }
public static void UpdateFromMainCamera(this Listener listener) { if (MySector.MainCamera == null) { return; } listener.Position = SharpDXHelper.ToSharpDX(MySector.MainCamera.Position); listener.OrientFront = -SharpDXHelper.ToSharpDX(MySector.MainCamera.ForwardVector); listener.OrientTop = SharpDXHelper.ToSharpDX(MySector.MainCamera.UpVector); listener.Velocity = SharpDXHelper.ToSharpDX(MySector.MainCamera.Velocity); }
/// <summary> /// Updates emitter position, forward, up and velocity /// </summary> public static void UpdateValues(this Emitter emitter, Vector3 position, Vector3 forward, Vector3 up, Vector3 velocity, MyObjectBuilder_CueDefinition cue, int channelsCount) { emitter.Position = SharpDXHelper.ToSharpDX(position); emitter.OrientFront = SharpDXHelper.ToSharpDX(forward); emitter.OrientTop = SharpDXHelper.ToSharpDX(up); emitter.Velocity = SharpDXHelper.ToSharpDX(velocity); emitter.DopplerScaler = 1f; emitter.CurveDistanceScaler = cue.MaxDistance; if (m_currVolumeCurve != cue.VolumeCurve) { emitter.VolumeCurve = m_curves[(int)cue.VolumeCurve]; m_currVolumeCurve = cue.VolumeCurve; } emitter.InnerRadius = (channelsCount > 2) ? cue.MaxDistance : 0f; emitter.InnerRadiusAngle = (channelsCount > 2) ? 0.5f * SharpDX.AngleSingle.RightAngle.Radians : 0f; }
public static bool UpdateFromPlayer(this Listener listener) { if ((MySession.Player == null) || (MySession.Player.PlayerEntity == null) || (MySession.Player.PlayerEntity.Entity == null)) { return(false); } if (MySession.Player.PlayerEntity is MyCharacter) { listener.Position = SharpDXHelper.ToSharpDX(MySession.Player.PlayerEntity.Entity.GetPosition() + 1f * MySession.Player.PlayerEntity.Entity.WorldMatrix.Up); } else { listener.Position = SharpDXHelper.ToSharpDX(MySession.Player.PlayerEntity.Entity.GetPosition()); } listener.OrientFront = -SharpDXHelper.ToSharpDX(MySession.Player.PlayerEntity.Entity.WorldMatrix.Forward); listener.OrientTop = SharpDXHelper.ToSharpDX(MySession.Player.PlayerEntity.Entity.WorldMatrix.Up); listener.Velocity = SharpDXHelper.ToSharpDX(MySession.Player.PlayerEntity.Entity.Physics.LinearVelocity); return(true); }
// Draws the lensflare sprites, computing the position // of each one based on the current angle of the sun. static void DrawFlares(float occlusionFactor, float visibilityRatio) { Viewport viewport = MyMinerGame.Static.GraphicsDevice.Viewport; // Lensflare sprites are positioned at intervals along a line that // runs from the 2D light position toward the center of the screen. Vector2 screenCenter = new Vector2(viewport.Width, viewport.Height) / 2; Vector2 flareVector = screenCenter - m_lightPosition; // Draw the flare sprites using additive blending. m_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); foreach (MyFlare flare in m_flares) { // Compute the position of this flare sprite. Vector2 flarePosition = m_lightPosition + flareVector * flare.Position * m_screenScale; // Set the flare alpha based on the previous occlusion query result. Vector4 flareColor = flare.Color.ToVector4(); flareColor.W *= occlusionFactor * visibilityRatio * visibilityRatio * (1 - MySector.FogMultiplierForSun); flareColor.W *= (1 - MySector.FogProperties.FogMultiplier); // Center the sprite texture. Vector2 flareOrigin = new Vector2(flare.Texture.Width, flare.Texture.Height) / 2; // Draw the flare. m_spriteBatch.Draw(flare.Texture, SharpDXHelper.ToSharpDX(flarePosition), null, new SharpDX.Color(flareColor.X, flareColor.Y, flareColor.Z, flareColor.W), 1, SharpDXHelper.ToSharpDX(flareOrigin), flare.Scale * m_screenScale, SpriteEffects.None, 0); } m_spriteBatch.End(); }
private static void DrawGlare(float occlusionFactor, float visibilityRatio) { //Dont draw glare if there are godrays, it is overexposed then if (MyRenderConstants.RenderQualityProfile.EnableGodRays && MySector.GodRaysProperties.Enabled) { return; } var zoom = MyRender.CurrentRenderSetup.EnableZoom ? MyCamera.Zoom.GetZoomLevel() : 1; zoom = MathHelper.Clamp(zoom, 0.1f, 1); float glowSize = 0.1f * m_querySize / zoom; float occlusionRatio = occlusionFactor * visibilityRatio; Vector2 origin = new Vector2(m_glowSprite.Width, m_glowSprite.Height) / 2; float viewportScale = 0.5f * (MyRender.GetScaleForViewport(null).X + MyRender.GetScaleForViewport(null).Y); float scale = glowSize * 2.0f / m_glowSprite.Width * viewportScale; m_directionToSunNormalized = MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized(); float dot = Vector3.Dot(m_directionToSunNormalized, MyCamera.ForwardVector); float glareIntensity; if (dot > 0.9f) { glareIntensity = dot * (1 + MySunConstants.MAX_GLARE_MULTIPLIER * (dot - 0.9f)); } else { glareIntensity = .9f; } m_spriteBatch.Begin(SpriteSortMode.Deferred, MyStateObjects.Additive_NoAlphaWrite_BlendState, SharpDX.Toolkit.Graphics.SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.Current); Matrix rot = MyCamera.ViewMatrix; rot.Translation = Vector3.Zero; float yaw, pitch, roll; MyUtils.RotationMatrixToYawPitchRoll(ref rot, out yaw, out pitch, out roll); // ----- small colored glares (bleeding, complements bloom): ----- // this one isn't rotating with camera: float glare1Alpha = occlusionRatio * occlusionRatio * (1 - MySector.FogProperties.FogMultiplier); float glare1Size = scale; Color color1 = new Color(new Vector4(MySector.SunProperties.SunDiffuse, MathHelper.Clamp(glare1Alpha, 0, 0.1f))); m_spriteBatch.Draw(m_glowSprite, SharpDXHelper.ToSharpDX(m_lightPosition), null, SharpDXHelper.ToSharpDX(color1), -pitch, SharpDXHelper.ToSharpDX(origin), glare1Size, SpriteEffects.None, 0); // rays glare - this one is rotating with camera float glare2Alpha = 0.6f * glareIntensity * glareIntensity * occlusionRatio * occlusionRatio * (1 - MySector.FogProperties.FogMultiplier); float glare2Size = 1.5f * glareIntensity * scale; Color color2 = new Color(new Vector4(MySector.SunProperties.SunDiffuse, glare2Alpha)); m_spriteBatch.Draw(m_glowSprite2, SharpDXHelper.ToSharpDX(m_lightPosition), null, SharpDXHelper.ToSharpDX(color2), 0, SharpDXHelper.ToSharpDX(origin), glare2Size, SpriteEffects.None, 0); // large white glare - blinding effect float glare3Size = 40 * scale; m_spriteBatch.Draw(m_glareSprite, SharpDXHelper.ToSharpDX(m_lightPosition), null, new SharpDX.Color(1, 0, 1, glareIntensity * occlusionRatio * 0.3f), 0, SharpDXHelper.ToSharpDX(origin), glare3Size, SpriteEffects.None, 0); m_spriteBatch.End(); }