Exemple #1
0
        public void PoseUpdate(PSMoveDataContext DataContext, Transform ParentGameObjectTransform)
        {
            Matrix     TrackingSpaceToWorldSpacePosition = Matrix.Identity;
            Quaternion OrientationTransform = Quaternion.Identity;

            PSMoveUtility.ComputeTrackingToWorldTransforms(
                ParentGameObjectTransform,
                ref TrackingSpaceToWorldSpacePosition,
                ref OrientationTransform);

            if (DataContext.GetIsSeenByTracker())
            {
                // The PSMove position is given in the space of the rift camera in centimeters
                Vector3 PSMPosTrackingSpace = DataContext.GetTrackingSpacePosition();
                // Transform to world space
                Vector3 PSMPosWorldSpace =
                    Vector3.TransformCoordinate(PSMoveUtility.PSMoveCSToUnityCSPosition(PSMPosTrackingSpace),
                                                TrackingSpaceToWorldSpacePosition);

                // Save the resulting position, updating for internal offset
                UncorrectedWorldPosition = PSMPosWorldSpace;
                WorldPosition            = PSMPosWorldSpace - ZeroPosition;
            }

            // The PSMove orientation is given in its native coordinate system
            Quaternion PSMOriNative = DataContext.GetTrackingSpaceOrientation();
            // Apply controller orientation first, then apply orientation transform
            Quaternion PSMOriWorld =
                PSMoveUtility.PSMoveQuatToUnityQuat(PSMOriNative) * OrientationTransform;

            // Save the resulting pose, updating for internal zero yaw
            UncorrectedWorldOrientation = PSMOriWorld;
            WorldOrientation            = ZeroYaw * PSMOriWorld;
        }
Exemple #2
0
        public void Update()
        {
            // Get the latest state from the
            dataContext.ComponentRead(transform.parent);

            // Button Pressed Handlers
            if (OnButtonTrianglePressed != null && dataContext.GetButtonTrianglePressed())
            {
                OnButtonTrianglePressed(this, EventArgs.Empty);
            }
            if (OnButtonCirclePressed != null && dataContext.GetButtonCirclePressed())
            {
                OnButtonCirclePressed(this, EventArgs.Empty);
            }
            if (OnButtonCrossPressed != null && dataContext.GetButtonCrossPressed())
            {
                OnButtonCrossPressed(this, EventArgs.Empty);
            }
            if (OnButtonSquarePressed != null && dataContext.GetButtonSquarePressed())
            {
                OnButtonSquarePressed(this, EventArgs.Empty);
            }
            if (OnButtonSelectPressed != null && dataContext.GetButtonSelectPressed())
            {
                OnButtonSelectPressed(this, EventArgs.Empty);
            }
            if (OnButtonStartPressed != null && dataContext.GetButtonStartPressed())
            {
                OnButtonStartPressed(this, EventArgs.Empty);
            }
            if (OnButtonPSPressed != null && dataContext.GetButtonPSPressed())
            {
                OnButtonPSPressed(this, EventArgs.Empty);
            }
            if (OnButtonMovePressed != null && dataContext.GetButtonMovePressed())
            {
                OnButtonMovePressed(this, EventArgs.Empty);
            }

            // Button Released Handlers
            if (OnButtonTriangleReleased != null && dataContext.GetButtonTriangleReleased())
            {
                OnButtonTriangleReleased(this, EventArgs.Empty);
            }
            if (OnButtonCircleReleased != null && dataContext.GetButtonCircleReleased())
            {
                OnButtonCircleReleased(this, EventArgs.Empty);
            }
            if (OnButtonCrossReleased != null && dataContext.GetButtonCrossReleased())
            {
                OnButtonCrossReleased(this, EventArgs.Empty);
            }
            if (OnButtonSquareReleased != null && dataContext.GetButtonSquareReleased())
            {
                OnButtonSquareReleased(this, EventArgs.Empty);
            }
            if (OnButtonSelectReleased != null && dataContext.GetButtonSelectReleased())
            {
                OnButtonSelectReleased(this, EventArgs.Empty);
            }
            if (OnButtonStartReleased != null && dataContext.GetButtonStartReleased())
            {
                OnButtonStartReleased(this, EventArgs.Empty);
            }
            if (OnButtonPSReleased != null && dataContext.GetButtonPSReleased())
            {
                OnButtonPSReleased(this, EventArgs.Empty);
            }
            if (OnButtonMoveReleased != null && dataContext.GetButtonMoveReleased())
            {
                OnButtonMoveReleased(this, EventArgs.Empty);
            }

            bool seen = dataContext.GetIsSeenByTracker();

            // Update the transform of this game object based on the new pose

            if (useInterpolation)
            {
                if (seen)
                {
                    lerpTarget = dataContext.Pose.WorldPosition;
                }
                transform.position = Vector3.Lerp(transform.position, lerpTarget, lerpRate);
            }
            else if (seen)
            {
                transform.position = dataContext.Pose.WorldPosition;
            }
            transform.rotation = dataContext.Pose.WorldOrientation;
        }