private void UpdateVertexFromSpriteInfo2(ref SpriteInfo spriteInfo, ref MyVertexFormatPositionTextureColor vertex, float deltaX, float deltaY) { var rotation = spriteInfo.Rotation != 0f ? new Vector2((float)Math.Cos(spriteInfo.Rotation), (float)Math.Sin(spriteInfo.Rotation)) : Vector2.UnitX; // Origin scale down to the size of the source texture var origin = spriteInfo.Origin; origin.X /= spriteInfo.Source.Width == 0f ? float.Epsilon : spriteInfo.Source.Width; origin.Y /= spriteInfo.Source.Height == 0f ? float.Epsilon : spriteInfo.Source.Height; for (int j = 0; j < 4; j++) { // Gets the corner and take into account the Flip mode. var corner = CornerOffsets[j]; // Calculate position on destination var position = new Vector2((corner.X - origin.X) * spriteInfo.Destination.Width, (corner.Y - origin.Y) * spriteInfo.Destination.Height); // Apply rotation and destination offset vertex.Position.X = spriteInfo.Destination.X + (position.X * rotation.X) - (position.Y * rotation.Y); vertex.Position.Y = spriteInfo.Destination.Y + (position.X * rotation.Y) + (position.Y * rotation.X); vertex.Position.Z = spriteInfo.Depth; vertex.Color = SharpDXHelper.ToXNA(spriteInfo.Color.ToVector4()); corner = CornerOffsets[j ^ (int)spriteInfo.SpriteEffects]; vertex.TexCoord.X = (spriteInfo.Source.X + corner.X * spriteInfo.Source.Width) * deltaX; vertex.TexCoord.Y = (spriteInfo.Source.Y + corner.Y * spriteInfo.Source.Height) * deltaY; } }
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)); }
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); }