Ejemplo n.º 1
0
        public TrajectoryModel3D(Trajectory track, double thickness, double coeff = 1)
        {
            this.coeff                   = coeff;
            this.pointRadius             = thickness * this.coeff / 2;
            this.trackLineRadius         = this.pointRadius * 0.90;
            this.track                   = track;
            this.trackModelVisual3D      = new List <ModelVisual3D>();
            this.splitTrackModelVisual3D = new List <ModelVisual3D>();

            this.trackModelVisual3D.Add(
                this.CreateAnchorPointModelVisual3D(VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[0], this.coeff), this.pointRadius));
            for (var i = 1; i < this.track.AnchorPoints.Count; i++)
            {
                var trackLineMV3D = this.CreateTrajectoryLineModelVisual3D(
                    VRConvert.ConvertFromRealToVirtual(
                        this.track.AnchorPoints[i - 1],
                        this.coeff),
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[i], this.coeff),
                    this.trackLineRadius);

                this.trackModelVisual3D.Add(trackLineMV3D);
                this.trackModelVisual3D.Add(
                    this.CreateAnchorPointModelVisual3D(VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[i], this.coeff), this.pointRadius));
            }

            foreach (var splitPoint in this.track.SplitPoints)
            {
                this.splitTrackModelVisual3D.Add(
                    this.CreateSplitPointModelVisual3D(VRConvert.ConvertFromRealToVirtual(splitPoint, this.coeff)));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Change z coordinate of anchor point
        /// </summary>
        /// <param name="indexOfAnchorPoint"> begin from second point of trajectory,
        /// because first point pinned to manipulator end point</param>
        /// <param name="deltaZ">real deltaZ in cm</param>
        public void ChangeAnchorPointZ(int indexOfAnchorPoint, double deltaZ)
        {
            if (indexOfAnchorPoint == 0)
            {
                throw new Exception("Can't change z coordinate of first trajectory point!");
            }

            this.track.AnchorPointOffsetZ(indexOfAnchorPoint, deltaZ);

            ((TranslateTransform3D)this.trackModelVisual3D[indexOfAnchorPoint * 2].Transform).OffsetZ += deltaZ * this.coeff;

            if (indexOfAnchorPoint == this.track.AnchorPoints.Count - 1)
            {
                this.trackModelVisual3D[indexOfAnchorPoint * 2 - 1] = this.CreateTrajectoryLineModelVisual3D(
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[indexOfAnchorPoint - 1], this.coeff),
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[indexOfAnchorPoint], this.coeff),
                    this.trackLineRadius);
            }
            else
            {
                this.trackModelVisual3D[indexOfAnchorPoint * 2 - 1] = this.CreateTrajectoryLineModelVisual3D(
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[indexOfAnchorPoint - 1], this.coeff),
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[indexOfAnchorPoint], this.coeff),
                    this.trackLineRadius);
                this.trackModelVisual3D[indexOfAnchorPoint * 2 + 1] = this.CreateTrajectoryLineModelVisual3D(
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[indexOfAnchorPoint], this.coeff),
                    VRConvert.ConvertFromRealToVirtual(this.track.AnchorPoints[indexOfAnchorPoint + 1], this.coeff),
                    this.trackLineRadius);
            }
        }
Ejemplo n.º 3
0
        public void BuildModelVisual3DCollection(double thickness)
        {
            var boneRadius  = thickness * this.coeff / 2;
            var jointRadius = (thickness * this.coeff / 2) * 1.7;

            var sup = new Point3D(0, 0, 0);   // Start Unit Point
            var eup = (Point3D)this.arm.F(0); // End Unit Point

            // Zero unit of arm:
            this.armModelVisual3D.Add(
                this.CreateArmBoneModelVisual3D(
                    VRConvert.ConvertFromRealToVirtual(sup, this.coeff),
                    VRConvert.ConvertFromRealToVirtual(eup, this.coeff),
                    boneRadius));
            var jointBrush = Brushes.Black;

            this.armModelVisual3D.Add(
                this.CreateArmJointModelVisual3D(VRConvert.ConvertFromRealToVirtual(eup, this.coeff), jointRadius, jointBrush));

            sup = eup;

            // 'P' and 'R' units:
            for (var i = 0; i < this.arm.N; i++)
            {
                eup = (Point3D)this.arm.F(i + 1);

                var axis = VRConvert.ConvertFromRealToVirtual(this.arm.GetZAxis(i), this.coeff);
                MathFunctions.Normalize(axis);

                jointBrush = this.arm.Units[i].Type == 'R' ? Brushes.OrangeRed : Brushes.Green;
                this.armModelVisual3D.Add(
                    this.CreateArmJointModelVisual3D(
                        VRConvert.ConvertFromRealToVirtual(sup, this.coeff),
                        jointRadius,
                        jointBrush,
                        i + 1,
                        axis));

                this.armModelVisual3D.Add(
                    this.CreateArmBoneModelVisual3D(
                        VRConvert.ConvertFromRealToVirtual(sup, this.coeff),
                        VRConvert.ConvertFromRealToVirtual(eup, this.coeff),
                        boneRadius,
                        i + 1));

                sup = eup;
            }

            // Grip unit:
            jointBrush = Brushes.Blue;
            this.armModelVisual3D.Add(
                this.CreateArmJointModelVisual3D(
                    VRConvert.ConvertFromRealToVirtual(sup, this.coeff),
                    jointRadius,
                    jointBrush,
                    this.arm.N));
        }
Ejemplo n.º 4
0
    void OnVREvent(VREvent e)
    {
        if (e.Name == headTrackingEvent)
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray(matrix4x4DataField));
            transform.position = m.GetTranslation();
            transform.rotation = m.GetRotation();
            //Debug.Log("Head Position = " + m.GetTranslation().ToString());
            //Debug.Log("Head Rotation = " + m.GetRotation().ToString());

            Vector3 offsetInLocalCoords = new Vector3(0.0f, 0.0f, Camera.main.nearClipPlane + 0.001f);
            Vector3 offsetInWorldCoords = transform.TransformVector(offsetInLocalCoords);
            transform.position += offsetInWorldCoords;
        }
    }
Ejemplo n.º 5
0
        public void AddAnchorPoint(Point3D newVirtualPoint)
        {
            this.track.AddAnchorPoint(VRConvert.ConvertFromVirtualToReal(newVirtualPoint, this.coeff));

            var trackLineMV3D = this.CreateTrajectoryLineModelVisual3D(
                VRConvert.ConvertFromRealToVirtual(
                    this.track.AnchorPoints[this.track.AnchorPoints.Count - 2],
                    this.coeff),
                newVirtualPoint,
                this.trackLineRadius);
            var trackAnchorPointMV3D = this.CreateAnchorPointModelVisual3D(newVirtualPoint, this.pointRadius);

            this.trackModelVisual3D.Add(trackLineMV3D);
            this.trackModelVisual3D.Add(trackAnchorPointMV3D);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="with3DLines"> if it false then only track points will be displayed</param>
        public void ShowInterpolatedTrack(bool with3DLines)
        {
            this.splitTrackModelVisual3D.Add(
                this.CreateAnchorPointModelVisual3D(VRConvert.ConvertFromRealToVirtual(this.track.SplitPoints[0], this.coeff), this.pointRadius));
            for (var i = 1; i < this.track.SplitPoints.Count; i++)
            {
                if (with3DLines)
                {
                    var trackLineMV3D = this.CreateTrajectoryLineModelVisual3D(
                        VRConvert.ConvertFromRealToVirtual(
                            this.track.SplitPoints[i - 1],
                            this.coeff),
                        VRConvert.ConvertFromRealToVirtual(this.track.SplitPoints[i], this.coeff),
                        this.trackLineRadius);

                    this.splitTrackModelVisual3D.Add(trackLineMV3D);
                }

                this.splitTrackModelVisual3D.Add(
                    this.CreateAnchorPointModelVisual3D(VRConvert.ConvertFromRealToVirtual(this.track.SplitPoints[i], this.coeff), this.pointRadius));
            }
        }
Ejemplo n.º 7
0
    // This function gets called every time a new VREvent is generated.  Typically, VREvents will come
    // from the MinVR server, which polls trackers, buttons, and other input devices for input.  When
    // debugging on your laptop, you can also generate 'fake' VREvents using the VRMain script.
    void OnVREvent(VREvent e)
    {
        // USER 2 ==========================================================
        if (e.Name == "Brush2_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            brushPos = m.GetTranslation();
            brushRot = m.GetRotation();
            brushCursor2.transform.position = brushPos;
            brushCursor2.transform.rotation = brushRot;

            // Menu Selection ----------------------------------------------
            if (MenuManager.ShowMenu && user_id == 2)
            {
                // Color change when hover on the button
                MenuManager.isHover(brushCursor2.transform.position);
            }
        }
        else if (e.Name == "Hand2_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            handPos = m.GetTranslation();
            handRot = m.GetRotation();
            handCursor2.transform.position = handPos;
            handCursor2.transform.rotation = handRot;
        }
        else if (e.Name == "Head2_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            headPos = m.GetTranslation();
            headRot = m.GetRotation();
        }
        // Button Controls --------------------------------------------------
        else if (e.Name == "stylus0_btn1_up")
        {
            // stylys 0: blue pen

            if (user_id == 2)
            {
                // Show Main Menu
                if (MenuManager.CurMenu == null)
                {
                    // Open Main Menu
                    Menu mainMenu = null;
                    //Debug.Log (MenuManager.Menus.Count);
                    foreach (var item in MenuManager.Menus)
                    {
                        if (item.gameObject.name == "MainMenu")
                        {
                            mainMenu = item;
                            break;
                        }
                    }

                    if (mainMenu == null)
                    {
                        // TODO: catch could not find error
                    }
                    else
                    {
                        /*
                         * mainMenu.ShowMenu = true;
                         * mainMenu.gameObject.SetActive (true);
                         * MenuManager.CurMenu = mainMenu.gameObject;
                         * MenuManager.ShowMenu = true;
                         * Vector3 hpos = GameObject.Find ("User2").transform.position;
                         * MenuContainer.transform.position = new Vector3 (hpos.x, hpos.y - 70, hpos.z);
                         */
                        Vector3 hpos = GameObject.Find("User2").transform.position;

                        MenuManager.OpenMenu(mainMenu, new Vector3(hpos.x, hpos.y - 2, hpos.z), MenuContainer);
                    }
                }
                else
                {
                    MenuManager.CloseMenu();
                }
            }
        }
        else if (e.Name == "stylus0_btn0_down")
        {
            if (user_id == 2)
            {
                if (!MenuManager.ShowMenu)
                {
                    paintingComponent2.startNewStroke(painting2, brushCursor2);
                }
            }
            else if (user_id == 1)
            {
                // determine user 2 whether menu is open
            }
        }
        else if (e.Name == "stylus0_btn0_up")
        {
            if (user_id == 2)
            {
                if (MenuManager.ShowMenu)
                {
                    // Call the function when the button is selected
                    MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor2.transform.position);
                }
                else
                {
                    paintingComponent2.EndStroke();
                }
            }
        }

        // USER 1 ==========================================================
        else if (e.Name == "Brush1_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            brushPos = m.GetTranslation();
            brushRot = m.GetRotation();
            brushCursor.transform.position = brushPos;
            brushCursor.transform.rotation = brushRot;

            if (MenuManager.ShowMenu && user_id == 1)
            {
                // Color change when hover on the button
                MenuManager.isHover(brushCursor.transform.position);
            }
        }
        else if (e.Name == "Hand1_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            handPos = m.GetTranslation();
            handRot = m.GetRotation();
            handCursor.transform.position = handPos;
            handCursor.transform.rotation = handRot;
        }
        else if (e.Name == "Head1_Move")
        {
            Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
            headPos = m.GetTranslation();
            headRot = m.GetRotation();
        }
        // Button Controls --------------------------------------------------
        else if (e.Name == "stylus1_btn1_up")
        {
            // stylys 1: red pen

            if (user_id == 1)
            {
                // Show Main Menu
                if (MenuManager.CurMenu == null)
                {
                    // Open Main Menu
                    Menu mainMenu = null;
                    Debug.Log(MenuManager.Menus.Count);
                    foreach (var item in MenuManager.Menus)
                    {
                        if (item.gameObject.name == "MainMenu")
                        {
                            mainMenu = item;
                            break;
                        }
                    }

                    if (mainMenu == null)
                    {
                        // TODO: catch could not find error
                    }
                    else
                    {
                        /*
                         * mainMenu.ShowMenu = true;
                         * mainMenu.gameObject.SetActive (true);
                         * MenuManager.CurMenu = mainMenu.gameObject;
                         * MenuManager.ShowMenu = true;
                         * Vector3 hpos = GameObject.Find ("User1").transform.position;
                         * MenuContainer.transform.position = new Vector3 (hpos.x, hpos.y - 70, hpos.z);
                         */

                        Vector3 hpos = GameObject.Find("User1").transform.position;

                        MenuManager.OpenMenu(mainMenu, new Vector3(hpos.x, hpos.y - 2, hpos.z), MenuContainer);
                    }
                }
                else
                {
                    MenuManager.CloseMenu();
                }
            }
        }
        else if (e.Name == "stylus1_btn0_down")
        {
            if (user_id == 1)
            {
                if (!MenuManager.ShowMenu)
                {
                    paintingComponent.startNewStroke(painting, brushCursor);
                }
            }
            else if (user_id == 2)
            {
                // determine user 1 whether menu is open
            }
        }
        else if (e.Name == "stylus1_btn0_up")
        {
            if (user_id == 1)
            {
                if (MenuManager.ShowMenu)
                {
                    // Call the function when the button is selected
                    MenuManager.CurMenu.GetComponent <Menu> ().Clicked(brushCursor.transform.position);
                }
                else
                {
                    paintingComponent.EndStroke();
                }
            }
        }
        // Client input events -----------------------------------------------
        else if (e.Name == "Type_Change")
        {
            if (user_id == 1)
            {
            }
            else if (user_id == 2)
            {
            }
        }
        else if (e.Name == "Color_Change")
        {
            if (user_id == 1)
            {
            }
            else if (user_id == 2)
            {
            }
        }
        else if (e.Name == "Start_Collaboration")
        {
            if (user_id == 1)
            {
            }
            else if (user_id == 2)
            {
            }
        }
    }
Ejemplo n.º 8
0
        public void BeginAnimation(double[] dQ)
        {
            for (var i = 0; i < this.arm.N; i++)
            {
                switch (this.arm.Units[i].Type)
                {
                case 'R':
                    var rotAxis   = VRConvert.ConvertFromRealToVirtual(this.arm.GetZAxis(i), this.coeff);
                    var centerRot = VRConvert.ConvertFromRealToVirtual((Point3D)this.arm.F(i), this.coeff);
                    for (var j = 2 * (i + 1); j < 2 * (this.arm.N + 1) + 1; j++)
                    {
                        ((this.armModelVisual3D[j]
                          .Transform as Transform3DGroup)
                         .Children[2 * i + 1] as RotateTransform3D)
                        .CenterX = centerRot.X;
                        ((this.armModelVisual3D[j]
                          .Transform as Transform3DGroup)
                         .Children[2 * i + 1] as RotateTransform3D)
                        .CenterY = centerRot.Y;
                        ((this.armModelVisual3D[j]
                          .Transform as Transform3DGroup)
                         .Children[2 * i + 1] as RotateTransform3D)
                        .CenterZ = centerRot.Z;

                        (((this.armModelVisual3D[j]
                           .Transform as Transform3DGroup)
                          .Children[2 * i + 1] as RotateTransform3D)
                         .Rotation as AxisAngleRotation3D)
                        .Axis = rotAxis;

                        (((this.armModelVisual3D[j].Transform as Transform3DGroup)
                          .Children[2 * i + 1] as RotateTransform3D)
                         .Rotation as AxisAngleRotation3D)
                        .Angle = MathFunctions.RadianToDegree(dQ[i]);
                    }

                    break;

                case 'P':
                    var prismaticAxis = VRConvert.ConvertFromRealToVirtual(this.arm.GetZAxis(i), this.coeff);
                    for (var j = 2 * (i + 1); j < 2 * (this.arm.N + 1) + 1; j++)
                    {
                        if (j == 2 * (i + 1) + 1)
                        {
                            continue;
                        }

                        ((this.armModelVisual3D[j]
                          .Transform as Transform3DGroup)
                         .Children[2 * i] as TranslateTransform3D)
                        .OffsetX = prismaticAxis.X * dQ[i];
                        ((this.armModelVisual3D[j]
                          .Transform as Transform3DGroup)
                         .Children[2 * i] as TranslateTransform3D)
                        .OffsetY = prismaticAxis.Y * dQ[i];
                        ((this.armModelVisual3D[j]
                          .Transform as Transform3DGroup)
                         .Children[2 * i] as TranslateTransform3D)
                        .OffsetZ = prismaticAxis.Z * dQ[i];
                    }

                    break;
                }
            }
        }
Ejemplo n.º 9
0
 // This function gets called every time a new VREvent is generated.  Typically, VREvents will come
 // from the MinVR server, which polls trackers, buttons, and other input devices for input.  When
 // debugging on your laptop, you can also generate 'fake' VREvents using the VRMain script.
 void OnVREvent(VREvent e)
 {
     if (e.Name == "Brush_Move")             // for faster user 2
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         brushPos = m.GetTranslation();
         brushRot = m.GetRotation();
         brushCursor.transform.position = brushPos;
         brushCursor.transform.rotation = brushRot;
     }
     else if (e.Name == "Hand_Move")
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         handPos = m.GetTranslation();
         handRot = m.GetRotation();
         handCursor.transform.position = handPos;
         handCursor.transform.rotation = handRot;
     }
     else if (e.Name == "user_header_1" && user_id)             // for cave painting system user 1
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         headPos = m.GetTranslation();
         headRot = m.GetRotation();
         headObj.transform.position = headPos;
         headObj.transform.rotation = headRot;
     }
     else if (e.Name == "user_header_2" && !user_id)             // for cave painting system user 2
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         handPos = m.GetTranslation();
         handRot = m.GetRotation();
         headObj.transform.position = headPos;
         headObj.transform.rotation = headRot;
     }
     else if (e.Name == "Head_Move")
     {
         Matrix4x4 m = VRConvert.ToMatrix4x4(e.DataIndex.GetValueAsDoubleArray("Transform"));
         headPos = m.GetTranslation();
         handRot = m.GetRotation();
     }
     else if (e.Name == "Mouse_Down")                // TODO : useless for now
     {
         Debug.Log("mouse down");
     }
     else if (e.Name == "Mouse_Up")
     {
         Debug.Log("mouse up");
     }
     else if (e.Name == "stylus1_btn0_down")                    // user 2 start to draw
     {
         startDrawing = true;
         Debug.Log("Red User 2 drawing down");
     }
     else if (e.Name == "stylus1_btn0_up")
     {
         startDrawing = false;
         Debug.Log("Red User 2 drawing up");
     }
     else if (e.Name == "stylus1_btn1_down")                // controll what user 2 see
     // TODO : manipulate User 2 camera
     {
         Debug.Log("Red User 2 control down");
     }
     else if (e.Name == "stylus1_btn1_up")
     {
         // TODO : .... I don't know for now
         Debug.Log("Red User 2 control up");
     }
     else if (e.Name == "stylus1_btn1_down")                // user 1 start to draw
     {
         startDrawing = true;
         Debug.Log("Red User 1 control down");
     }
     else if (e.Name == "stylus1_btn1_up")
     {
         startDrawing = false;
         Debug.Log("Red User 1 control up");
     }
     else if (e.Name == "stylus1_btn1_down")                // controll what user 1 see
     // TODO : manipulate User 1 camera
     {
         Debug.Log("Red User 1 control down");
     }
     else if (e.Name == "stylus1_btn1_up")
     {
         // TODO : .... I don't know for now
         Debug.Log("Red User 1 control up");
     }
 }