Exemplo n.º 1
0
    void UpdatePose(params object[] args)
    {
        if (lockHMDPosition && needUpdatePose)
        {
            needUpdatePose = false;
            StillPoses[0]  = WaveVR.Instance.hmd.pose.pose;
            WaveVR_Render.SetPoseUsedOnSubmit(StillPoses[0]);
        }

        if (lockHMDPosition && needSmoothMove)
        {
            if (smoothMoveFrame >= smoothMoveFrameCount || smSpline == null)
            {
                smoothMoveFrame = 0;

                // Copy old value
                MovePoses[0] = StillPoses[0];

                SmoothMovePosesFrom = new WVRMatrix(MovePoses[0].PoseMatrix);
                SmoothMovePosesTo   = new WVRMatrix(WaveVR.Instance.hmd.pose.pose.PoseMatrix);

                smSpline = new MatrixSpline(SmoothMovePosesFrom.GetMatrix(), SmoothMovePosesTo.GetMatrix());

                // save a new one
                StillPoses[0] = WaveVR.Instance.hmd.pose.pose;
            }

            smoothMoveFrame++;
            //Log.d("MovieMode", "smoothMoveFrame=" + smoothMoveFrame);

            if (smoothMoveFrame < smoothMoveNoActionFrameCount)
            {
                return;
            }

            int total = smoothMoveFrameCount - smoothMoveNoActionFrameCount;
            int time  = smoothMoveFrame - smoothMoveNoActionFrameCount;

            // This will accelerate the speed.
            if (needSmoothMoveAccelerate && smCurrent != null)
            {
                SmoothMovePosesTo = new WVRMatrix(WaveVR.Instance.hmd.pose.pose.PoseMatrix);
                smSpline.UpdateFromTo(smCurrent, SmoothMovePosesTo.GetMatrix());
            }

            smCurrent = smSpline.Spline(time / (float)total);

            //Log.d("MovieMode", "From=" + SmoothMovePosesFrom.rot + ", To=" + SmoothMovePosesTo.rot + ", lerp=" + rot);

            WVRMatrix wvrMatrix = new WVRMatrix(smCurrent.pos, smCurrent.rot, false);
            MovePoses[0].PoseMatrix       = wvrMatrix.GetWVRMatrix();
            MovePoses[0].RawPose.position = wvrMatrix.GetWVRPosition();
            MovePoses[0].RawPose.rotation = wvrMatrix.GetWVRRotation();

            WaveVR_Render.SetPoseUsedOnSubmit(MovePoses[0]);
        }
    }
Exemplo n.º 2
0
    public void updateTexture(IntPtr textureId)
    {
        if (!mStarted)
        {
            Log.w(LOG_TAG, "Camera not start yet");
            return;
        }

        //PrintDebugLog("updateTexture start, syncPose = " + syncPose.ToString() + " updateFramebuffer = " + updateFramebuffer.ToString());

        nativeTextureId = textureId;
        if (WaveVR_Render.Instance != null)
        {
            origin = WaveVR_Render.Instance.origin;
        }

        if (syncPose)
        {
            if (mframeBuffer != IntPtr.Zero)
            {
                uint predictInMs = 0;
                PrintDebugLog("updateTexture frameBuffer and PoseState, predict time:" + predictInMs);

                Interop.WVR_GetFrameBufferWithPoseState(mframeBuffer, camerainfo.size, origin, predictInMs, ref mPoseState);

                PrintDebugLog("Sync camera frame buffer with poseState, timeStamp: " + mPoseState.PoseTimestamp_ns);
                WaveVR_Render.SetPoseUsedOnSubmit(mPoseState);

                PrintDebugLog("send event to draw OpenGL");
                WaveVR_Utils.SendRenderEvent(WaveVR_Utils.RENDEREVENTID_DrawTextureWithBuffer);
            }
        }
        else
        {
            if (updateFramebuffer && (threadframeBuffer != IntPtr.Zero))
            {
                PrintDebugLog("updateFramebuffer camera frame buffer");
                nativeTextureId = textureId;
                PrintDebugLog("send event to draw OpenGL");
                WaveVR_Utils.SendRenderEvent(WaveVR_Utils.RENDEREVENTID_DrawTextureWithBuffer);
                updateFramebuffer = false;
            }
            else
            {
                // thread frame buffer is not updated and native texture is not updated, send complete delegate back
                if (UpdateCameraCompletedDelegate != null)
                {
                    UpdateCameraCompletedDelegate(nativeTextureId);
                }
            }
        }
    }
Exemplo n.º 3
0
    void UpdatePose2(object[] args)
    {
        if (lockHMDPosition && needUpdatePose)
        {
            needUpdatePose = false;
            WaveVR_Render.SetPoseUsedOnSubmit(WaveVR.Instance.hmd.pose.pose);
        }

        if (lockHMDPosition && needSmoothMove)
        {
            if (smoothMoveFrame >= smoothMoveFrameCount)
            {
                smoothMoveFrame = 0;

                // Copy old value
                MovePoses[0] = StillPoses[0];

                SmoothMovePosesFrom = new WVRMatrix(MovePoses[0].PoseMatrix);
                SmoothMovePosesTo   = new WVRMatrix(WaveVR.Instance.hmd.pose.pose.PoseMatrix);

                // Record a new one
                StillPoses[0] = WaveVR.Instance.hmd.pose.pose;
            }

            smoothMoveFrame++;
            //Log.d("MovieMode", "smoothMoveFrame=" + smoothMoveFrame);

            if (smoothMoveFrame < smoothMoveNoActionFrameCount)
            {
                return;
            }

            int total = smoothMoveFrameCount - smoothMoveNoActionFrameCount;
            int time  = smoothMoveFrame - smoothMoveNoActionFrameCount;

            var from = SmoothMovePosesFrom.GetMatrix();
            var to   = SmoothMovePosesTo.GetMatrix();
            var pos  = Vector3.Lerp(from.GetPosition(), to.GetPosition(), time / (float)total);
            var rot  = Quaternion.Lerp(from.GetRotation(), to.GetRotation(), time / (float)total);

            //Log.d("MovieMode", "From=" + SmoothMovePosesFrom.rot + ", To=" + SmoothMovePosesTo.rot + ", lerp=" + rot);

            WVRMatrix wvrMatrix = new WVRMatrix(pos, rot, false);
            MovePoses[0].PoseMatrix       = wvrMatrix.GetWVRMatrix();
            MovePoses[0].RawPose.position = wvrMatrix.GetWVRPosition();
            MovePoses[0].RawPose.rotation = wvrMatrix.GetWVRRotation();

            WaveVR_Render.SetPoseUsedOnSubmit(MovePoses[0]);
        }
    }