public static Scene MakeMultiTouchScene() { Trail <Vector2>[] touch = new Trail <Vector2> [Input2.Touch.MaxTouch]; Grid[] trail_polys = new Grid[Input2.Touch.MaxTouch]; for (int i = 0; i < touch.Length; ++i) { touch[i] = new Trail <Vector2>(16); } Vector2i grid_size = new Vector2i(20, 24); for (int i = 0; i < trail_polys.Length; ++i) { trail_polys[i] = new Grid(grid_size); } Vector2[] curve_points = new Vector2[grid_size.Y]; Vector2[] circle_points = new Vector2[grid_size.X]; for (int i = 0; i < circle_points.Length; ++i) { circle_points[i] = Vector2.Rotation(Math.TwicePi * (float)i / (float)(circle_points.Length - 1)); } List <Vector2> control_points = new List <Vector2>(); Vector4[] colors = { // Colors.Black, Colors.Red, Colors.Green, Colors.Yellow, Colors.Blue, Colors.Magenta, Colors.Cyan, Colors.White, Colors.Lime, Colors.LightBlue, Colors.Pink, Colors.Orange, Colors.LightCyan, Colors.Purple, }; var scene = new Scene(); { var info = new Label(); info.Camera = UICamera; info.Position = UICamera.CalcBounds().Point00; info.FontMap = UIFontMap; info.HeightScale = UICamera.GetPixelSize(); info.Text = "try touch the screen at multiple points at the same time"; scene.AddChild(info); } scene.OnExitEvents += () => { foreach (Grid grid in trail_polys) { grid.Dispose(); } trail_polys = null; }; scene.AdHocDraw += () => { BlendFunc blend_func = Director.Instance.GL.Context.GetBlendFunc(); DepthFunc depth_func = Director.Instance.GL.Context.GetDepthFunc(); for (int k = 0; k < touch.Length; ++k) { bool down = Input2.Touch.GetData(0)[k].Down; bool press = Input2.Touch.GetData(0)[k].Press; Vector2 p = Director.Instance.CurrentScene.GetTouchPos(k); if (!down) { continue; } // press means a new touch data has just been "created" // -> fill the whole trail to the new position if (press) { touch[k].Fill(p); } touch[k].Add(p); control_points.Clear(); control_points.Add(touch[k].At(0)); for (int i = 0; i < touch[k].Count; ++i) { control_points.Add(touch[k].At(i)); } { Vector4 start_color = colors[k]; Vector4 end_color = Math.SetAlpha(start_color, 0.0f); float start_radius = 2.0f; float end_radius = 1.8f; Grid grid = trail_polys[k]; for (int i = 0; i < curve_points.Length; ++i) { curve_points[i] = Curves.CatmullRom((float)i / (float)(curve_points.Length - 1), control_points, false); } for (int j = 0; j < grid.Size.Y; ++j) { float y = (float)j / (float)(grid.Size.Y - 1); for (int i = 0; i < grid.Size.X; ++i) { grid.TmpVertices[i + j * grid.Size.X] = new DrawHelpers.Vertex((curve_points[j] + circle_points[i] * Math.Lerp(start_radius, end_radius, y)).Xy01 , Math.Lerp(start_color, end_color, y)); } } grid.VertexBuffer.SetVertices(grid.TmpVertices, 0, 0, grid.NumVertices); Director.Instance.GL.SetBlendMode(BlendMode.Normal); Director.Instance.DrawHelpers.ShaderPush(); grid.Draw(); { Director.Instance.DrawHelpers.ImmBegin(DrawMode.TriangleFan, (uint)grid.Size.X); for (int i = 0; i < grid.Size.X; ++i) { Director.Instance.DrawHelpers.ImmVertex(new DrawHelpers.Vertex((curve_points[0] + circle_points[i] * start_radius).Xy01 , start_color)); } Director.Instance.DrawHelpers.ImmEnd(); } Director.Instance.DrawHelpers.ShaderPop(); } } // restore states Director.Instance.GL.Context.Disable(EnableMode.DepthTest); Director.Instance.GL.Context.SetDepthFunc(depth_func); Director.Instance.GL.Context.SetBlendFunc(blend_func); }; return(scene); }