coolroar Posted August 24, 2018 Share Posted August 24, 2018 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. ? Quote Link to comment Share on other sites More sharing options...
Guest Posted August 24, 2018 Share Posted August 24, 2018 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 :)) coolroar and JackFalcon 2 Quote Link to comment Share on other sites More sharing options...
coolroar Posted August 24, 2018 Author Share Posted August 24, 2018 Oh, good! Can't wait to try it! But other duties call. After I get to it, i'll post results. @Deltakosh Thanks! Quote Link to comment Share on other sites More sharing options...
Guest Posted August 24, 2018 Share Posted August 24, 2018 My pleasure..keep us posted Quote Link to comment Share on other sites More sharing options...
coolroar Posted August 25, 2018 Author Share Posted August 25, 2018 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. ? Quote Link to comment Share on other sites More sharing options...
Guest Posted August 27, 2018 Share Posted August 27, 2018 Was more thinking about something like that: https://www.babylonjs-playground.com/index.html#2UFUC3#6 (but this needs tweaking) JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
coolroar Posted August 27, 2018 Author Share Posted August 27, 2018 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! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted August 28, 2018 Share Posted August 28, 2018 I recommend parenting your camera to a mesh. Here's post discussing this. DB GameMonetize and coolroar 2 Quote Link to comment Share on other sites More sharing options...
coolroar Posted August 28, 2018 Author Share Posted August 28, 2018 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! Quote Link to comment Share on other sites More sharing options...
JackFalcon Posted August 28, 2018 Share Posted August 28, 2018 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 .... : ) coolroar 1 Quote Link to comment Share on other sites More sharing options...
coolroar Posted September 1, 2018 Author Share Posted September 1, 2018 (edited) 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!) Edited September 4, 2018 by coolroar solved GameMonetize 1 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.