Exemplo n.º 1
0
 private void CalculateCurrentPose()
 {
     if (GetIsTrackedRemote())
     {
         CurrentPose = new PoseFrame
         {
             voiceAmplitude      = voiceAmplitude,
             headPosition        = headPos,
             headRotation        = headRot,
             handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTrackedRemote),
             handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTrackedRemote),
             handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTrackedRemote),
             handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTrackedRemote),
             controllerLeftPose  = GetMalibuControllerPose(OVRInput.Controller.LTrackedRemote),
             controllerRightPose = GetMalibuControllerPose(OVRInput.Controller.RTrackedRemote),
         };
     }
     else
     {
         CurrentPose = new PoseFrame
         {
             voiceAmplitude      = voiceAmplitude,
             headPosition        = headPos,
             headRotation        = headRot,
             handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
             handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
             handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
             handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
             controllerLeftPose  = GetControllerPose(OVRInput.Controller.LTouch),
             controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
         };
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 75個のデータを受けて、サーボ情報を調べます。
        /// </summary>
        /// <param name="servoStrings"></param>
        /// <returns></returns>
        PoseFrame ParseOneFrame(string[] servoStrings)
        {
            if (servoStrings.Length != 80)
            {
                Debug.LogError("不正なフレームです");
            }

            PoseFrame ret = new PoseFrame();

            ret.commandLength  = servoStrings[0];
            ret.command        = servoStrings[1];
            ret.commandPadding = servoStrings[2];
            ret.frameWait      = servoStrings[3];

            ret.wait = HexToInt(ret.frameWait);

            //25軸だと信じていますよ
            for (int i = 0; i < 25; i++)
            {
                Servo tmp = new Servo();
                tmp.id         = servoStrings[4 + i * 3];
                tmp.hb         = servoStrings[4 + i * 3 + 1];
                tmp.lb         = servoStrings[4 + i * 3 + 2];
                tmp.servoValue = ServoStringToValue(servoStrings[4 + (i * 3) + 1], servoStrings[4 + (i * 3) + 2]);
                tmp.eulerAngle = (tmp.servoValue - 7500) * 0.03375f; //0.03375= 135/4000
                ret.servos.Add(tmp);
            }

            //checkbyte
            ret.checkByte = servoStrings[79];
            return(ret);
        }
Exemplo n.º 3
0
        void ApplyPose(PoseFrame prevFrame, PoseFrame nextFrame, float weight)
        {
            foreach (var prevServo in prevFrame.servos)
            {
                float angle = prevServo.eulerAngle;

                string id        = prevServo.id;
                var    nextServo = nextFrame.servos.First(servo => servo.id.Equals(id));
                if (nextServo != null)
                {
                    // -135~135 [deg] ということだとLeapAngle()は一旦 +180 してから -180 とかしないとダメかも
                    //angle = Mathf.LerpAngle(prevServo.eulerAngle, nextServo.eulerAngle, weight);

                    // サーボが 360 [deg] 回らないため、単にLerp()で良いのでは
                    angle = Mathf.Lerp(prevServo.eulerAngle, nextServo.eulerAngle, weight);
                }

                try
                {
                    var modelJoint = _joints.FirstOrDefault(joint => joint.ServoID == prevServo.id);
                    if (modelJoint != null)
                    {
                        modelJoint.SetServoValue(angle);
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("some exeption:" + e);
                }
            }
        }
            public void DisposeFrames()
            {
                if (colorFrame != null)
                {
                    colorFrame.Dispose();
                    colorFrame = null;
                }

                if (depthFrame != null)
                {
                    depthFrame.Dispose();
                    depthFrame = null;
                }

                if (infraredFrame != null)
                {
                    infraredFrame.Dispose();
                    infraredFrame = null;
                }

                if (poseFrame != null)
                {
                    poseFrame.Dispose();
                    poseFrame = null;
                }
            }
Exemplo n.º 5
0
 private void CalculateCurrentPose()
 {
     // Platform and device agnostic calls to return center eye pose, used to pass in head pose to sdk
     OVRNodeStateProperties.GetNodeStatePropertyVector3(UnityEngine.XR.XRNode.CenterEye, NodeStatePropertyType.Position,
                                                        OVRPlugin.Node.EyeCenter, OVRPlugin.Step.Render, out centerEyePosition);
     OVRNodeStateProperties.GetNodeStatePropertyQuaternion(UnityEngine.XR.XRNode.CenterEye, NodeStatePropertyType.Orientation,
                                                           OVRPlugin.Node.EyeCenter, OVRPlugin.Step.Render, out centerEyeRotation);
     Debug.Log("gggg");
     if (!is_hand_movment_locked)
     {
         Debug.Log("log");
         CurrentPose = new PoseFrame
         {
             voiceAmplitude      = voiceAmplitude,
             headPosition        = centerEyePosition,
             headRotation        = centerEyeRotation,
             handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
             handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
             handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
             handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
             controllerLeftPose  = GetControllerPose(OVRInput.Controller.LTouch),
             controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
         };
     }
 }
 public override bool GetCurrentPose(out PoseFrame pose)
 {
     if (currentPose != null)
     {
         pose = currentPose;
         return(true);
     }
     pose = null;
     return(false);
 }
 public override bool GetCurrentPose(out PoseFrame pose)
 {
     if (currentPose.HasValue)
     {
         pose = currentPose.Value;
         return(true);
     }
     pose = new PoseFrame();
     return(false);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 指定コマ(本当はフレーム)に該当する姿勢を前後の姿勢から補間して返す
        /// </summary>
        /// <param name="koma"></param>
        void ApplyPoseByKoma(int koma)
        {
            if (_frames.Count < 1)
            {
                // キーフレームが1つもなければ何もしない
                return;
            }
            else if ((_frames.Count == 1) || (koma < _frames[0].wait))
            {
                // キーフレームが1つしかないか、指定コマが負なら先頭の姿勢を単にとる
                currentFrame = 0;
                ApplyPose(currentFrame);
                return;
            }

            PoseFrame prevFrame = _frames[0];
            PoseFrame nextFrame = null;

            currentFrame = 0;

            int   elapsedKoma = prevFrame.wait;
            float weight      = 0f;

            for (int frameNumber = 1; frameNumber < _frames.Count; frameNumber++)
            {
                nextFrame = _frames[frameNumber];

                // 次のフレームで指定時刻以上になるなら、ここが求めたいタイミングである
                if ((elapsedKoma + nextFrame.wait) >= koma)
                {
                    // 2つのコマ間の重みを0~1で求める
                    weight = Mathf.Clamp01((float)(koma - elapsedKoma) / nextFrame.wait);
                    break;
                }

                elapsedKoma += nextFrame.wait;
                prevFrame    = nextFrame;

                currentFrame = frameNumber;
            }

            // 最後まで指定タイミングが見つからなければ、最終姿勢をとらせる
            if (prevFrame == nextFrame)
            {
                currentFrame = _frames.Count - 1;
                ApplyPose(currentFrame);
                return;
            }

            // 2つのキーフレームの間の姿勢をとらせる
            ApplyPose(prevFrame, nextFrame, weight);
        }
Exemplo n.º 9
0
    private void CalculateCurrentPose()
    {
#if UNITY_2017_2_OR_NEWER
        Vector3 headPos = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye):
#else
        Vector3 headPos = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye):
#endif
#if UNITY_ANDROID && !UNITY_EDITOR
        headPos.y += mobileBaseHeadHeight:
#endif

        if (GetIsTrackedRemote())
        {
            CurrentPose = new PoseFrame
            {
                voiceAmplitude = voiceAmplitude,
                headPosition = headPos,
#if UNITY_2017_2_OR_NEWER
                headRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye),
#else
                headRotation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye),
#endif
                handLeftPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTrackedRemote),
                handLeftRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTrackedRemote),
                handRightPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTrackedRemote),
                handRightRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTrackedRemote),
                controllerLeftPose = GetMalibuControllerPose(OVRInput.Controller.LTrackedRemote),
                controllerRightPose = GetMalibuControllerPose(OVRInput.Controller.RTrackedRemote),
            }:
        }
        else
        {
            CurrentPose = new PoseFrame
            {
                voiceAmplitude = voiceAmplitude,
                headPosition = headPos,
#if UNITY_2017_2_OR_NEWER
                headRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye),
#else
                headRotation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye),
#endif
                handLeftPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
                handLeftRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
                handRightPosition = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
                handRightRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
                controllerLeftPose = GetControllerPose(OVRInput.Controller.LTouch),
                controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
            }:
        }

    }
    public override void UpdateTransforms(IntPtr sdkAvatar)
    {
        if (sdkAvatar != IntPtr.Zero)
        {
            PoseFrame pose = GetCurrentPose();

            ovrAvatarTransform      bodyTransform   = OvrAvatar.CreateOvrAvatarTransform(pose.headPosition, pose.headRotation);
            ovrAvatarHandInputState inputStateLeft  = OvrAvatar.CreateInputState(OvrAvatar.CreateOvrAvatarTransform(pose.handLeftPosition, pose.handLeftRotation), pose.controllerLeftPose);
            ovrAvatarHandInputState inputStateRight = OvrAvatar.CreateInputState(OvrAvatar.CreateOvrAvatarTransform(pose.handRightPosition, pose.handRightRotation), pose.controllerRightPose);

            CAPI.ovrAvatarPose_UpdateBody(sdkAvatar, bodyTransform);
            CAPI.ovrAvatarPose_UpdateHands(sdkAvatar, inputStateLeft, inputStateRight);
        }
    }
Exemplo n.º 11
0
 public static PoseFrame Interpolate(PoseFrame a, PoseFrame b, float t)
 {
     return(new PoseFrame
     {
         headPosition = Vector3.Lerp(a.headPosition, b.headPosition, t),
         headRotation = Quaternion.Slerp(a.headRotation, b.headRotation, t),
         handLeftPosition = Vector3.Lerp(a.handLeftPosition, b.handLeftPosition, t),
         handLeftRotation = Quaternion.Slerp(a.handLeftRotation, b.handLeftRotation, t),
         handRightPosition = Vector3.Lerp(a.handRightPosition, b.handRightPosition, t),
         handRightRotation = Quaternion.Slerp(a.handRightRotation, b.handRightRotation, t),
         voiceAmplitude = Mathf.Lerp(a.voiceAmplitude, b.voiceAmplitude, t),
         controllerLeftPose = ControllerPose.Interpolate(a.controllerLeftPose, b.controllerLeftPose, t),
         controllerRightPose = ControllerPose.Interpolate(a.controllerRightPose, b.controllerRightPose, t),
     });
 }
Exemplo n.º 12
0
 private void CalculateCurrentPose()
 {
     CurrentPose = new PoseFrame
     {
         voiceAmplitude      = voiceAmplitude,
         headPosition        = headPos,
         headRotation        = headRot,
         handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
         handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
         handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
         handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
         controllerLeftPose  = GetControllerPose(OVRInput.Controller.LTouch),
         controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
     };
 }
Exemplo n.º 13
0
 public bool MyGetCurrentPose(out PoseFrame pose)
 {
     pose = new PoseFrame
     {
         voiceAmplitude      = voiceAmplitude,
         headPosition        = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye) * 2,
         headRotation        = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye),
         handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
         handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
         handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
         handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
         controllerLeftPose  = GetControllerPose(OVRInput.Controller.LTouch),
         controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
     };
     return(true);
 }
Exemplo n.º 14
0
    private void CalculateCurrentPose()
    {
#if UNITY_2017_2_OR_NEWER
        Vector3 headPos = Vector3.zero;
#else
        Vector3 headPos = Vector3.zero;
#endif

        if (GetIsTrackedRemote())
        {
            CurrentPose = new PoseFrame
            {
                voiceAmplitude = voiceAmplitude,
                headPosition   = headPos,
#if UNITY_2017_2_OR_NEWER
                headRotation = Quaternion.identity,
#else
                headRotation = Quaternion.identity,
#endif
                handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTrackedRemote),
                handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTrackedRemote),
                handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTrackedRemote),
                handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTrackedRemote),
                controllerLeftPose  = GetMalibuControllerPose(OVRInput.Controller.LTrackedRemote),
                controllerRightPose = GetMalibuControllerPose(OVRInput.Controller.RTrackedRemote),
            };
        }
        else
        {
            CurrentPose = new PoseFrame
            {
                voiceAmplitude = voiceAmplitude,
                headPosition   = headPos,
#if UNITY_2017_2_OR_NEWER
                headRotation = Quaternion.identity,
#else
                headRotation = Quaternion.identity,
#endif
                handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
                handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
                handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
                handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
                controllerLeftPose  = GetControllerPose(OVRInput.Controller.LTouch),
                controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
            };
        }
    }
Exemplo n.º 15
0
        void EnqueueFrame(PoseFrame frame)
        {
            var pose = new Pose {
                time = frame.Timestamp
            };

            PoseData data;

            frame.CopyTo(out data);

            var t = data.translation;

            pose.position = new Vector3(t.x, t.y, -t.z);

            var e = data.rotation.eulerAngles;

            pose.rotation = Quaternion.Euler(-e.x, -e.y, e.z);

            lock (_poseQueue) _poseQueue.Enqueue(pose);
        }
Exemplo n.º 16
0
    public override bool GetCurrentPose(out PoseFrame pose)
    {
        Vector3 headPos = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye);

#if UNITY_ANDROID && !UNITY_EDITOR
        headPos.y += mobileBaseHeadHeight;
#endif

        pose = new PoseFrame
        {
            voiceAmplitude      = voiceAmplitude,
            headPosition        = headPos,
            headRotation        = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye),
            handLeftPosition    = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch),
            handLeftRotation    = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch),
            handRightPosition   = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch),
            handRightRotation   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch),
            controllerLeftPose  = GetControllerPose(OVRInput.Controller.LTouch),
            controllerRightPose = GetControllerPose(OVRInput.Controller.RTouch),
        };
        return(true);
    }
Exemplo n.º 17
0
    private void CalculateCurrentPose()
    {
        Transform head  = VRTK_DeviceFinder.HeadsetTransform();
        Transform left  = VRTK_DeviceFinder.GetControllerLeftHand().transform;
        Transform right = VRTK_DeviceFinder.GetControllerRightHand().transform;

        CurrentPose = new PoseFrame
        {
            voiceAmplitude = voiceAmplitude,
            headPosition   = head.position,

            headRotation = head.rotation,

            handLeftPosition  = left.TransformPoint(new Vector3(0.025f, 0, -0.04f)),
            handLeftRotation  = left.rotation,
            handRightPosition = right.TransformPoint(new Vector3(-0.025f, 0, -0.04f)),
            handRightRotation = right.rotation,

            controllerLeftPose  = GetControllerPose(left.GetComponent <VRTK_ControllerEvents>()),
            controllerRightPose = GetControllerPose(right.GetComponent <VRTK_ControllerEvents>())
        };
    }
Exemplo n.º 18
0
        private PoseFrame[] ParseFrames(BinaryDataReader reader)
        {
            var count  = reader.ReadUInt16();
            var frames = new PoseFrame[count];

            for (int i = 0; i < frames.Length; i++)
            {
                var frame = new PoseFrame();
                frame.Time        = reader.ReadFloat40();
                frame.Translation = new double[3];
                for (int o = 0; o < 3; o++)
                {
                    frame.Translation[o] = reader.ReadFloat40();
                }
                frame.RotationAngle = reader.ReadFloat40();
                frame.RotationAxis  = new double[3];
                for (int o = 0; o < 3; o++)
                {
                    frame.RotationAxis[o] = reader.ReadFloat40();
                }
                frames[i] = frame;
            }
            return(frames);
        }
Exemplo n.º 19
0
 public override bool GetCurrentPose(out PoseFrame pose)
 {
     pose = remotePose;
     return(true);
 }
Exemplo n.º 20
0
 public abstract bool GetCurrentPose(out PoseFrame pose);
Exemplo n.º 21
0
 public override bool GetCurrentPose(out PoseFrame pose)
 {
     return(base.GetCurrentPose(out pose));
 }