private void RenderToTexture() { if (FrameSize.X > 0 && FrameSize.Y > 0) { RenderTexture.SetAsRenderTarget(); Renderer.PushState( RenderState.Viewport | RenderState.World | RenderState.View | RenderState.Projection | RenderState.DepthState | RenderState.ScissorState | RenderState.StencilState | RenderState.CullMode | RenderState.Transform2); try { Renderer.ScissorState = ScissorState.ScissorDisabled; Renderer.StencilState = StencilState.Default; Renderer.Viewport = new Viewport(0, 0, RenderTexture.ImageSize.Width, RenderTexture.ImageSize.Height); Renderer.Clear(new Color4(0, 0, 0, 0)); Renderer.World = Renderer.View = Matrix44.Identity; Renderer.SetOrthogonalProjection(0, 0, FrameSize.X, FrameSize.Y); Renderer.DepthState = DepthState.DepthDisabled; Renderer.CullMode = CullMode.None; Renderer.Transform2 = LocalToWorldTransform.CalcInversed(); Objects.Render(); } finally { RenderTexture.RestoreRenderTarget(); Renderer.PopState(); } } }
bool PartHitTest(Part part, Vector2 point) { point = LocalToWorldTransform.CalcInversed().TransformVector(point); if (part.Rect.BX < part.Rect.AX) { part.Rect.AX = -part.Rect.AX; part.Rect.BX = -part.Rect.BX; point.X = -point.X; } if (part.Rect.BY < part.Rect.AY) { part.Rect.AY = -part.Rect.AY; part.Rect.BY = -part.Rect.BY; point.Y = -point.Y; } if (point.X >= part.Rect.AX && point.Y >= part.Rect.AY && point.X < part.Rect.BX && point.Y < part.Rect.BY) { float uf = (point.X - part.Rect.AX) / part.Rect.Width * part.UV.Width + part.UV.AX; float vf = (point.Y - part.Rect.AY) / part.Rect.Height * part.UV.Height + part.UV.AY; int ui = (int)(Texture.ImageSize.Width * uf); int vi = (int)(Texture.ImageSize.Height * vf); return(!Texture.IsTransparentPixel(ui, vi)); } return(false); }
internal protected override bool PartialHitTestByContents(ref HitTestArgs args) { Vector2 localPoint = LocalToWorldTransform.CalcInversed().TransformVector(args.Point); Vector2 size = Size; if (size.X < 0) { localPoint.X = -localPoint.X; size.X = -size.X; } if (size.Y < 0) { localPoint.Y = -localPoint.Y; size.Y = -size.Y; } if (localPoint.X >= 0 && localPoint.Y >= 0 && localPoint.X < size.X && localPoint.Y < size.Y) { int u = (int)(Texture.ImageSize.Width * (localPoint.X / size.X)); int v = (int)(Texture.ImageSize.Height * (localPoint.Y / size.Y)); return(!Texture.IsTransparentPixel(u, v)); } else { return(false); } }
protected internal override bool PartialHitTestByContents(ref HitTestArgs args) { Vector2 localPoint = LocalToWorldTransform.CalcInversed().TransformVector(args.Point); Vector2 size = Size; if (size.X < 0) { localPoint.X = -localPoint.X; size.X = -size.X; } if (size.Y < 0) { localPoint.Y = -localPoint.Y; size.Y = -size.Y; } for (int i = 0; i < (NumRows + 1) * NumCols; i++) { if ((i + 1) % (NumCols + 1) == 0) { continue; } var n1 = (DistortionMeshPoint)Nodes[i]; var n2 = (DistortionMeshPoint)Nodes[i + NumCols + 1]; var n3 = (DistortionMeshPoint)Nodes[i + NumCols + 2]; var n4 = (DistortionMeshPoint)Nodes[i + 1]; var v1 = (n1.TransformedPosition, n1.UV); var v2 = (n2.TransformedPosition, n2.UV); var v3 = (n3.TransformedPosition, n3.UV); var v4 = (n4.TransformedPosition, n4.UV); var center = ( (v1.TransformedPosition + v2.TransformedPosition + v3.TransformedPosition + v4.TransformedPosition) * .25f, (v1.UV + v2.UV + v3.UV + v4.UV) * .25f ); if ( HitTest(localPoint, v1, center, v2) || HitTest(localPoint, v2, center, v3) || HitTest(localPoint, v3, center, v4) || HitTest(localPoint, v4, center, v1) ) { return(true); } } return(false); }
public Ray ScreenPointToRay(Vector3 pt) { var xy = LocalToWorldTransform.CalcInversed().TransformVector((Vector2)pt); return(ViewportPointToRay(new Vector3(xy, pt.Z))); }
public Vector3 WorldToScreenPoint(Vector3 pt) { pt = WorldToViewportPoint(pt); return(new Vector3(LocalToWorldTransform.TransformVector((Vector2)pt), pt.Z)); }