coolroar Posted September 13, 2018 Share Posted September 13, 2018 I have a minimal flight simulator here: https://www.babylonjs-playground.com/#UL7W2M and at my website jounce.space/flightsimhome that can be full-screened (f11) and has skybox as shown here: The code that makes the flight simulation possible: var camera = new BABYLON.UniversalCamera("cam", BABYLON.Vector3.Zero(), scene); addYawPitchRollFunction(camera, 1); where addYawPitchRollFunction(...) is defined as: function addYawPitchRollFunction(ob, gravity) { ob.rotationQuaternion = new BABYLON.Quaternion(); ob.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(ob.rotation.y, ob.rotation.x, ob.rotation.z); ob.myGrav = gravity; ob.yawPitchRoll = function(yaw, pitch, roll) { var axis = new BABYLON.Vector3(0, 0, -1); var partRotQuat = new BABYLON.Quaternion(); BABYLON.Quaternion.RotationAxisToRef(axis, roll, partRotQuat); this.rotationQuaternion.multiplyInPlace(partRotQuat); BABYLON.Quaternion.RotationAxisToRef(axis.set(-1, 0, 0), pitch, partRotQuat); this.rotationQuaternion.multiplyInPlace(partRotQuat); BABYLON.Quaternion.RotationAxisToRef(axis.set(0, 1, 0), yaw, partRotQuat); this.rotationQuaternion.multiplyInPlace(partRotQuat); this.rotationQuaternion.toEulerAnglesToRef(this.rotation); } ob.autoBank = function(yaw, pitch, speed) { var axis = new BABYLON.Vector3(0, 0, -1); var partRotQuat = new BABYLON.Quaternion(); var roll = Math.atan2(-yaw*222*speed, this.myGrav); this.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, roll); BABYLON.Quaternion.RotationAxisToRef(axis.set(-1, 0, 0), pitch, partRotQuat); this.rotationQuaternion.multiplyInPlace(partRotQuat); BABYLON.Quaternion.RotationAxisToRef(axis.set(0, 1, 0), yaw, partRotQuat); this.rotationQuaternion.multiplyInPlace(partRotQuat); this.rotationQuaternion.toEulerAnglesToRef(this.rotation); } ob.clearYawPitchRoll = function() { this.rotationQuaternion.set(0, 0, 0, 1); this.rotation.set(0,0,0); } } Now you can add increments of yaw, pitch, & roll to camera's orientation: camera.yawPitchRoll(yawInc, pitchInc, rollInc); Or for automatically coordinated turns: camera.autoBank(yawInc, pitchInc, speed); Look at https://www.babylonjs-playground.com/#UL7W2M as a complete example. I welcome your comments, corrections, suggestions, & accolades! ? Enjoy! - - QuintusHegie, jerome and NasimiAsl 3 Quote Link to comment Share on other sites More sharing options...
jerome Posted September 13, 2018 Share Posted September 13, 2018 really nice coolroar and NasimiAsl 2 Quote Link to comment Share on other sites More sharing options...
coolroar Posted September 13, 2018 Author Share Posted September 13, 2018 Thanks. Well, some of us are not overwhelmed by the EXUBERANT colors ?! Quote Link to comment Share on other sites More sharing options...
Guest Posted September 14, 2018 Share Posted September 14, 2018 Excellent! Quote Link to comment Share on other sites More sharing options...
Rob G Posted October 17, 2018 Share Posted October 17, 2018 Ohh very cool ? coolroar 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.