示例#1
0
 void Update()
 {
     coordsUnity.text = "";
     coordsVts.text   = "";
     if (!map.GetVtsMap().GetMapconfigAvailable())
     {
         return;
     }
     double[] p = VtsUtil.U2V3(transform.position);
     p = map.UnityToVtsNavigation(p);
     coordsUnity.text = "Unity World: " + transform.position.ToString("F5");
     coordsVts.text   = "Vts Navigation: " + VtsUtil.V2U3(p).ToString("F5");
 }
 private void CollOverrideCenter(ref double[] values)
 {
     values = VtsUtil.U2V3(probTrans.position);
     { // convert from unity world to (local) vts physical
         double[] point4 = new double[4] {
             values[0], values[1], values[2], 1
         };
         point4    = Math.Mul44x4(VtsUtil.U2V44(mapTrans.worldToLocalMatrix), point4);
         values[0] = point4[0]; values[1] = point4[1]; values[2] = point4[2];
     }
     { // swap YZ
         double tmp = values[1];
         values[1] = values[2];
         values[2] = tmp;
     }
 }
示例#3
0
    void Update()
    {
        coordsUnity.text = "";
        coordsVts.text   = "";
        if (!map.GetVtsMap().GetMapconfigAvailable())
        {
            return;
        }
        Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (!Physics.Raycast(ray, out hit))
        {
            return;
        }
        double[] p = VtsUtil.U2V3(hit.point);
        p = map.UnityToVtsNavigation(p);
        coordsUnity.text = "Unity World: " + hit.point.ToString("F5");
        coordsVts.text   = "Vts Navigation: " + VtsUtil.V2U3(p).ToString("F5");
    }
示例#4
0
    private void PerformShift()
    {
        // the focus object must be moved
        Debug.Assert(focusObject.GetComponentInParent <VtsObjectShiftingOriginBase>());

        // compute the transformation change
        double[] originalNavigationPoint = umap.UnityToVtsNavigation(VtsUtil.ZeroV);
        double[] targetNavigationPoint   = umap.UnityToVtsNavigation(VtsUtil.U2V3(focusObject.transform.position));
        if (!VtsMapMakeLocal.MakeLocal(umap, targetNavigationPoint))
        {
            Debug.Assert(false, "failed shifting origin");
            return;
        }
        Vector3 move = -focusObject.transform.position;
        float   Yrot = (float)(targetNavigationPoint[0] - originalNavigationPoint[0]) * Mathf.Sign((float)originalNavigationPoint[1]);

        // find objects that will be transformed
        var objs = new System.Collections.Generic.List <VtsObjectShiftingOriginBase>();

        foreach (VtsObjectShiftingOriginBase obj in FindObjectsOfType <VtsObjectShiftingOriginBase>())
        {
            // ask if the object allows to be transformed by this map
            if (obj.enabled && obj.OnBeforeOriginShift(this))
            {
                objs.Add(obj);
            }
        }

        // actually transform the objects
        foreach (VtsObjectShiftingOriginBase obj in objs)
        {
            // only transform object's topmost ancestor - its childs will inherit the change
            // an object is shifted only once even if it has multiple VtsObjectShiftingOriginBase components
            if (!obj.transform.parent || !obj.transform.parent.GetComponentInParent <VtsObjectShiftingOriginBase>() &&
                obj == obj.GetComponents <VtsObjectShiftingOriginBase>()[0])
            {
                obj.transform.localPosition += move;
                obj.transform.RotateAround(Vector3.zero, Vector3.up, Yrot);
            }
        }

        // notify the object that it was transformed
        foreach (VtsObjectShiftingOriginBase obj in objs)
        {
            obj.OnAfterOriginShift();
        }

        // force all objects cameras to recompute positions -> improves precision
        foreach (VtsCameraBase cam in FindObjectsOfType <VtsCameraBase>())
        {
            cam.OriginShifted();
        }

        // force all collider probes to recompute positions -> improves precision
        // warning: this has big performance impact!
        if (updateColliders)
        {
            foreach (VtsColliderProbe col in FindObjectsOfType <VtsColliderProbe>())
            {
                col.OriginShifted();
            }
        }
    }