Jump to content

Moving FreeCamera with DOM Buttons


devbot
 Share

Recommended Posts

I've been scratching my head a bit on this and feel it should be much easier than it is turning out to be.

 

I have a freeCamera in a scene which can be controlled with WASD.

What I also have is a UI with the WASD keys which light up when the user presses those keys.

 

Lastly I'm trying to have those keys mousedown to also move the free camera in the same way they keys do.

 

What I've been trying to work with is something along the lines of

case: "forward"freeCamera.cameraDirection += BABYLON.Vector3.Cross(freeCamera.position,freeCamera.rotation) * speed;break;case: "back"freeCamera.cameraDirection -= BABYLON.Vector3.Cross(freeCamera.position,freeCamera.rotation) * speed;break;

 

And about 50 variations of that.

 

I started out with simply assigning each key to an axis and moving along it, which is all well and good until you rotate the camera.

 

 

Link to comment
Share on other sites

Hi guys.  Many folk parent the camera to an invisible mesh, and then do all their orientations and translations on the parent "camera gizmo".  *shrug*  An option.

 

Ped-up and ped-down seem like important camera movements (up and down the Y axis)... but not found on a default free camera. 

 

I wired those actions to control-upcursor and control-downcursor, in a project once (plotting vertices in space).  I didn't modify the free camera itself.  I just built my own ped-up/down funcs that did the job.  You guys can do the same for spinning the camera around z-axis (rolling)... as needed.

 

Also... umm... devbot... think about continuously using cam.setTarget(something)...  on every frame.  Maybe even better... free camera is a subClass of TargetCamera... which also has a .lockedTarget property.  The free camera inherits that property, of course. 

 

These might be usable features for this issue, too.  Party on!

Link to comment
Share on other sites

Thanks for the input,

 

I saw this thread which lead me to this result.

 

function drive_camera(axis){   var move_direction = BABYLON.Vector3.TransformNormal(axis, freeCamera.getWorldMatrix());    freeCamera.cameraDirection = move_direction   }

 

Where axis is a variation of BABYLON.Vector3(1, 0, 0); depending on the button clicked/mousedown (WASD)

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