コード例 #1
0
    public void PoseUpdate(PSMoveDataContext DataContext, Transform ParentGameObjectTransform)
    {
        Matrix4x4  TrackingSpaceToWorldSpacePosition = Matrix4x4.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 =
                TrackingSpaceToWorldSpacePosition.MultiplyPoint3x4(
                    PSMoveUtility.PSMoveCSToUnityCSPosition(PSMPosTrackingSpace));

            // 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 =
            OrientationTransform * PSMoveUtility.PSMoveQuatToUnityQuat(PSMOriNative);

        // Save the resulting pose, updating for internal zero yaw
        UncorrectedWorldOrientation = PSMOriWorld;
        WorldOrientation            = ZeroYaw * PSMOriWorld;
    }
コード例 #2
0
    void Update()
    {
        // Get the latest state from the
        dataContext.ComponentRead(this.gameObject.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);
        }

        // Update the transform of this game object based on the new pose
        if (dataContext.GetIsSeenByTracker())
        {
            this.gameObject.transform.position = dataContext.Pose.WorldPosition;
        }
        this.gameObject.transform.rotation = dataContext.Pose.WorldOrientation;

        // Show the HMD frus
        if (ShowHMDFrustumDebug)
        {
            PSMoveUtility.DebugDrawHMDFrustum(this.gameObject.transform.parent);
        }
    }