UrhoSharp Examples

BeanzBeanz Member ✭✭
edited December 2018 in Xamarin.iOS

Hey Guys,

I am using @EgorBo 's UrhoSharp example, I am replicating something similar to his RulerDemo.

What I would like to know is if there is a way to make the line / a line visible between the starting point and the new point during the

OnTouchMove

I thought I could possibly just move it into that method instead :neutral: shamefully not that easy

But basically heres an image of what I would like to do

Just the displaying of the line, but not commiting the node / line until I have raised my finger

As currently it is placing a node for every touch / hold while I am moving it much like in the video, but would prefer a free form line from the last point to where my finger currently is

http://gifmaker.me/PlayVideoAnimation.php?folder=2018120402Dh320MLyWeCxB3ML2Z1Bmo&file=output_UQCOUt.mp4

Much like that

Best Answer

  • BeanzBeanz ✭✭
    edited December 2018 Accepted Answer

    @LandLu said:
    Could you please share your sample? And which part are you getting stuck?

    Yeah of course

    ~~~~ void AddConnection(Node point1, Node point2 = null)
        {
            const float size = 0.02f;
            var node = Scene.CreateChild();
            node.Name = "Test";
            c = point1;
            Vector3 v1 = point1.Position;
            Vector3 v2 = point2?.Position ?? Vector3.Zero;
            var distance = Vector3.Distance(v2, v1);
            node.Scale = new Vector3(size, Math.Abs(distance), size);
            if (!c.GetNull())
            {
                c = point1;
            }
            node.Position = (v1 + v2) / 2f;
            node.Rotation = Quaternion.FromRotationTo(Vector3.UnitY, v1 - v2);
            var cylinder = node.CreateComponent<StaticModel>();
            cylinder.Model = CoreAssets.Models.Cylinder;
            cylinder.CastShadows = false;
            cylinder.SetMaterial(Material.FromColor(Color.White, true));
            node.RunActions(new TintTo(1f, 0f, 1f, 1f, 1f));
        } ~~~~
    

    So I have modified the AddConnection method now, and have just basically used the current pointer as the new location and it works.....

    My next question would be, how do I do this on finger drag rather than scene move

    private void OnTouchMoved(TouchMoveEventArgs obj)
            {
    
                if (pointerNode != null)
                {
                    var container = Scene.GetChild("Test", true);
    
                    if (!container.GetNull())
                    {
                        container.Remove();
    
                        //c is previous nodePoint
                AddConnection(c, pointerNode);
                    }
                }
            }
    

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Could you please share your sample? And which part are you getting stuck?

  • BeanzBeanz Member ✭✭
    edited December 2018 Accepted Answer

    @LandLu said:
    Could you please share your sample? And which part are you getting stuck?

    Yeah of course

    ~~~~ void AddConnection(Node point1, Node point2 = null)
        {
            const float size = 0.02f;
            var node = Scene.CreateChild();
            node.Name = "Test";
            c = point1;
            Vector3 v1 = point1.Position;
            Vector3 v2 = point2?.Position ?? Vector3.Zero;
            var distance = Vector3.Distance(v2, v1);
            node.Scale = new Vector3(size, Math.Abs(distance), size);
            if (!c.GetNull())
            {
                c = point1;
            }
            node.Position = (v1 + v2) / 2f;
            node.Rotation = Quaternion.FromRotationTo(Vector3.UnitY, v1 - v2);
            var cylinder = node.CreateComponent<StaticModel>();
            cylinder.Model = CoreAssets.Models.Cylinder;
            cylinder.CastShadows = false;
            cylinder.SetMaterial(Material.FromColor(Color.White, true));
            node.RunActions(new TintTo(1f, 0f, 1f, 1f, 1f));
        } ~~~~
    

    So I have modified the AddConnection method now, and have just basically used the current pointer as the new location and it works.....

    My next question would be, how do I do this on finger drag rather than scene move

    private void OnTouchMoved(TouchMoveEventArgs obj)
            {
    
                if (pointerNode != null)
                {
                    var container = Scene.GetChild("Test", true);
    
                    if (!container.GetNull())
                    {
                        container.Remove();
    
                        //c is previous nodePoint
                AddConnection(c, pointerNode);
                    }
                }
            }
    
Sign In or Register to comment.