Exemplo n.º 1
0
    void Update()
    {
        timeSinceLastUpdate += Time.deltaTime;
        if (skeletonManager == null)
        {
            RUISSkeletonManager.JointData jointData = skeletonManager.GetJointData(jointToFollow, player.kinectPlayerId, player.bodyTrackingDeviceID);

            PointData newPoint = new PointData(jointData.position, jointData.rotation, timeSinceLastUpdate, Time.timeSinceLevelLoad, previousPoint);

            //remove zero velocities just in case, in order for the speeds not to get polluted by nonexisting data
            //if (newPoint.velocity == Vector3.zero) return;

            points.Add(newPoint);
            previousPoint = newPoint;

            Normalize();
            MoveToStart();

            while (points[points.Count - 1].startTime - points[0].startTime >= bufferLength)
            {
                points.RemoveAt(0);
            }
        }
        //if (points.Count > bufferSize) points.RemoveAt(0);

        InvalidateCaches();

        //Debug.Log(averageSpeed);

        timeSinceLastUpdate = 0;
    }
Exemplo n.º 2
0
    void Update()
    {
        if (!skeletonManager || !skeletonManager.skeletons[playerId].isTracking)
        {
            return;
        }

        RUISSkeletonManager.JointData jointData = skeletonManager.GetJointData(jointToFollow, playerId);
        if (jointData.positionConfidence > minimumConfidenceToUpdate)
        {
            transform.localPosition = Vector3.Lerp(transform.localPosition, jointData.position, positionSmoothing * Time.deltaTime);
        }
        if (jointData.rotationConfidence > minimumConfidenceToUpdate)
        {
            transform.localRotation = Quaternion.Slerp(transform.localRotation, jointData.rotation, rotationSmoothing * Time.deltaTime);
        }
    }
Exemplo n.º 3
0
    public void Update()
    {
        if (!isTracking && skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking)
        {
            PlayerFound();
        }
        else if (isTracking && !skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking)
        {
            PlayerLost();
        }
        else if (!skeletonManager.skeletons[bodyTrackingDeviceID, playerId].isTracking)
        {
            return;
        }

        if (!highlightStartObject && wandSelector.HighlightedObject)
        {
            highlightStartObject = wandSelector.HighlightedObject;
            gestureRecognizer.EnableGesture();
        }
        else if (!wandSelector.HighlightedObject)
        {
            highlightStartObject = null;

            if (!wandSelector.Selection)
            {
                gestureRecognizer.DisableGesture();
            }
        }

        visualizerThreshold = Mathf.Clamp01(visualizerThreshold);

        RUISSkeletonManager.JointData startData = skeletonManager.GetJointData(wandStart, playerId, bodyTrackingDeviceID);
        RUISSkeletonManager.JointData endData   = skeletonManager.GetJointData(wandEnd, playerId, bodyTrackingDeviceID);

        if (endData.positionConfidence >= 0.5f)
        {
            // TUUKKA: Original code
//            transform.localPosition = endData.position;
//
//            if (startData != null && startData.positionConfidence >= 0.5f)
//            {
//                transform.localRotation = Quaternion.LookRotation(endData.position - startData.position);
//            }
//            else if (endData.rotationConfidence >= 0.5f)
//            {
//                transform.localRotation = endData.rotation;
//            }

            // First calculate local rotation
            if (startData != null && startData.positionConfidence >= 0.5f)
            {
                tempVector = endData.position - startData.position;
                if (Vector3.Angle(startData.rotation * Vector3.up, tempVector) > 5)
                {
                    tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.up);
                }
                else
                {
                    tempRotation = Quaternion.LookRotation(endData.position - startData.position, startData.rotation * Vector3.right);
                }

                filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime);                 // HACK with kinect2 filtering is done in SkeletonManager
            }
//            else if (endData.rotationConfidence >= 0.5f)
//            {
//				tempRotation = endData.rotation;
//				filteredRotation = rotationFilter.Update(tempRotation, Time.deltaTime);
//            }

            if (rigidbody)
            {
                // TUUKKA:
                if (transform.parent)
                {
                    // If the wand has a parent, we need to apply its transformation first
                    rigidbody.MovePosition(transform.parent.TransformPoint(endData.position));
                    rigidbody.MoveRotation(transform.parent.rotation * filteredRotation);
                }
                else
                {
                    rigidbody.MovePosition(endData.position);
                    rigidbody.MoveRotation(filteredRotation);
                }
            }
            else
            {
                // If there is no rigidBody, then just change localPosition & localRotation
                transform.localPosition = endData.position;
                transform.localRotation = filteredRotation;
            }
        }
    }
Exemplo n.º 4
0
    private void doYawFiltering(float deltaT)
    {
        switch (driftingSensor)
        {
        case DriftingRotation.OculusRift:
            if (OVRDevice.IsSensorPresent(oculusID))
            {
                OVRDevice.GetOrientation(oculusID, ref driftingRot);
                if (oculusCamController)
                {
                    // In the future OVR SDK oculusCamController will have oculusID?
                    oculusCamController.SetYRotation(-finalYawDifference.eulerAngles.y);
                }
            }
            break;

        case DriftingRotation.RazerHydra:
            // TODO
            //driftingRot = hydraRotation;
            break;

        case DriftingRotation.InputTransform:
            if (driftingTransform)
            {
                driftingRot = driftingTransform.rotation;
            }
            break;
        }

        if (driftingDirectionVisualizer != null)
        {
            driftingDirectionVisualizer.transform.rotation = driftingRot;
        }

        driftingEuler = driftingRot.eulerAngles;

        switch (compass)
        {
        case CompassSource.Kinect:
            if (!skeletonManager || !skeletonManager.skeletons[kinectPlayerID].isTracking)
            {
                break;
            }
            else
            {
                compassData = skeletonManager.GetJointData(compassJoint, kinectPlayerID);

                // First check for high confidence value
                if (compassData != null && compassData.rotationConfidence >= 1.0f)
                {
                    updateDifferenceKalman(compassData.rotation.eulerAngles,
                                           driftingEuler, deltaT);
                }
            }
            break;

        case CompassSource.PSMove:

            if (inputManager)
            {
                compassMove = inputManager.GetMoveWand(PSMoveID);
                if (compassMove)
                {
                    updateDifferenceKalman(compassMove.localRotation.eulerAngles,
                                           driftingEuler, deltaT);
                }
            }
            break;

        case CompassSource.InputTransform:
            if (compassTransform != null)
            {
                updateDifferenceKalman(compassTransform.rotation.eulerAngles,
                                       driftingEuler, deltaT);
            }
            break;
        }

        float normalizedT = Mathf.Clamp01(deltaT * driftCorrectionRate);

        if (normalizedT != 0)
        {
            finalYawDifference = Quaternion.Lerp(finalYawDifference, filteredYawDifference,
                                                 normalizedT);
        }

        if (correctedDirectionVisualizer != null)
        {
            correctedDirectionVisualizer.transform.rotation = Quaternion.Euler(
                new Vector3(driftingEuler.x,
                            (360 + driftingEuler.y
                             - finalYawDifference.eulerAngles.y) % 360,
                            driftingEuler.z));
        }
        //driftingRotation*Quaternion.Inverse(finalDifference);
        if (correctedDirectionVisualizer != null && driftVisualizerPosition != null)
        {
            correctedDirectionVisualizer.transform.position = driftVisualizerPosition.position;
        }
    }