/// <inheritdoc cref="NotuiElement"/> public override IntersectionPoint PureHitTest(Touch touch, bool prevpos, out IntersectionPoint persistentIspoint) { var intersection = PreparePlanarShapeHitTest(touch, prevpos); var phit = intersection != null; if (!phit) { persistentIspoint = null; return(null); } //TODO: Ugly as f**k, fix phase like a human being var uvpos = Coordinates.RectToPolar(Vector2.Transform(intersection.ElementSpace.xy(), Matrix3x2.CreateRotation((float)Math.PI))); var d = uvpos.Y; uvpos.X = uvpos.X / (float)Math.PI; uvpos.Y = uvpos.Y * 4 - 1; intersection.SurfaceSpace = new Vector3(uvpos, 0); var str = Matrix4x4.CreateWorld(intersection.ElementSpace, Vector3.UnitZ, -Vector3.Normalize(intersection.ElementSpace)); intersection.WorldSurfaceTangentTransform = str * DisplayMatrix; persistentIspoint = intersection; return(d < 0.5 ? intersection : null); }
/// <inheritdoc cref="NotuiElement"/> public override IntersectionPoint PureHitTest(Touch touch, bool prevpos, out IntersectionPoint persistentIspoint) { var intersection = PreparePlanarShapeHitTest(touch, prevpos); var phit = intersection != null; if (!phit) { persistentIspoint = null; return(null); } //var polar = Coordinates.RectToPolar(intersection.ElementSpace.xy()); //polar.X = (float)Math.PI + (polar.X - Phase * (float)Math.PI*2) * Math.Sign(Cycles); var rad = Math.Max(HoleRadius, 1); var hrad = Math.Min(HoleRadius, 1); var uvpos = Coordinates.RectToPolar( Vector2.Transform( intersection.ElementSpace.xy(), Matrix3x2.CreateRotation((-Phase + 0.5f) * 2.0f * (float)Math.PI) ) ); uvpos.X = Cycles > 0 ? (float)VMath.Map(uvpos.X / (float)Math.PI, -1, Cycles * 2 - 1, -1, 1, TMapMode.Float) : (float)VMath.Map(uvpos.X / (float)Math.PI, 1, 1 + Cycles * 2, -1, 1, TMapMode.Float); uvpos.Y = HoleRadius > 1 ? (float)VMath.Map(uvpos.Y * 2, hrad, rad, -1, 1, TMapMode.Float) : (float)VMath.Map(uvpos.Y * 2, hrad, rad, 1, -1, TMapMode.Float); intersection.SurfaceSpace = new Vector3(uvpos, 0); var str = Matrix4x4.CreateWorld(intersection.ElementSpace, Vector3.UnitZ, -Vector3.Normalize(intersection.ElementSpace)); intersection.WorldSurfaceTangentTransform = str * DisplayMatrix; //var hit = polar.Y * 2 < rad && polar.Y * 2 >= hrad && (polar.X + Math.PI) % (Math.PI * 2) <= Math.Abs(Cycles * Math.PI * 2); var hit = uvpos.X > -1 && uvpos.X <1 && uvpos.Y> -1 && uvpos.Y < 1; persistentIspoint = intersection; return(hit ? intersection : null); }