private void UpdateStretch()
    {
        Vector3 pos   = obj.worldToLocalMatrix.MultiplyPoint(sceneManager.rightControllerPosition);
        MPoint  a     = activeEdges[0].start;
        MPoint  b     = activeEdges[0].end;
        MPoint  c     = activeEdges[1].end;
        float   width = Vector3.Distance(a.position, b.position);
        Vector3 p     = MHelperFunctions.VectorL2P(pos, activeEdges[0].direction, a.position);

        p = ReviseLength(p, width);
        c.SetPosition(p + b.position);
        if (activeFace != null && activeFace.IsValid())
        {
            activeFace.Render(obj.localToWorldMatrix);
            foreach (MLinearEdge edge in activeEdges)
            {
                edge.Render(obj.localToWorldMatrix);
            }
            a.Render(obj.localToWorldMatrix);
            b.Render(obj.localToWorldMatrix);
            c.Render(obj.localToWorldMatrix);
            activeTextMesh.GetComponentInChildren <TextMesh>().text = "1:" + (p.magnitude / width).ToString();
            activeTextMesh.transform.position = sceneManager.rightControllerPosition + MDefinitions.DEFAULT_ACTIVE_TEXT_OFFSET;
            if (sceneManager.camera != null)
            {
                activeTextMesh.transform.rotation = Quaternion.LookRotation((sceneManager.camera.transform.position - activeTextMesh.transform.position) * -1, Vector3.up);
            }
        }
        else
        {
            activeTextMesh.GetComponentInChildren <TextMesh>().text = "";
        }
    }
Пример #2
0
 private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e)
 {
     if (sceneManager.activeEntity.entity != null && ((MEdge)sceneManager.activeEntity.entity).edgeType == MEdge.MEdgeType.LINEAR)
     {
         if (curObject == null)
         {
             curObject = sceneManager.activeEntity.obj;
         }
         else
         {
             if (sceneManager.activeEntity.obj != curObject)
             {
                 ResetStatus();
                 return;
             }
         }
         MLinearEdge le = sceneManager.activeEntity.entity as MLinearEdge;
         if (selectEdges.Count > 1)
         {
             Vector3 normal = Vector3.Cross(selectEdges[0].direction, selectEdges[1].direction).normalized;
             if (!MHelperFunctions.Perpendicular(normal, le.direction))
             {
                 ResetStatus();
                 return;
             }
         }
         SelectEdge(le);
         if (selectEdges.Count < 3)
         {
             curObject = null;
             return;
         }
         MPolygonFace face = new MPolygonFace(selectEdges);
         if (face.IsValid())
         {
             curObject.CreatePolygonFace(new List <MLinearEdge>(selectEdges));
             ResetStatus();
         }
     }
     else
     {
         ResetStatus();
     }
 }
Пример #3
0
    private void RightTriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e)
    {
        switch (status)
        {
        case STATUS.DEFAULT:
            obj.transform.position = sceneManager.rightControllerPosition;
            stablePoint            = obj.worldToLocalMatrix.MultiplyPoint(sceneManager.rightControllerPosition);
            status         = STATUS.CREATE_EDGE;
            activeEdges[0] = new MLinearEdge(new MPoint(stablePoint), new MPoint(activePoint.position));
            activeEdges[0].end.edges.Add(activeEdges[0]);
            break;

        case STATUS.CREATE_EDGE:
            activeEdges[1] = new MLinearEdge(activeEdges[0].start, new MPoint(activePoint.position + activeEdges[0].start.position - activeEdges[0].end.position));
            activeEdges[1].end.edges.Add(activeEdges[1]);
            activeEdges[2] = new MLinearEdge(activeEdges[0].end, new MPoint(activePoint.position));
            activeEdges[2].end.edges.Add(activeEdges[2]);
            activeEdges[3] = new MLinearEdge(activeEdges[1].end, activeEdges[2].end);
            activeEdges[3].start.edges.Add(activeEdges[3]);
            activeEdges[3].end.edges.Add(activeEdges[3]);
            activeFace = new MPolygonFace(new List <MLinearEdge>(activeEdges));
            activeEdges[1].faces.Add(activeFace);
            activeEdges[2].faces.Add(activeFace);
            activeEdges[3].faces.Add(activeFace);
            activeTextMesh.SetActive(true);
            status = STATUS.STRETCH;
            break;

        case STATUS.STRETCH:
            if (activeFace != null && activeFace.IsValid())
            {
                status = STATUS.FINISH;
                obj.CreatePolygonFace(new List <MLinearEdge>(activeEdges));
                sceneManager.objects.Add(obj);
                sceneManager.sceneStateMachine.SwitchState((uint)SceneManager.SceneStatus.TRANSFORM, null);
            }
            else
            {
                ResetStatus();
            }
            break;
        }
    }
Пример #4
0
    public MPolygonFace CreatePolygonFace(List <MLinearEdge> edges)
    {
        MPolygonFace face = new MPolygonFace(edges);

        if (!face.IsValid())
        {
            return(null);
        }
        int i;

        if ((i = AddFaceToMesh(face)) != -1)
        {
            return(faceList[i] as MPolygonFace);
        }
        else
        {
            return(face);
        }
    }