//We do the actual interpolation in FixedUpdate(), since we're dealing with a rigidbody
        private void LateUpdate()
        {
            if (_isMapInitialized && _isLerping)
            {
                //We want percentage = 0.0 when Time.time = _timeStartedLerping
                //and percentage = 1.0 when Time.time = _timeStartedLerping + timeTakenDuringLerp
                //In other words, we want to know what percentage of "timeTakenDuringLerp" the value
                //"Time.time - _timeStartedLerping" is.
                float timeSinceStarted   = Time.time - _timeStartedLerping;
                float percentageComplete = timeSinceStarted / timeTakenDuringLerp;

                //Perform the actual lerping.  Notice that the first two parameters will always be the same
                //throughout a single lerp-processs (ie. they won't change until we hit the space-bar again
                //to start another lerp)
                _startPosition = _map.GeoToWorldPosition(_startLatLong, false);
                _endPosition   = _map.GeoToWorldPosition(_endLatlong, false);
                var position = Vector3.Lerp(_startPosition, _endPosition, percentageComplete);
                var latLong  = _map.WorldToGeoPosition(position);
                _map.UpdateMap(latLong, _map.Zoom);

                //When we've completed the lerp, we set _isLerping to false
                if (percentageComplete >= 1.0f)
                {
                    _isLerping = false;
                }
            }
        }
 private void LateUpdate()
 {
     if (_isMapInitialized)
     {
         var currentPosition = _map.GeoToWorldPosition(_map.CenterLatitudeLongitude, false);
         var position        = Vector3.Lerp(currentPosition, _targetPosition, Time.deltaTime);
         var latLong         = _map.WorldToGeoPosition(position);
         _map.UpdateMap(latLong, _map.Zoom);
     }
 }
Пример #3
0
    void GrabAction()
    {
        //Debug.Log ("grabbing");
        //attachment.transform.position += new Vector3(gestureRecognitionController.GetDominantVelocity (isLeftHanded).x, 0.0f, gestureRecognitionController.GetDominantVelocity(isLeftHanded).z);



        //Debug.Log (gestureRecognitionController.GetDominantHand (false).PalmPosition.ToVector3 ());
        //if (!(gestureRecognitionController.GetHandPinchStartPosition (gestureRecognitionController.GetDominantHand (false)) == Vector3.negativeInfinity))

        GameObject mainCamera          = GameObject.FindWithTag("MainCamera");
        Vector3    startPinch          = gestureRecognitionController.GetHandPinchStartPosition(gestureRecognitionController.GetDominantHand(false)) - mainCamera.transform.position;
        Vector3    currentHandPosition = gestureRecognitionController.GetDominantHand(false).PalmPosition.ToVector3() - mainCamera.transform.position;

        if (!float.IsNegativeInfinity(startPinch.x))
        {
            if (actionType == 0)
            {
                //Vector3 velocity = Quaternion.AngleAxis((mainCamera.transform.position), Vector3.up) * gestureRecognitionController.GetDominantVelocity(isLeftHanded);
                //float angle = Quaternion.Angle (mainCamera.transform.rotation, attachment.transform.rotation);
                //if (mainCamera.transform.rotation > attachment.transform.rotation)
                //{
                //	angle = -angle;
                //}

                float angle = mainCamera.transform.localEulerAngles.y - attachment.transform.localEulerAngles.y;
                Debug.Log("" + mainCamera.transform.localEulerAngles.y + " : " + attachment.transform.localEulerAngles.y + " : " + angle);

                Vector3 movement = Quaternion.AngleAxis(angle, Vector3.up) * gestureRecognitionController.GetDominantVelocity(isLeftHanded);
                Mapbox.Utils.Vector2d mapboxMovement = new Mapbox.Utils.Vector2d(movement.z, movement.x);
                attachment.UpdateMap(attachment.CenterLatitudeLongitude - (mapboxMovement * 0.0005f), attachment.Zoom);
            }
            else if (actionType == 1)
            {
            }
            else if (actionType == 2)
            {
                float   direction      = startPinch.x - currentHandPosition.x;
                float   angle          = Vector2.SignedAngle(new Vector2(currentHandPosition.x, currentHandPosition.z), new Vector2(startPinch.x, startPinch.z));
                float   currentAngle   = attachment.transform.eulerAngles.y;
                Vector3 targetLocation = (Quaternion.Euler(0, startAngle + angle - currentAngle, 0) * (attachment.transform.position - mainCamera.transform.position)) + mainCamera.transform.position;
                attachment.transform.SetPositionAndRotation(targetLocation, Quaternion.Euler(0, (startAngle + angle), 0));
            }

            //Debug.Log (direction);

            //if (attachment.transform.eulerAngles.y / 180 < 1) {
            //	currentAngle = attachment.transform.eulerAngles.y % 180;
            //} else {
            //	currentAngle = -attachment.transform.eulerAngles.y % 180;
            //}
            //Vector3 targetLocation = attachment.transform.position;

            //attachment.transform.rotation = Quaternion.Euler(0, (startAngle + angle), 0);

            //Debug.Log ((startAngle + angle - currentAngle));
            //Debug.Log ("" + startAngle + " + " + angle + " - " + currentAngle);

            /*/if (direction <= 0)
             * {
             *      attachment.transform.rotation = Quaternion.Euler(0, (startAngle + angle - currentAngle) % 180, 0);
             *      //Vector3 targetLocation = (Quaternion.Euler (0, startAngle - angle - currentAngle, 0) * (attachment.transform.position - cameraPosition))  + cameraPosition - attachment.transform.position;
             *      //attachment.transform.SetPositionAndRotation(targetLocation , Quaternion.Euler(0, (startAngle + angle - currentAngle) % 180, 0));
             *
             *      Debug.Log ((startAngle + angle - currentAngle) % 180);
             *      //attachment.transform.RotateAround (cameraPosition, Vector3.up, startAngle - angle - currentAngle);
             *      Debug.Log ("" + startAngle + " + " + angle + " - " + currentAngle);
             * }
             * else
             * {
             *      attachment.transform.rotation = Quaternion.Euler(0, (startAngle - angle - currentAngle) % 180, 0);
             *      //Vector3 targetLocation = (Quaternion.Euler (0, startAngle + angle - currentAngle, 0) * (attachment.transform.position - cameraPosition)) + cameraPosition - attachment.transform.position;
             *      //attachment.transform.SetPositionAndRotation(targetLocation , Quaternion.Euler(0, (startAngle - angle - currentAngle) % 180, 0));
             *      Debug.Log ((startAngle - angle - currentAngle) % 180);
             *      //attachment.transform.RotateAround (cameraPosition, Vector3.up, startAngle + angle - currentAngle);
             *      Debug.Log ("" + startAngle + " - " + angle + " - " + currentAngle);
             * }/*/
        }

        //Vector2 startPinch = (Vector2)gestureRecognitionController.GetHandPinchStartPosition (gestureRecognitionController.GetDominantHand (false));
        //if (!float.IsNegativeInfinity (startPinch.x))
        //{

        //}
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log ("hello");
        Vector3 movement = new Vector3();

        if (Input.GetKey(KeyCode.W))
        {
            //North
            movement.z = -0.00005f;
        }
        if (Input.GetKey(KeyCode.S))
        {
            //South
            movement.z = 0.00005f;
        }
        if (Input.GetKey(KeyCode.A))
        {
            //West
            movement.x = 0.00005f;
        }
        if (Input.GetKey(KeyCode.D))
        {
            //East
            movement.x = -0.00005f;
        }

        float angle = 0.0f;

        if (Input.GetKey(KeyCode.Q))
        {
            //Anti-Clockwise
            angle = 0.8f;
        }
        if (Input.GetKey(KeyCode.E))
        {
            //Clockwise
            angle = -0.8f;
        }

        float height = 0.0f;

        if (Input.GetKey(KeyCode.UpArrow))
        {
            //Up
            height = 0.01f;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            //Down
            height = -0.01f;
        }

        float zoomChange       = 0.0f;
        bool  zooming          = false;
        float percentageChange = 0.0f;

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            //Out
            if (transform.localScale.x > 0.15f)
            {
                zoomChange = -0.1f;
                zooming    = true;
            }
            //transform.localScale = Vector3.Lerp(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.15f, 0.15f, 0.15f), 0.2f * Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            //In
            if (transform.localScale.x < 0.5f)
            {
                zoomChange = 0.1f;
                zooming    = true;
            }
            //transform.localScale = Vector3.Lerp(new Vector3(0.15f, 0.15f, 0.15f), new Vector3(0.5f, 0.5f, 0.5f), 0.2f * Time.deltaTime);
        }

        if (zooming)
        {
            Vector3 difference    = transform.localPosition - zed.transform.localPosition;
            Vector3 finalPosition = zed.transform.localPosition;
            float   currentSize   = transform.localScale.x;
            transform.localScale += new Vector3(1, 1, 1) * Time.deltaTime * zoomChange;
            if (zoomChange < 0)
            {
                percentageChange = currentSize / (transform.localScale.x);
                finalPosition   += difference / (percentageChange);
            }
            else
            {
                percentageChange = (transform.localScale.x) / currentSize;
                finalPosition   += difference * (percentageChange);
            }
            Debug.Log(percentageChange);
            Debug.Log(difference);
            Debug.Log(finalPosition);

            transform.localPosition = finalPosition;
            //transform.localScale = Vector3.Lerp(transform.localScale, new Vector3(zoomChange, zoomChange, zoomChange), 0.2f * Time.deltaTime);
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
        }

        /*/if (Input.GetKeyDown (KeyCode.Space))
         * {
         * timer = 3;
         * if (count >= annotations.Count)
         * {
         * count = 0;
         * }
         * currentMarker = count;
         * count += 1;
         * //Component light = annotations[currentMarker].transform.GetChild(1).GetComponent("Light");
         * //light.GetType().GetProperty("enabled").SetValue(light, true, null);
         * annotations[currentMarker].SetActive(true);
         *      //Vector3 annotationPosition = new Vector3(Random.Range(gameObject.transform.position.x - 2.5f, gameObject.transform.position.x + 2.5f), yPosition + 0.1f, Random.Range(gameObject.transform.position.z - 2.5f, gameObject.transform.position.z + 2.5f));
         *      //annotations.Add((Transform)Instantiate(annotationPrefab, annotationPosition, Quaternion.identity));
         * }/*/

        /*/if (Input.GetKeyDown (KeyCode.R))
         * {
         * foreach(GameObject annotation in annotations)
         * {
         * //Component light = annotation.transform.GetChild(1).GetComponent("Light");
         * //light.GetType().GetProperty("enabled").SetValue(light, false, null);
         * annotation.SetActive(false);
         * }
         * }/*/

        timer -= Time.deltaTime;
        if (timer <= 0)
        {
            //Component light = annotations[currentMarker].transform.GetChild(1).GetComponent("Light");
            //light.GetType().GetProperty("enabled").SetValue(light, false, null);
        }

        //zoom += zoomChange;
        //gameObject.transform.localScale += new Vector3(zoomChange, zoomChange, zoomChange);

        Mapbox.Utils.Vector2d mapboxMovement = new Mapbox.Utils.Vector2d(movement.z, movement.x);
        attachment.UpdateMap(attachment.CenterLatitudeLongitude - (mapboxMovement), zoom);

        changeHeight += height;

        yPosition = changeHeight;

        Vector3 temp = new Vector3(gameObject.transform.position.x, yPosition, gameObject.transform.position.z);

        gameObject.transform.position = temp;

        float   currentAngle    = attachment.transform.eulerAngles.y;
        Vector3 zedMiniPosition = new Vector3(zed.transform.position.x, attachment.transform.position.y, zed.transform.position.z);
        Vector3 targetLocation  = (Quaternion.Euler(0, angle, 0) * (attachment.transform.position - zedMiniPosition)) + zedMiniPosition;

        attachment.transform.SetPositionAndRotation(targetLocation, Quaternion.Euler(0, (currentAngle + angle), 0));
    }
Пример #5
0
    IEnumerator Start()
    {
        pointClass = new Points();
        var anim     = GetComponent <Animator>();
        int walkHash = Animator.StringToHash("Walk");

        totalDistance = 0;
        // First, check if user has location service enabled
        if (!Input.location.isEnabledByUser)
        {
            yield break;
        }

        Input.location.Start();

        // Wait until service initializes
        int maxWait = 20;

        while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
        {
            yield return(new WaitForSeconds(1));

            maxWait--;
        }

        // Service didn't initialize in 20 seconds
        if (maxWait < 1)
        {
            print("Timed out");
            yield break;
        }

        // Connection has failed
        if (Input.location.status == LocationServiceStatus.Failed)
        {
            print("Unable to determine device location");
            yield break;
        }
        else
        {
            float[]  oldgps      = new float[] { Input.location.lastData.latitude, Input.location.lastData.longitude };
            Vector2d oldLocation = new Vector2d(oldgps[0], oldgps[1]);

            while (Input.location.status == LocationServiceStatus.Running)
            {
                Vector2d newLocation = new Vector2d(Input.location.lastData.latitude, Input.location.lastData.longitude);
                if (newLocation.x == oldLocation.x && newLocation.y == oldLocation.y)
                {
                    anim.ResetTrigger(walkHash);
                }
                else
                {
                    anim.SetTrigger(walkHash);
                }
                map.UpdateMap(newLocation, map.Zoom);
                Calcdistance(oldgps[0], oldgps[1], Input.location.lastData.latitude, Input.location.lastData.longitude);
                distanceText.text = ("Distance: " + Math.Round(totalDistance, 2) + " km").Replace('.', ',');
                pointText.text    = "Points: " + pointClass.setPoints(totalDistance, amountMeters);


                oldLocation = newLocation;
                oldgps[0]   = Input.location.lastData.latitude;
                oldgps[1]   = Input.location.lastData.longitude;
                yield return(new WaitForSeconds(3));
            }
        }
        // Stop service if there is no need to query location updates continuously
        Input.location.Stop();
    }