Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by s3738367 · Sep 08, 2018 at 01:17 PM · cameravrwebgltrackinggyro

Rotate object from headmovement using webvr?,Rotate object from head tracking movement? usingWEBVR asset store?

I'm trying to have a camera rotate around an object via headtracking movement. I'm using WEBVR as I want it to go on with all devices and on html. Two options:

  1. Trying to move the camera around the object.. while object stays stationary if somehow I can make camera node go around using lookat on object but then camera node should be linked to headvr movement. I was able to do a normal lookat fixed point using mouse coordinates but not in VR.

  2. Other option , keeping camera still and rotating the object via headmovement. This will also involve disabling movement of camera.

I'm fairly new to unity and coding, and then VR coding. I tried lookat functions and somehow try to put it in webvrcamera.cs script which comes in webvrassets. But nothing worked. Please help me get around a sol.

webvrcamera.cs_:

 private Camera cameraMain, cameraL, cameraR;
 private bool vrActive = false;

 [DllImport("__Internal")]
 private static extern void PostRender();

 private IEnumerator endOfFrame()
 {
     // Wait until end of frame to report back to WebVR browser to submit frame.
     yield return new WaitForEndOfFrame();
     PostRender ();
 }

 void OnEnable()
 {
     WebVRManager.Instance.OnVRChange += onVRChange;
     WebVRManager.Instance.OnHeadsetUpdate += onHeadsetUpdate;
     
     cameraMain = GameObject.Find("CameraMain").GetComponent<Camera>();
     cameraL = GameObject.Find("CameraL").GetComponent<Camera>();
     cameraR = GameObject.Find("CameraR").GetComponent<Camera>();

     cameraMain.transform.Translate(new Vector3(0, WebVRManager.Instance.DefaultHeight, 0));
 }

 void Update()
 {
     if (vrActive)
     {
         cameraMain.enabled = false;
         cameraL.enabled = true;
         cameraR.enabled = true;
     }
     else
     {
         cameraMain.enabled = true;
         cameraL.enabled = false;
         cameraR.enabled = false;
     }

     #if !UNITY_EDITOR && UNITY_WEBGL
     // Calls Javascript to Submit Frame to the browser WebVR API.
     StartCoroutine(endOfFrame());
     #endif
 }

 private void onVRChange(WebVRState state)
 {
     vrActive = state == WebVRState.ENABLED;
 }

 private void onHeadsetUpdate (
     Matrix4x4 leftProjectionMatrix,
     Matrix4x4 leftViewMatrix,
     Matrix4x4 rightProjectionMatrix,
     Matrix4x4 rightViewMatrix,
     Matrix4x4 sitStandMatrix)
 {
     if (vrActive)
     {
         SetTransformFromViewMatrix (cameraL.transform, leftViewMatrix * sitStandMatrix.inverse);
         cameraL.projectionMatrix = leftProjectionMatrix;
         SetTransformFromViewMatrix (cameraR.transform, rightViewMatrix * sitStandMatrix.inverse);
         cameraR.projectionMatrix = rightProjectionMatrix;
     }
 }

 // According to https://answers.unity.com/questions/402280/how-to-decompose-a-trs-matrix.html
 private void SetTransformFromViewMatrix(Transform transform, Matrix4x4 webVRViewMatrix)
 {
     Matrix4x4 trs = TransformViewMatrixToTRS(webVRViewMatrix);
     transform.localPosition = trs.GetColumn(3);
     transform.localRotation = Quaternion.LookRotation(trs.GetColumn(2), trs.GetColumn(1));
     transform.localScale = new Vector3(
         trs.GetColumn(0).magnitude,
         trs.GetColumn(1).magnitude,
         trs.GetColumn(2).magnitude
     );
 }

 // According to https://forum.unity.com/threads/reproducing-cameras-worldtocameramatrix.365645/#post-2367177
 private Matrix4x4 TransformViewMatrixToTRS(Matrix4x4 openGLViewMatrix)
 {
     openGLViewMatrix.m20 *= -1;
     openGLViewMatrix.m21 *= -1;
     openGLViewMatrix.m22 *= -1;
     openGLViewMatrix.m23 *= -1;
     return openGLViewMatrix.inverse;
 }

,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

237 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Native VR - which api call gives floor offset of HMD?? 1 Answer

Tracked Pose Driver has position support range error on VR 0 Answers

Am I able to add a video clip in VR project (Google VR and Cardboard) in Unity? 1 Answer

Enable a non-VR camera only when the Rift is removed 0 Answers

Camera.RenderToCubemap in VR has black edges 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges