Gerente Posted July 30, 2015 Share Posted July 30, 2015 As you can see in this test I'm trying to be able to drag the blue ball around the wireframed sphere with circular movement. Basically im trying to locate an object inside the wireframed sphere, the wireframed sphere will have a texture 360 panoramic.http://www.babylonjs-playground.com/#1282WV I have 3 problems with my code: when I drag the ball the cursor move faster than the ball. There is a way to detect the sensitivity of the move so the cursor move togheter with the ball?It is only move in the plane XY move the mouse LEFT and RIGHT. How can I add Y Axis to the movement?there is any function "lookAt" as in Unity3d?, so I can drag an object (like a plane with text) and the text will be always facing the camera. Thanks! Quote Link to comment Share on other sites More sharing options...
jahow Posted July 30, 2015 Share Posted July 30, 2015 Hey! So I worked a bit on your code. Here is what I came up with: http://www.babylonjs-playground.com/#1282WV#1 I did several things:made the camera a FreeCamera instead of an ArcRotateCamera (that couldn't be precisely placed in the center of the sphere)deaattached the camera controls, otherwise I had problem making this work properlyadded a bit of code to make the camera follow the sphere position with a delaythe position of the mesh is now determined by unprojecting the mouse coordinates in 3D space, thus allowing us to know precisely where the ball needs to be. This is done with this code:var radius = 5;// mesh position is the mouse position projected back in 3D spacevar mesh_pos = BABYLON.Vector3.Unproject(mouse_position.clone(),camera.viewport.width, camera.viewport.height,BABYLON.Matrix.Identity(),camera.getViewMatrix(),camera.getProjectionMatrix());// mesh position is set at a constant radius from the sphere centermesh_pos.normalize().scaleInPlace(radius);currentMesh.position = mesh_pos; I commented out the parts of your code that were not needed anymore. Hope this is clear enough & helpful to you! jerome, Blax, iiceman and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Gerente Posted July 30, 2015 Author Share Posted July 30, 2015 Thank you Jahow!!. The ball moves perfect, But I can't move the camera anymore. On mouse UP should I dettach the FreeCamera and attach the ArcCamera? so I can continue looking around the sphere? Quote Link to comment Share on other sites More sharing options...
jahow Posted July 30, 2015 Share Posted July 30, 2015 You're welcome I don't think you need two cameras. ArcRotateCamera is not really suited for your case if I'm not mistaken. FreeCamera = the camera remains in one position and looks around. ArcRotateCamera = the camera looks at one fixed point and rotates around it. What you could do is have a variable that indicates if the camera is in "tracking" mode or not, i.e. if it follows the sphere position. When the user clicks on the sphere, the camera goes into tracking mode and stays that way until the user clicks elsewhere (not on the sphere). Then tracking mode is off, controls are reattached to the camera and the code that makes the camera look at the sphere is skipped. Not sure if that would work well though... 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.