/// <summary>Function to retrieve the sampler based on the specified states.</summary> /// <param name="filter">The texture filtering state to use.</param> /// <param name="wrapU">The horizontal wrapping state.</param> /// <param name="wrapV">The vertical wrapping state.</param> /// <param name="borderColor">The border color to use when one of the wrapping states is set to <see cref="TextureWrap.Border"/>.</param> /// <returns>The sampler state.</returns> public GorgonSamplerState GetSampler(SampleFilter filter, TextureWrap wrapU, TextureWrap wrapV, GorgonColor borderColor) { if ((filter == GorgonSamplerState.Default.Filter) && (wrapU == GorgonSamplerState.Default.WrapU) && (wrapV == GorgonSamplerState.Default.WrapV) && (borderColor.Equals(GorgonSamplerState.Default.BorderColor))) { return(GorgonSamplerState.Default); } if ((filter == GorgonSamplerState.PointFiltering.Filter) && (wrapU == GorgonSamplerState.PointFiltering.WrapU) && (wrapV == GorgonSamplerState.PointFiltering.WrapV) && (borderColor.Equals(GorgonSamplerState.PointFiltering.BorderColor))) { return(GorgonSamplerState.PointFiltering); } if ((filter == GorgonSamplerState.Wrapping.Filter) && (wrapU == GorgonSamplerState.Wrapping.WrapU) && (wrapV == GorgonSamplerState.Wrapping.WrapV) && (borderColor.Equals(GorgonSamplerState.Wrapping.BorderColor))) { return(GorgonSamplerState.Wrapping); } #pragma warning disable IDE0046 // Convert to conditional expression if ((filter == GorgonSamplerState.PointFilteringWrapping.Filter) && (wrapU == GorgonSamplerState.PointFilteringWrapping.WrapU) && (wrapV == GorgonSamplerState.PointFilteringWrapping.WrapV) && (borderColor.Equals(GorgonSamplerState.PointFilteringWrapping.BorderColor))) { return(GorgonSamplerState.PointFilteringWrapping); } return(_builder.Clear() .Filter(filter) .Wrapping(wrapU, wrapV, borderColor: borderColor) .Build()); #pragma warning restore IDE0046 // Convert to conditional expression }
/// <summary> /// Function to transform the vertices. /// </summary> protected override void TransformVertices() { int vertexIndex = 0; Vector2 center = _center; for (int i = 0; i < _points.Length; i++) { Vector2 startPosition = _points[i]; Vector2 endPosition = i + 1 < _points.Length ? _points[i + 1] : _points[0]; // ReSharper disable CompareOfFloatsByEqualityOperator if (Scale.X != 1.0f) { startPosition.X *= Scale.X; endPosition.X *= Scale.X; center.X *= Scale.X; } if (Scale.Y != 1.0f) { startPosition.Y *= Scale.Y; endPosition.Y *= Scale.Y; center.Y *= Scale.Y; } if (Angle != 0.0f) { float angle = Angle.Radians(); // Angle in radians. float cosVal = angle.Cos(); // Cached cosine. float sinVal = angle.Sin(); // Cached sine. Vertices[vertexIndex].Position.X = (center.X * cosVal - center.Y * sinVal) + Position.X; Vertices[vertexIndex].Position.Y = (center.X * sinVal + center.Y * cosVal) + Position.Y; Vertices[vertexIndex + 1].Position.X = (startPosition.X * cosVal - startPosition.Y * sinVal) + Position.X; Vertices[vertexIndex + 1].Position.Y = (startPosition.X * sinVal + startPosition.Y * cosVal) + Position.Y; Vertices[vertexIndex + 2].Position.X = (endPosition.X * cosVal - endPosition.Y * sinVal) + Position.X; Vertices[vertexIndex + 2].Position.Y = (endPosition.X * sinVal + endPosition.Y * cosVal) + Position.Y; } else { Vertices[vertexIndex].Position.X = center.X + Position.X; Vertices[vertexIndex].Position.Y = center.Y + Position.Y; Vertices[vertexIndex + 1].Position.X = startPosition.X + Position.X; Vertices[vertexIndex + 1].Position.Y = startPosition.Y + Position.Y; Vertices[vertexIndex + 2].Position.X = endPosition.X + Position.X; Vertices[vertexIndex + 2].Position.Y = endPosition.Y + Position.Y; } // ReSharper restore CompareOfFloatsByEqualityOperator Vertices[vertexIndex].Position.Z = Depth; Vertices[vertexIndex + 1].Position.Z = Depth; Vertices[vertexIndex + 2].Position.Z = Depth; if (!GorgonColor.Equals(ref _colors[i], ref Vertices[vertexIndex].Color)) { Vertices[vertexIndex + 2].Color = Vertices[vertexIndex + 1].Color = Vertices[vertexIndex].Color = _colors[i]; } vertexIndex += 3; } }