private void DrawImageVertex(ImageInfo info) { // CCW from bottom left var tl = new Vector2(-info.Width / 2, info.Height / 2); var br = new Vector2(info.Width / 2, -info.Height / 2); var transform = info.Angle != 0 ? Matrix3x2.Rotation(info.Angle) : Matrix3x2.Identity; var offTL = tl * info.Scale; var offBR = br * info.Scale; var offTR = new Vector2(offBR.X, offTL.Y); var offBL = new Vector2(offTL.X, offBR.Y); BillboardVertices.Add(new BillboardVertex() { Position = info.Position.ToVector4(), Foreground = Color.White, Background = maskColor, TexTL = info.UV_TopLeft, TexBR = info.UV_BottomRight, OffTL = Matrix3x2.TransformPoint(transform, offTL), OffBL = Matrix3x2.TransformPoint(transform, offBL), OffBR = Matrix3x2.TransformPoint(transform, offBR), OffTR = Matrix3x2.TransformPoint(transform, offTR) }); }
/// <summary> /// Called when [draw texture]. /// </summary> /// <param name="deviceResources">The device resources.</param> protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources) { var w = Width; var h = Height; // CCW from bottom left var tl = new Vector2(-w / 2, h / 2); var br = new Vector2(w / 2, -h / 2); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); var transform = Angle != 0 ? Matrix3x2.Rotation(Angle) : Matrix3x2.Identity; var tr = new Vector2(br.X, tl.Y); var bl = new Vector2(tl.X, br.Y); BillboardVertices.Add(new BillboardVertex() { Position = Center.ToVector4(), Foreground = Color.White, Background = MaskColor, TexTL = uv_tl, TexBR = uv_br, OffTL = Matrix3x2.TransformPoint(transform, tl), OffBR = Matrix3x2.TransformPoint(transform, br), OffBL = Matrix3x2.TransformPoint(transform, bl), OffTR = Matrix3x2.TransformPoint(transform, tr) }); }
private void Render() { context.Clear(null); Matrix3x2 worldToFormTransform = GetWorldToFormTransform(); foreach (var bone in bones) { var transform = bone.GetChainedTransform(inputs) * worldToFormTransform; var formCenter = Matrix3x2.TransformPoint(transform, bone.Center); var formEnd = Matrix3x2.TransformPoint(transform, bone.End); context.DrawEllipse(new Ellipse(formCenter, 5, 5), whiteBrush, 2); context.DrawLine(formCenter, formEnd, whiteBrush, 2); } var formTarget = Matrix3x2.TransformPoint(worldToFormTransform, target); float crossSize = 5; context.DrawLine( formTarget + crossSize * new Vector2(-1, -1), formTarget + crossSize * new Vector2(+1, +1), redBrush, 2); context.DrawLine( formTarget + crossSize * new Vector2(-1, +1), formTarget + crossSize * new Vector2(+1, -1), redBrush, 2); }
private void DrawCharacter(string text, Vector3 origin, float w, float h, TextInfo info) { // CCW from bottom left var tl = new Vector2(-w / 2, h / 2); var br = new Vector2(w / 2, -h / 2); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); var transform = info.Angle != 0 ? Matrix3x2.Rotation(info.Angle) : Matrix3x2.Identity; var offTL = tl * info.Scale; var offBR = br * info.Scale; var offTR = new Vector2(offBR.X, offTL.Y); var offBL = new Vector2(offTL.X, offBR.Y); BillboardVertices.Add(new BillboardVertex() { Position = info.Origin.ToVector4(), Foreground = FontColor, Background = BackgroundColor, TexTL = uv_tl, TexBR = uv_br, OffTL = Matrix3x2.TransformPoint(transform, offTL), OffBL = Matrix3x2.TransformPoint(transform, offBL), OffBR = Matrix3x2.TransformPoint(transform, offBR), OffTR = Matrix3x2.TransformPoint(transform, offTR) }); }
public bool Contains(Point point) { Matrix3x2 inverse = Matrix3x2.Invert(Transform); Point p = Matrix3x2.TransformPoint(inverse, point); return(PolygonPointTest(Vertices, p)); }
/** * Given a point that has already had bone total-transform applied to it, retransform it as the rotation of this bone was adjusted by a delta. */ public Vector2 RetransformPoint(SkeletonInputs inputs, float rotationDelta, Vector2 point) { Matrix3x2 parentTransform = GetChainedTransform(Parent, inputs); Vector2 transformedCenter = Matrix3x2.TransformPoint(parentTransform, Center); var retransform = Matrix3x2.Rotation(rotationDelta, transformedCenter); return(Matrix3x2.TransformPoint(retransform, point)); }
public void TestRetransformPointByZero() { var point = new Vector2(2, 3); var transformedPoint = Matrix3x2.TransformPoint(bone2.GetChainedTransform(inputs), point); var retransformedPoint = bone1.RetransformPoint(inputs, 0, transformedPoint); Assert.AreEqual(transformedPoint, retransformedPoint); }
/** * Returns the gradient of a transformed point with respect to the rotation parameter. */ public Vector2 GetGradientOfTransformedPointWithRespectToRotation(SkeletonInputs inputs, Vector2 point) { Matrix3x2 parentTransform = GetChainedTransform(Parent, inputs); Vector2 transformedCenter = Matrix3x2.TransformPoint(parentTransform, Center); Vector2 centeredPoint = point - transformedCenter; return(new Vector2(-centeredPoint.Y, centeredPoint.X)); }
private void AdjustBone(SkeletonInputs inputs, Bone bone, Vector2 source, Vector2 target, float weight) { var transform = bone.GetChainedTransform(inputs); var center = Matrix3x2.TransformPoint(transform, bone.Center); float rotationDelta = Vector2Utils.AngleBetween(source - center, target - center); bone.IncrementRotation(inputs, rotationDelta * weight); }
public static unsafe Point[] PointArray(Matrix3x2 transform, params int[] values) { Point[] points = PointArray(values); for (int i = 0; i < points.Length; i++) { points[i] = transform.TransformPoint(points[i]); } return(points); }
public void DoIteration(SkeletonInputs inputs, Bone sourceBone, Vector2 unposedSource, Vector2 target) { Vector2 posedSource = Matrix3x2.TransformPoint(sourceBone.GetChainedTransform(inputs), unposedSource); List <Vector2> posedCenters = bones .Select(bone => Matrix3x2.TransformPoint(bone.GetChainedTransform(inputs), bone.Center)) .ToList(); List <Vector2> boneVectors = posedCenters .Zip(posedCenters.Skip(1).Concat(new [] { posedSource }), (center, end) => end - center) .ToList(); List <float> weights = Enumerable.Range(0, bones.Count).Select(i => 1f / (bones.Count - i)).ToList(); Vector <float> gradient = Vector <float> .Build.Dense(bones.Count); Matrix <float> hessian = Matrix <float> .Build.Dense(bones.Count, bones.Count); for (int i = 0; i < bones.Count; ++i) { Vector2 bi = boneVectors[i]; Vector2 temp = target - posedSource + bi; gradient[i] = weights[i] * (bi.Y * temp.X - bi.X * temp.Y); hessian[i, i] = weights[i] * weights[i] * Vector2.Dot(bi, temp); for (int j = 0; j < bones.Count; ++j) { Vector2 bj = boneVectors[j]; if (i != j) { hessian[i, j] = weights[i] * weights[j] * Vector2.Dot(bi, bj); } } } //var step = -hessian.Inverse().Multiply(gradient); var step = -hessian.PseudoInverse().Multiply(gradient); //var step = -0.5f * gradient; /* * // Ensure step is approaching a minimum and not a maximum * for (int i = 0; i < bones.Count; ++i) { * step[i] = -Math.Abs(step[i]) * Math.Sign(gradient[i]); * } */ for (int i = 0; i < bones.Count; ++i) { float localRotationDelta = step[i] - ((i > 0) ? step[i - 1] : 0); inputs.IncrementRotation(i, weights[i] * localRotationDelta); } }
public void DoIteration(SkeletonInputs inputs, Bone sourceBone, Vector2 unposedSource, Vector2 target) { Vector2 source = Matrix3x2.TransformPoint(sourceBone.GetChainedTransform(inputs), sourceBone.End); float decay = 0.9f; float weight = 1 - decay; for (var bone = sourceBone; bone != null; bone = bone.Parent) { AdjustBone(inputs, bone, source, target, weight); weight *= decay; } }
private void DrawDiagnostics(DeviceContext renderTarget) { renderTarget.Transform = Matrix3x2.Identity; Matrix3x2 wt = GlobalTransform; wt.Invert(); var worldPos = Matrix3x2.TransformPoint(wt, MouseClientPosition); renderTarget.DrawText( $"FPS: {RenderTimer.FramesPerSecond:0}\r\nFrameTime: {RenderTimer.DurationSinceLastFrame}\r\n({worldPos.X:0}, {worldPos.Y:0})", XResource.TextFormats[11], new RectangleF(0, 0, 100, 30), XResource.GetColor(Color.White)); }
public void TestRetransformPoint() { var point = new Vector2(2, 3); var transformedPoint = Matrix3x2.TransformPoint(bone2.GetChainedTransform(inputs), point); float rotationDelta = 0.3f; var retransformedPoint = bone1.RetransformPoint(inputs, rotationDelta, transformedPoint); bone1.IncrementRotation(inputs, rotationDelta); var expectedRetransformedPoint = Matrix3x2.TransformPoint(bone2.GetChainedTransform(inputs), point); Assert.AreEqual(expectedRetransformedPoint, retransformedPoint); }
/// <summary> /// Initializes a new instance of the <see cref="TextRenderUnit" /> class. /// </summary> /// <param name="textLayout">The text layout.</param> /// <param name="brush">The brush.</param> /// <param name="transform">The text transform.</param> public TextRenderUnit(TextLayout textLayout, Brush brush, Matrix3x2 transform) { this.layout = textLayout; this.brush = brush; this.transform = transform; var topleft = Matrix3x2.TransformPoint(transform, new Vector2(0, 0)); var bottomRight = Matrix3x2.TransformPoint(transform, new Vector2(textLayout.Metrics.Width, textLayout.Metrics.Height)); this.bounds = new RectangleF { Top = topleft.Y, Left = topleft.X, Right = bottomRight.X, Bottom = bottomRight.Y }; }
public void TestGradientOfTransformedPointWithRespectToRotation() { Vector2 point = new Vector2(2, 3); Vector2 transformedPoint = Matrix3x2.TransformPoint(bone2.GetChainedTransform(inputs), point); Vector2 gradient = bone1.GetGradientOfTransformedPointWithRespectToRotation(inputs, transformedPoint); float rotationStepSize = 1e-3f; bone1.IncrementRotation(inputs, rotationStepSize); Vector2 steppedTransformedPoint = Matrix3x2.TransformPoint(bone2.GetChainedTransform(inputs), point); Vector2 finiteDifferenceApproximationToGradient = (steppedTransformedPoint - transformedPoint) / rotationStepSize; Assert.AreEqual(finiteDifferenceApproximationToGradient.X, gradient.X, 1e-3); Assert.AreEqual(finiteDifferenceApproximationToGradient.Y, gradient.Y, 1e-3); }
public static FabrIkChain Make(SkeletonInputs inputs, Bone sourceBone, Vector2 unposedSource, Vector2 target) { Vector2 posedSource = Matrix3x2.TransformPoint(sourceBone.GetChainedTransform(inputs), sourceBone.End); List <Bone> bones = new List <Bone> { }; List <Vector2> unposedBoneVectors = new List <Vector2> { }; List <float> rotations = new List <float>(); List <Vector2> positions = new List <Vector2> { }; positions.Add(posedSource); Vector2 previousUnposedPosition = unposedSource; Vector2 previousPosedPosition = posedSource; for (var bone = sourceBone; bone != null; bone = bone.Parent) { var unposedCenter = bone.Center; var posedCenter = Matrix3x2.TransformPoint(bone.GetChainedTransform(inputs), unposedCenter); Vector2 unposedBoneVector = previousUnposedPosition - unposedCenter; Vector2 posedBoneVector = previousPosedPosition - posedCenter; float rotation = Vector2Utils.AngleBetween( unposedBoneVector, posedBoneVector); bones.Add(bone); unposedBoneVectors.Add(unposedBoneVector); rotations.Add(rotation); positions.Add(posedCenter); previousUnposedPosition = unposedCenter; previousPosedPosition = posedCenter; } var startTarget = target; var endTarget = positions[bones.Count]; return(new FabrIkChain(bones, unposedBoneVectors, rotations, positions, target, endTarget)); }
public void Run() { renderEnvironment.Form.MouseClick += (sender, e) => { Vector2 formPosition = new Vector2(e.X, e.Y); var transform = GetWorldToFormTransform(); transform.Invert(); Vector2 worldPosition = Matrix3x2.TransformPoint(transform, formPosition); target = worldPosition; }; renderEnvironment.Form.KeyPress += (sender, e) => { if (e.KeyChar == ' ') { DoIkIteration(); } }; renderEnvironment.Run(Render); }
/// <summary> /// Called when [draw texture]. /// </summary> /// <param name="deviceResources">The device resources.</param> protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources) { GetQuadOffset(Width, Height, HorizontalAlignment, VerticalAlignment, out var tl, out var br); var uv_tl = new Vector2(0, 0); var uv_br = new Vector2(1, 1); var transform = Angle != 0 ? Matrix3x2.Rotation(Angle) : Matrix3x2.Identity; var tr = new Vector2(br.X, tl.Y); var bl = new Vector2(tl.X, br.Y); BillboardVertices.Add(new BillboardVertex() { Position = Center.ToVector4(), Foreground = Color.White, Background = MaskColor, TexTL = uv_tl, TexBR = uv_br, OffTL = Matrix3x2.TransformPoint(transform, tl), OffBR = Matrix3x2.TransformPoint(transform, br), OffBL = Matrix3x2.TransformPoint(transform, bl), OffTR = Matrix3x2.TransformPoint(transform, tr) }); }
protected void UpdateCamera() { //var mousePos = PointToClient(MousePosition); //_cameraTransformMatrix = Matrix3x2.Add(Matrix3x2.Scaling((float)CameraZoom, (float)CameraZoom, Vector2.Clamp(new Vector2(Width-mousePos.X, Height-mousePos.Y), new Vector2(0, 0), new Vector2(Width, Height))), Matrix3x2.Translation(CameraPosition)); //_cameraTransformMatrix = Matrix3x2.Transformation((float)CameraZoom, (float)CameraZoom, 0, CameraPosition.X, CameraPosition.Y); var translate = Matrix3x2.Translation(CameraPosition); var scale = Matrix3x2.Scaling((float)CameraZoom, (float)CameraZoom, new Vector2(ClientRectangle.Width / 2f, ClientRectangle.Height / 2f)); _cameraTransformMatrix = translate * scale; var cameraMax = Matrix3x2.TransformPoint(_cameraTransformMatrix, new Vector2(ClientRectangle.Width, ClientRectangle.Height)); var cameraPos = Matrix3x2.TransformPoint(_cameraTransformMatrix, CameraPosition); //_cameraBounds = new ViewportF(cameraPos.X, cameraPos.Y, cameraMax.X, cameraMax.Y); //var inverse = Matrix3x2.Invert(_cameraTransformMatrix); //Matrix3x2.TransformPoint(ref inverse, ref cameraPos, out cameraMin); //Matrix3x2.TransformPoint(ref inverse, ref cameraPos, out cameraMax); //_cameraBounds = new Rectangle((int)cameraMin.X, (int)cameraMin.Y, (int)(cameraMax.X - cameraMin.X), (int)(cameraMax.Y - cameraMin.Y)); _viewport.Transform = _cameraTransformMatrix; }
private void DrawImageVertex(ImageInfo info) { GetQuadOffset(info.Width, info.Height, info.HorizontalAlignment, info.VerticalAlignment, out var tl, out var br); var transform = info.Angle != 0 ? Matrix3x2.Rotation(info.Angle) : Matrix3x2.Identity; var offTL = tl * info.Scale; var offBR = br * info.Scale; var offTR = new Vector2(offBR.X, offTL.Y); var offBL = new Vector2(offTL.X, offBR.Y); BillboardVertices.Add(new BillboardVertex() { Position = info.Position.ToVector4(), Foreground = Color.White, Background = maskColor, TexTL = info.UV_TopLeft, TexBR = info.UV_BottomRight, OffTL = Matrix3x2.TransformPoint(transform, offTL), OffBL = Matrix3x2.TransformPoint(transform, offBL), OffBR = Matrix3x2.TransformPoint(transform, offBR), OffTR = Matrix3x2.TransformPoint(transform, offTR) }); }
private void OnRenderFormMouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { // Mouse clicks are in "screen space". DirectX might be rendering the client/form in a different resolution (i.e., "world space") // so we need to transform the click coordinates from "screen space" to "world space". // It gets trickier. We want to know what facial point is clicked on. The facial point coordinates exist in "local/object space". They // were transformed to "world space" prior to being rendered. So, we need to transform the mouse click coordinates from "world space" to // the facial point "local/object space". Matrix3x2 inverseOfRenderTargetTransform = new Matrix3x2(); Matrix3x2.Invert(ref this.transformation, out inverseOfRenderTargetTransform); Size2F renderTargetSize = this.d2dRenderTarget.Size; System.Drawing.Rectangle clientSize = this.renderForm.ClientRectangle; float scalingFromClientToRenderTargetX = renderTargetSize.Width / clientSize.Right; float scalingFromClientToRenderTargetY = renderTargetSize.Height / clientSize.Bottom; Vector2 renderTargetClickCoord = new Vector2(e.X * scalingFromClientToRenderTargetX, e.Y * scalingFromClientToRenderTargetY); Vector2 transformedRenderTargetClickCoord = Matrix3x2.TransformPoint(inverseOfRenderTargetTransform, renderTargetClickCoord); RectangleF transformedRenderTargetClickArea = new RectangleF(transformedRenderTargetClickCoord.X, transformedRenderTargetClickCoord.Y, ClickSize, ClickSize); this.selectedFacePointIndex = null; for (int pointIndex = 0; pointIndex < this.facePoints.Length; pointIndex++) { if (transformedRenderTargetClickArea.Contains(this.facePoints[pointIndex])) { this.selectedFacePointIndex = pointIndex; break; } } this.selectedFacePointTimeout = this.framesPerSecond.RunTime.Add(new TimeSpan(0, 0, EventTimeoutSeconds)); }
public void DoIteration(SkeletonInputs inputs, Bone sourceBone, Vector2 unposedSource, Vector2 target) { Vector2 source = Matrix3x2.TransformPoint(sourceBone.GetChainedTransform(inputs), sourceBone.End); Vector <float> residuals = Vector <float> .Build.Dense(2); residuals[0] = target.X - source.X; residuals[1] = target.Y - source.Y; List <Bone> bones = GetBoneChain(sourceBone).ToList(); int boneCount = bones.Count; Matrix <float> jacobian = Matrix <float> .Build.Dense(2, boneCount + 2); for (int boneIdx = 0; boneIdx < boneCount; ++boneIdx) { Vector2 boneGradient = bones[boneIdx].GetGradientOfTransformedPointWithRespectToRotation(inputs, source); jacobian[0, boneIdx] = boneGradient.X; jacobian[1, boneIdx] = boneGradient.Y; } jacobian[0, boneCount + 0] = RootTranslationWeight; jacobian[1, boneCount + 1] = RootTranslationWeight; Vector <float> step = jacobian.PseudoInverse().Multiply(residuals); for (int boneIdx = 0; boneIdx < boneCount; ++boneIdx) { var bone = bones[boneIdx]; bone.IncrementRotation(inputs, step[boneIdx]); } Vector2 rootTranslationStep = new Vector2( step[boneCount + 0], step[boneCount + 1]); inputs.Translation += rootTranslationStep * RootTranslationWeight; }
protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources) { Width = 0; Height = 0; // http://www.cyotek.com/blog/angelcode-bitmap-font-parsing-using-csharp var tempList = new List <BillboardVertex>(100); foreach (var textInfo in TextInfo) { int tempPrevCount = tempList.Count; int x = 0; int y = 0; var w = BitmapFont.TextureSize.Width; var h = BitmapFont.TextureSize.Height; char previousCharacter; previousCharacter = ' '; var normalizedText = textInfo.Text; var rect = new RectangleF(textInfo.Origin.X, textInfo.Origin.Y, 0, 0); foreach (char character in normalizedText) { switch (character) { case '\n': x = 0; y -= BitmapFont.LineHeight; break; default: Character data = BitmapFont[character]; int kerning = BitmapFont.GetKerning(previousCharacter, character); tempList.Add(DrawCharacter(data, new Vector3(x + data.Offset.X, y - data.Offset.Y, 0), w, h, kerning, textInfo)); x += data.XAdvance + kerning; break; } previousCharacter = character; if (tempList.Count > 0) { rect.Width = Math.Max(rect.Width, x * textInfo.Scale * textureScale); rect.Height = Math.Max(rect.Height, Math.Abs(tempList.Last().OffBR.Y)); } } var transform = textInfo.Angle != 0 ? Matrix3x2.Rotation(textInfo.Angle) : Matrix3x2.Identity; var halfW = rect.Width / 2; var halfH = rect.Height / 2; //Add backbround vertex first. This also used for hit test BillboardVertices.Add(new BillboardVertex() { Position = textInfo.Origin.ToVector4(), Background = textInfo.Background, TexTL = Vector2.Zero, TexBR = Vector2.Zero, OffTL = Matrix3x2.TransformPoint(transform, new Vector2(-halfW, halfH)), OffBR = Matrix3x2.TransformPoint(transform, new Vector2(halfW, -halfH)), OffTR = Matrix3x2.TransformPoint(transform, new Vector2(-halfW, -halfH)), OffBL = Matrix3x2.TransformPoint(transform, new Vector2(halfW, halfH)), }); textInfo.UpdateTextInfo(rect.Width, rect.Height); for (int k = tempPrevCount; k < tempList.Count; ++k) { var v = tempList[k]; v.OffTL = Matrix3x2.TransformPoint(transform, v.OffTL + new Vector2(-halfW, halfH)); v.OffBR = Matrix3x2.TransformPoint(transform, v.OffBR + new Vector2(-halfW, halfH)); v.OffTR = Matrix3x2.TransformPoint(transform, v.OffTR + new Vector2(-halfW, halfH)); v.OffBL = Matrix3x2.TransformPoint(transform, v.OffBL + new Vector2(-halfW, halfH)); tempList[k] = v; } Width += rect.Width; Height += rect.Height; } foreach (var v in tempList) { BillboardVertices.Add(v); } }
private void DrawCircle(decimal currentValue, decimal maxValue, int thisIndex, int selectedIndex) { int partyIndex = (Party.PartySize - 4) * -1; PointF location = new PointF(Config.CooldownBarLocation.X + (Config.CooldownBarXOffset * thisIndex), Config.CooldownBarLocation.Y + (Config.CooldownBarXOffset != 0 ? 0 : ((Config.CooldownBarYOffsets[partyIndex] * thisIndex) + Config.PartyNumBarOffsets[partyIndex]))); if (thisIndex == selectedIndex) { if (Config.CooldownBarYOffsets[partyIndex] > 0) { location.X += Config.CooldownBarSelOffset; } else { location.Y += Config.CooldownBarSelOffset; } } int scale = Config.CooldownBarSize.Height; int lineWidth = Config.CooldownBarSize.Width; bool drawPie = Config.CooldownBarSize.Width > Config.CooldownBarSize.Height * 2; int val = (int)(360 - (360 * (currentValue / (maxValue + 0.01M)))); Vector2 circleCenter = new Vector2(location.X, location.Y); Vector2 circleStart = new Vector2(circleCenter.X, circleCenter.Y - scale); Vector2 circleStartBG = new Vector2(circleCenter.X, circleCenter.Y + scale); float thetaDegrees = (float)(val * 0.0174533); float thetaDegreesBG = (float)((360 - (180 - val)) * 0.0174533); Vector2 circleEnd = Matrix3x2.TransformPoint(Matrix3x2.Rotation(thetaDegrees, circleCenter), circleStart); Vector2 circleEndBG = Matrix3x2.TransformPoint(Matrix3x2.Rotation(thetaDegreesBG, circleCenter), circleStartBG); float dx = circleStart.X - circleCenter.X; float dy = circleStart.Y - circleCenter.Y; float radius = (float)Math.Sqrt(dx * dx + dy * dy); if (val < 360 && BGColorBrush.Color.A > 0 && ((thisIndex != selectedIndex && FG1ColorBrush.Color.A > 0) || (thisIndex == selectedIndex && SELColorBrush.Color.A > 0))) { using (PathGeometry pathGeometry = new PathGeometry(Factory)) { using (GeometrySink geometrySink = pathGeometry.Open()) { if (val <= 180) { geometrySink.BeginFigure(drawPie ? circleCenter : circleStartBG, FigureBegin.Filled); if (drawPie) { geometrySink.AddLine(circleStartBG); } geometrySink.AddArc(new ArcSegment() { Point = (val == 0) ? circleStart : circleEndBG, Size = new Size2F(radius, radius), RotationAngle = 0.0f, SweepDirection = SweepDirection.CounterClockwise, ArcSize = ArcSize.Small }); geometrySink.EndFigure(drawPie ? FigureEnd.Closed : FigureEnd.Open); } geometrySink.BeginFigure(drawPie ? circleCenter : circleStart, FigureBegin.Filled); if (drawPie) { geometrySink.AddLine(circleStart); } geometrySink.AddArc(new ArcSegment() { Point = (val <= 180) ? circleStartBG : circleEndBG, Size = new Size2F(radius, radius), RotationAngle = 0.0f, SweepDirection = SweepDirection.CounterClockwise, ArcSize = ArcSize.Small }); geometrySink.EndFigure(drawPie ? FigureEnd.Closed : FigureEnd.Open); geometrySink.Close(); if (drawPie) { Render.FillGeometry(pathGeometry, BGColorBrush); } else { //using(StrokeStyle strokeStyle = new StrokeStyle(Factory, // new StrokeStyleProperties() { DashCap = CapStyle.Flat, DashStyle = DashStyle.Solid, LineJoin = LineJoin.Miter, StartCap = CapStyle.Flat, EndCap = CapStyle.Flat, MiterLimit = 0, DashOffset = 0 })) { //} Render.DrawGeometry(pathGeometry, BGColorBrush, lineWidth); //, strokeStyle); } } } } if ((thisIndex != selectedIndex && FG1ColorBrush.Color.A > 0) || (thisIndex == selectedIndex && SELColorBrush.Color.A > 0) || (FG2ColorBrush.Color.A > 0 && val == 360)) { using (PathGeometry pathGeometry = new PathGeometry(Factory)) { using (GeometrySink geometrySink = pathGeometry.Open()) { geometrySink.BeginFigure(drawPie ? circleCenter : circleStart, FigureBegin.Filled); if (drawPie) { geometrySink.AddLine(circleStart); } geometrySink.AddArc(new ArcSegment() { Point = (val > 180) ? new Vector2(circleStart.X, circleStart.Y + (radius * 2)) : circleEnd, Size = new Size2F(radius, radius), RotationAngle = 0.0f, SweepDirection = SweepDirection.Clockwise, ArcSize = ArcSize.Small }); geometrySink.EndFigure(drawPie ? FigureEnd.Closed : FigureEnd.Open); if (val > 180) { geometrySink.BeginFigure(drawPie ? circleCenter : new Vector2(circleStart.X, circleStart.Y + (radius * 2)), FigureBegin.Filled); if (drawPie) { geometrySink.AddLine(new Vector2(circleStart.X, circleStart.Y + (radius * 2))); } geometrySink.AddArc(new ArcSegment() { Point = circleEnd, Size = new Size2F(radius, radius), RotationAngle = 0.0f, SweepDirection = SweepDirection.Clockwise, ArcSize = ArcSize.Small }); geometrySink.EndFigure(drawPie ? FigureEnd.Closed : FigureEnd.Open); } geometrySink.Close(); if (drawPie) { Render.FillGeometry(pathGeometry, val == 360 ? FG2ColorBrush : thisIndex != selectedIndex ? FG1ColorBrush : SELColorBrush); } else { //using(StrokeStyle strokeStyle = new StrokeStyle(Factory, // new StrokeStyleProperties() { DashCap = CapStyle.Flat, DashStyle = DashStyle.Solid, LineJoin = LineJoin.Miter, StartCap = CapStyle.Flat, EndCap = CapStyle.Flat, MiterLimit = 0, DashOffset = 0 })) { //} Render.DrawGeometry(pathGeometry, val == 360 ? FG2ColorBrush : thisIndex != selectedIndex ? FG1ColorBrush : SELColorBrush, lineWidth); //, strokeStyle); } } } } if (Config.CooldownBarTextFontSize > 0 && Config.CooldownBarTextFontSize > 0 && val == 360 && FG2TColorBrush.Color.A > 0) { DrawText(Config.CooldownBarTextReady != "" ? Config.CooldownBarTextReady : FormatDecimalToString(currentValue, Config.CooldownBarTextDecimal), circleCenter.X + Config.CooldownBarTextOffset.X, circleCenter.Y + Config.CooldownBarTextOffset.Y, FG2TColorBrush, BGTColorBrush); } else if (Config.CooldownBarTextFontSize > 0 && Config.CooldownBarTextFontSize > 0 && val < 360 && thisIndex != selectedIndex && FG1TColorBrush.Color.A > 0) { DrawText(FormatDecimalToString(currentValue, Config.CooldownBarTextDecimal), circleCenter.X + Config.CooldownBarTextOffset.X, circleCenter.Y + Config.CooldownBarTextOffset.Y, FG1TColorBrush, BGTColorBrush); } else if (Config.CooldownBarTextFontSize > 0 && Config.CooldownBarTextFontSize > 0 && val < 360 && thisIndex == selectedIndex && SELTColorBrush.Color.A > 0) { DrawText(FormatDecimalToString(currentValue, Config.CooldownBarTextDecimal), circleCenter.X + Config.CooldownBarTextOffset.X, circleCenter.Y + Config.CooldownBarTextOffset.Y, SELTColorBrush, BGTColorBrush); } }
public static Vector2 RotateBy(float rotation, Vector2 v) { return(Matrix3x2.TransformPoint(Matrix3x2.Rotation(rotation), v)); }
public void DoIteration(SkeletonInputs inputs, Bone sourceBone, Vector2 unposedSource, Vector2 target) { Vector2 source = Matrix3x2.TransformPoint(sourceBone.GetChainedTransform(inputs), sourceBone.End); List <Bone> bones = GetBoneChain(sourceBone).ToList(); int boneCount = bones.Count; Vector <float> residuals = Vector <float> .Build.Dense(boneCount * 2 + 2); for (int boneIdx = 0; boneIdx < boneCount; ++boneIdx) { var bone = bones[boneIdx]; var posedCenter = Matrix3x2.TransformPoint(bone.GetChainedTransform(inputs), bone.Center); var residual = bone.Center - posedCenter; //var residual = Vector2.Zero; residuals[boneIdx * 2 + 0] = BoneCenterWeight * residual.X; residuals[boneIdx * 2 + 1] = BoneCenterWeight * residual.Y; } residuals[boneCount * 2 + 0] = IkTargetWeight * (target.X - source.X); residuals[boneCount * 2 + 1] = IkTargetWeight * (target.Y - source.Y); Matrix <float> jacobian = Matrix <float> .Build.Dense(2 *boneCount + 2, boneCount); for (int boneIdx = 0; boneIdx < boneCount; ++boneIdx) { for (int targetIdx = 0; targetIdx < boneCount + 1; ++targetIdx) { Vector2 boneGradient; if (targetIdx > boneIdx && targetIdx != boneCount) { //target is unaffected by this bone boneGradient = Vector2.Zero; } else { Vector2 targetSource; float weight; if (targetIdx < boneCount) { //target is a bone center var targetBone = bones[targetIdx]; targetSource = Matrix3x2.TransformPoint(targetBone.GetChainedTransform(inputs), targetBone.Center); weight = BoneCenterWeight; } else { //target is IK target targetSource = source; weight = IkTargetWeight; } boneGradient = weight * bones[boneIdx].GetGradientOfTransformedPointWithRespectToRotation(inputs, targetSource); } jacobian[targetIdx * 2 + 0, boneIdx] = boneGradient.X; jacobian[targetIdx * 2 + 1, boneIdx] = boneGradient.Y; } } Vector <float> step = jacobian.PseudoInverse().Multiply(residuals); for (int boneIdx = 0; boneIdx < boneCount; ++boneIdx) { var bone = bones[boneIdx]; bone.IncrementRotation(inputs, step[boneIdx]); } }
/// <summary> /// 将指定的拼图原始坐标转换为拼图坐标。 /// </summary> /// <param name="point">要转换的点。</param> /// <returns>转换得到的结果。</returns> private Vector2 PointToJigsaw(Vector2 point) { return(Matrix3x2.TransformPoint(this.TransformMatrix, point)); }
public Vector2 InvertTransformPoint(Matrix3x2 matrix, Vector2 point) { matrix.Invert(); return(Matrix3x2.TransformPoint(matrix, point)); }