Ejemplo n.º 1
0
 public float Response(out MEntity entity, Vector3 pos, MInteractMode mode)
 {
     Vector3 p = worldToLocalMatrix.MultiplyPoint(pos);
     float dis = float.MaxValue;
     float res = float.MaxValue;
     MPoint point;
     MEdge edge;
     MFace face;
     MEntity e = null;
     switch (mode)
     {
         case MInteractMode.ALL:
             dis = mesh.GetClosetPoint(out point, p);
             if(dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = point;
                 res = dis;
                 break;
             }
             dis = mesh.GetClosetEdge(out edge, p);
             if(dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = edge;
                 res = dis;
                 break;
             }
             dis = mesh.GetClosetFace(out face, p, true, MDefinitions.ACTIVE_DISTANCE / scale);
             if(dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = face;
                 res = dis;
                 break;
             }
             break;
         case MInteractMode.POINT_ONLY:
             dis = mesh.GetClosetPoint(out point, p);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = point;
                 res = dis;
             }
             break;
         case MInteractMode.EDGE_ONLY:
             dis = mesh.GetClosetEdge(out edge, p);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = edge;
                 res = dis;
             }
             break;
         case MInteractMode.FACE_ONLY:
             dis = mesh.GetClosetFace(out face, p, true, MDefinitions.ACTIVE_DISTANCE / scale);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = face;
                 res = dis;
             }
             break;
         case MInteractMode.POINT_EXPT:
             dis = mesh.GetClosetEdge(out edge, p);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = edge;
                 res = dis;
                 break;
             }
             dis = mesh.GetClosetFace(out face, p, true, MDefinitions.ACTIVE_DISTANCE / scale);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = face;
                 res = dis;
                 break;
             }
             break;
         case MInteractMode.EDGE_EXPT:
             dis = mesh.GetClosetPoint(out point, p);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = point;
                 res = dis;
                 break;
             }
             dis = mesh.GetClosetFace(out face, p, true, MDefinitions.ACTIVE_DISTANCE / scale);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = face;
                 res = dis;
                 break;
             }
             break;
         case MInteractMode.FACE_EXPT:
             dis = mesh.GetClosetPoint(out point, p);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = point;
                 res = dis;
                 break;
             }
             dis = mesh.GetClosetEdge(out edge, p);
             if (dis < MDefinitions.ACTIVE_DISTANCE)
             {
                 e = edge;
                 res = dis;
                 break;
             }
             break;
         default:
             Debug.Log("MObject: Response: unknown interact mode");
             break;
     }
     entity = e;
     return res;
 }