Sign in to follow this  
coolroar

Yaw Pitch Roll

Recommended Posts

Hey All,

Another help request:

I want ZOOM's steering controls to more closely resemble an airplane (or my idea of a space-ship).
Currently Zoom turns left-right (yaw) by incrementing camera.rotation.y
and up-down (pitch) by incrementing camera.rotation.x.
Playground: https://www.babylonjs-playground.com/index.html#2UFUC3#2

It works, but yaw is not correct: when I pitch so view is up (world), and then attempt to turn left (yaw),
I expect to turn away from world up. Instead, the view spins around a world vertical axis.

I believe I could make it work if camera.rotation could apply to local space as is possible with meshes.
https://www.babylonjs-playground.com/#LLNE9E#1

But I can't find a camera.rotate(...) function like pilot1.rotate(axis, deltaTheta, BABYLON.Space.LOCAL) for meshes.

I hope this is in BABYLONjs somewhere 'cause matrix orders and conventions will proly overload my elderly mental agility.
😧

Share this post


Link to post
Share on other sites

Hey!

Actually you have to control the camera in camera local world.

This means something like:

- Instead of updating camera.rotation.y when turning left of right, you may want to create a vector3 like (0,offset, 0) and then transform this vector using  inverse of camera.worldMatrix

- Then use the transformed vector to add to camera.rotation

This **should** work (At least it work in my mind :))

Share this post


Link to post
Share on other sites

I've been poking at this for a while, trying various matrices from camera with or without invert or transpose.

BABYLON.Matrix.Transpose(camera.getWorldMatrix()) works at first but is soon overcome by some instability.

Pg: https://www.babylonjs-playground.com/index.html#2UFUC3#5

Desired effect: view scrolls linearly in direction of mouse. 😕

Share this post


Link to post
Share on other sites
On 8/24/2018 at 11:07 AM, coolroar said:

Interesting, dizzying screen dance.
It seems like one of the matrices in camera with Invert or Transpose (with untranslate, op, translate if not at origin) should work with minimal tweaking.
Or how about add method camera.rotate(axis, angle, BABYLON.Space.LOCAL) lifted from mesh?


Or... focus, understand, create function:



function helm( currentCamRotation, mouseX, mouseY ) {
	...
	...
	return newCamRotation;
}

Desired effect: camera pans strait toward mouse.

I'm gonna work on the helm function.

I'll check back here to see if anyone's beat me to a solution.

Thanks!

 

Share this post


Link to post
Share on other sites

Woo hoo!!

@dbawel thats it!

I thought I had tried that before without success, but with this try it's doing just what I want!

PG: https://www.babylonjs-playground.com/index.html#2UFUC3#8

I'm very happy! Eager to plug it into ZOOM!

Oops, I just thought of the likely complications of moving camera & parent away from origin.

But anyway........

Thanks so much!

Share this post


Link to post
Share on other sites
On 8/24/2018 at 12:13 PM, Deltakosh said:

- Instead of updating camera.rotation.y when turning left of right, you may want to create a vector3 like (0,offset, 0) and then transform this vector using  inverse of camera.worldMatrix

- Then use the transformed vector to add to camera.rotation

This **should** work (At least it work in my mind :))

It works. Delta & crew helped on step 3-4 (above). : )

That world inversion syntax:

    /*CONVERT WORLD COORDINATES INTO LOCAL*/
    var invertParentWorldMatrix = worldObj.getWorldMatrix().clone();
    invertParentWorldMatrix.invert();
    var local_position = BABYLON.Vector3.TransformCoordinates(pickPointNext, invertParentWorldMatrix);

Thinking, pickPointNext is where the vector3(0,offset,0) goes. 

Maybe it helps? Could understand world inversions better! Awesome how matrix math works ....

: )

Share this post


Link to post
Share on other sites

Premature enthusiasm in my previous post. It did not work reliably in my app that alters camera's parent in render loop.

Also camera.getFrontPosition(frontOffset) cannot work right. And perhaps others as well.

So, I dived into BJS source and grafted mesh.rotate(...) to camera.

It works just like I want with no problems in my app at https://jounce.space.

A good PG demo:    https://www.babylonjs-playground.com/index.html#I3J22V#1

Thanks to All for your help & encouragement! 👍

Now someone take this and run with it to make it easy to build a flight simulator!

(Not me, I've got other fish to fry!)

B)

 

Edited by coolroar
solved

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.