Jump to content

Sphere Movement with Pivot Vector3.Zero


Gerente
 Share

Recommended Posts

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!

 

Link to comment
Share on other sites

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 properly
  • added a bit of code to make the camera follow the sphere position with a delay
  • the 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!

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...