PavolHejný Posted October 2, 2018 Share Posted October 2, 2018 Hi, I am using Babylon.js with HTC Vive and WebVR and I want to pick a point on the mesh (this.wallMesh) with controller ray. I don't want to use default VRHelper interactions. I expected that this code should work for it but it seems that there is wrong rotation because the rotation of the device behaves totally weird. Do you have some tips on how to fix it? Thank you a lot. const pickMesh = BABYLON.Mesh.CreateSphere( 'pickMesh', 5, 0.1, this.scene, ); const ray = new BABYLON.Ray( BABYLON.Vector3.Zero(), BABYLON.Vector3.One(), 100, ); this.scene.registerAfterRender(() => { ray.origin = controller.devicePosition; ray.direction = controller.deviceRotationQuaternion.toEulerAngles(); const hit = this.wallMesh! .getScene() .pickWithRay(ray, (mesh) => mesh === this.wallMesh); if (hit) { console.log(hit.hit); if (hit.pickedPoint) { pickMesh.position = hit.pickedPoint; } } }); Quote Link to comment Share on other sites More sharing options...
Guest Posted October 2, 2018 Share Posted October 2, 2018 Pinging @trevordev PavolHejný 1 Quote Link to comment Share on other sites More sharing options...
trevordev Posted October 2, 2018 Share Posted October 2, 2018 Hey @PavolHejný, from a quick look ray.direction = controller.deviceRotationQuaternion.toEulerAngles(); looks incorrect, instead to get a direction for your ray you can rotate a forward vector by your rotation quaternion. var m = new BABYLON.Matrix(); controller.deviceRotationQuaternion.toRotationMatrix(m); var direction = Vector3.TransformCoordinates(BABYLON.Vector3.Forward(), m); Let me know if that doesn't work. PavolHejný 1 Quote Link to comment Share on other sites More sharing options...
PavolHejný Posted October 2, 2018 Author Share Posted October 2, 2018 @trevordev Thanks a lot. Your code is working perfectly! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.