Exemple #1
0
 public void UpdateObjectHighlight()
 {
     foreach (MObject obj in objects)
     {
         if (obj.HitObject(rightControllerPosition))
         {
             if (activeEntity.obj != obj)
             {
                 if (activeEntity.obj != null && activeEntity.obj.objectState == MObject.MObjectState.ACTIVE)
                 {
                     activeEntity.obj.ResetStatus();
                 }
                 if (obj.objectState == MObject.MObjectState.DEFAULT)
                 {
                     obj.Highlight();
                 }
                 activeEntity = new MEntityPair(null, obj);
             }
             return;
         }
     }
     if (activeEntity.obj != null)
     {
         if (activeEntity.obj.objectState == MObject.MObjectState.ACTIVE)
         {
             activeEntity.obj.ResetStatus();
         }
         activeEntity = new MEntityPair(null, null);
     }
 }
Exemple #2
0
 public MRelation(EntityRelationType type, MEntityPair lower, MEntityPair higher, float dis, float angle, bool shareObject)
 {
     relationType     = type;
     lowerEntity      = lower;
     higherEntity     = higher;
     distance         = dis;
     this.angle       = angle;
     this.shareObject = shareObject;
 }
    private void AddEntity(MEntityPair entityPair)
    {
        MEntity entity = entityPair.entity;

        if (entity.entityStatus != MEntity.MEntityStatus.SPECIAL)
        {
            entity.entityStatus = MEntity.MEntityStatus.SELECT;
        }
        selectedEntity.Add(entityPair);
    }
    private void RemoveEntity(MEntityPair entityPair)
    {
        MEntity entity = entityPair.entity;

        if (entity.entityStatus == MEntity.MEntityStatus.SELECT)
        {
            entity.entityStatus = MEntity.MEntityStatus.DEFAULT;
        }
        selectedEntity.Remove(entityPair);
    }
Exemple #5
0
    public void UpdateEntityHighlight(MObject.MInteractMode interactMode)
    {
        MEntityPair e = GetAvailEntity(rightControllerPosition, interactMode);

        if (activeEntity.entity != e.entity)
        {
            UnhighlightEntity(activeEntity.entity);
            HighlightEntity(e.entity);
        }
        activeEntity = e;
    }
 private void SelectEntity(MEntityPair entityPair)
 {
     if (selectedEntity.Contains(entityPair))
     {
         RemoveEntity(entityPair);
     }
     else
     {
         AddEntity(entityPair);
     }
 }
 private void CompareEntity(MEntityPair e1, MEntityPair e2, out MEntityPair lower, out MEntityPair higher)
 {
     if ((e1.entity.entityType == e2.entity.entityType) ||
         (e1.entity.entityType == MEntity.MEntityType.POINT) ||
         (e1.entity.entityType == MEntity.MEntityType.EDGE && e2.entity.entityType == MEntity.MEntityType.FACE))
     {
         lower  = e1;
         higher = e2;
         return;
     }
     else
     {
         lower  = e2;
         higher = e1;
         return;
     }
 }
    private void AddEntity(MEntityPair entityPair)
    {
        MEntity entity = entityPair.entity;
        MObject obj    = entityPair.obj;

        if (entityPair.entity.entityStatus != MEntity.MEntityStatus.SPECIAL)
        {
            entityPair.entity.entityStatus = MEntity.MEntityStatus.SELECT;
        }
        switch (entity.entityType)
        {
        case MEntity.MEntityType.EDGE:
            selectLengthCount[sceneManager.objects.IndexOf(obj)] += obj.GetEdgeLength((MEdge)entity);
            break;

        case MEntity.MEntityType.FACE:
            selectSurfaceCount[sceneManager.objects.IndexOf(obj)] += obj.GetFaceSurface((MFace)entity);
            break;
        }
        selectedEntity.Add(entityPair);
    }
Exemple #9
0
    public void UpdateEntityHighlight(MObject.MInteractMode interactMode, MObject obj)
    {
        MEntity entity = null;

        if (obj.HitObject(rightControllerPosition))
        {
            obj.Response(out entity, rightControllerPosition, interactMode);
        }
        if (activeEntity.entity != entity)
        {
            UnhighlightEntity(activeEntity.entity);
            HighlightEntity(entity);
        }
        if (entity == null)
        {
            activeEntity = new MEntityPair(null, null);
        }
        else
        {
            activeEntity = new MEntityPair(entity, obj);
        }
    }
    private MRelation GetEntityRelation(MEntityPair e1, MEntityPair e2)
    {
        MEntityPair lowerEntity, higherEntity;

        CompareEntity(e1, e2, out lowerEntity, out higherEntity);
        bool    shareObject = (e1.obj == e2.obj);
        MObject obj         = null;

        if (shareObject)
        {
            obj = e1.obj;
        }
        float distance = -1;
        float angle    = 0;

        MRelation.EntityRelationType type;
        if (higherEntity.entity.entityType == MEntity.MEntityType.POINT) //点点关系
        {
            type = MRelation.EntityRelationType.POINT_POINT;
            if (shareObject)
            {
                Vector3 p1 = ((MPoint)lowerEntity.entity).position;
                Vector3 p2 = ((MPoint)higherEntity.entity).position;
                distance = obj.RefEdgeRelativeLength(Vector3.Distance(p1, p2));
            }
        }
        else if (lowerEntity.entity.entityType == MEntity.MEntityType.POINT && higherEntity.entity.entityType == MEntity.MEntityType.EDGE) //点线关系
        {
            type = MRelation.EntityRelationType.POINT_EDGE;
            if (shareObject)
            {
                MEdge edge = (MEdge)higherEntity.entity;
                if (edge.edgeType != MEdge.MEdgeType.LINEAR)
                {
                    return(null);
                }
                distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2L(
                                                         ((MPoint)lowerEntity.entity).position,
                                                         ((MLinearEdge)edge).direction,
                                                         ((MLinearEdge)edge).end.position));
            }
        }
        else if (higherEntity.entity.entityType == MEntity.MEntityType.EDGE) //线线关系
        {
            type = MRelation.EntityRelationType.EDGE_EDGE;
            MEdge edge1 = (MEdge)lowerEntity.entity;
            MEdge edge2 = (MEdge)higherEntity.entity;
            if (edge1.edgeType != MEdge.MEdgeType.LINEAR || edge2.edgeType != MEdge.MEdgeType.LINEAR)
            {
                return(null);
            }
            MLinearEdge le1 = edge1 as MLinearEdge;
            MLinearEdge le2 = edge2 as MLinearEdge;
            if (shareObject)
            {
                distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceL2L(le1.start.position, le1.direction, le2.start.position, le2.direction));
                angle    = MHelperFunctions.CalcAngle(le1.direction, le2.direction);
            }
            else
            {
                angle = MHelperFunctions.CalcAngle(
                    lowerEntity.obj.localToWorldMatrix.MultiplyVector(le1.direction),
                    higherEntity.obj.localToWorldMatrix.MultiplyVector(le2.direction));
            }
        }
        else if (lowerEntity.entity.entityType == MEntity.MEntityType.POINT) //点面关系
        {
            type = MRelation.EntityRelationType.POINT_FACE;
            MFace   face = (MFace)higherEntity.entity;
            Vector3 normal;
            Vector3 facePoint;
            if (shareObject)
            {
                if (face.faceType == MFace.MFaceType.POLYGON)
                {
                    normal    = ((MPolygonFace)face).normal;
                    facePoint = ((MPolygonFace)face).edgeList[0].start.position;
                }
                else if (face.faceType == MFace.MFaceType.CIRCLE)
                {
                    normal    = ((MCircleFace)face).circle.normal;
                    facePoint = ((MCircleFace)face).circle.center.position;
                }
                else
                {
                    return(null);
                }
                distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2F(((MPoint)lowerEntity.entity).position, normal, facePoint));
            }
        }
        else if (lowerEntity.entity.entityType == MEntity.MEntityType.EDGE) //线面关系
        {
            type = MRelation.EntityRelationType.EDGE_FACE;
            MEdge edge = (MEdge)lowerEntity.entity;
            if (edge.edgeType != MEdge.MEdgeType.LINEAR)
            {
                return(null);
            }
            MFace   face = (MFace)higherEntity.entity;
            Vector3 normal;
            Vector3 facePoint;
            if (face.faceType == MFace.MFaceType.POLYGON)
            {
                normal    = ((MPolygonFace)face).normal;
                facePoint = ((MPolygonFace)face).edgeList[0].start.position;
            }
            else if (face.faceType == MFace.MFaceType.CIRCLE)
            {
                normal    = ((MCircleFace)face).circle.normal;
                facePoint = ((MCircleFace)face).circle.center.position;
            }
            else
            {
                return(null);
            }
            if (shareObject)
            {
                angle = 90 - MHelperFunctions.CalcAngle(((MLinearEdge)edge).direction, normal);
                if (MHelperFunctions.FloatEqual(angle, 0))
                {
                    distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2F(((MLinearEdge)edge).start.position, normal, facePoint));
                }
            }
            else
            {
                angle = 90 - MHelperFunctions.CalcAngle(
                    lowerEntity.obj.localToWorldMatrix.MultiplyVector(((MLinearEdge)edge).direction),
                    higherEntity.obj.localToWorldMatrix.MultiplyVector(normal));
            }
        }
        else //面面关系
        {
            type = MRelation.EntityRelationType.FACE_FACE;
            MFace   f1 = (MFace)lowerEntity.entity;
            MFace   f2 = (MFace)higherEntity.entity;
            Vector3 normal1, normal2;
            Vector3 facePoint1, facePoint2;
            if (f1.faceType == MFace.MFaceType.POLYGON)
            {
                normal1    = ((MPolygonFace)f1).normal;
                facePoint1 = ((MPolygonFace)f1).edgeList[0].start.position;
            }
            else if (f1.faceType == MFace.MFaceType.CIRCLE)
            {
                normal1    = ((MCircleFace)f1).circle.normal;
                facePoint1 = ((MCircleFace)f1).circle.center.position;
            }
            else
            {
                return(null);
            }
            if (f2.faceType == MFace.MFaceType.POLYGON)
            {
                normal2    = ((MPolygonFace)f2).normal;
                facePoint2 = ((MPolygonFace)f2).edgeList[0].start.position;
            }
            else if (f2.faceType == MFace.MFaceType.CIRCLE)
            {
                normal2    = ((MCircleFace)f2).circle.normal;
                facePoint2 = ((MCircleFace)f2).circle.center.position;
            }
            else
            {
                return(null);
            }
            if (shareObject)
            {
                angle = MHelperFunctions.CalcAngle(normal1, normal2);
                if (MHelperFunctions.FloatEqual(angle, 0))
                {
                    distance = obj.RefEdgeRelativeLength(MHelperFunctions.DistanceP2F(facePoint1, normal2, facePoint2));
                }
            }
            else
            {
                angle = MHelperFunctions.CalcAngle(
                    lowerEntity.obj.localToWorldMatrix.MultiplyVector(normal1),
                    higherEntity.obj.localToWorldMatrix.MultiplyVector(normal2));
            }
        }
        return(new MRelation(type, lowerEntity, higherEntity, distance, angle, shareObject));
    }