JonVarner Posted November 13, 2018 Share Posted November 13, 2018 Hey all, I have a use case where I have two camera positions, A and B. I am currently using an arc camera. What I would like to do is rotate the camera from position A to position B using the shortest path over a period of frames. I am confident I could code this but wanted to double check there wasn't already a built in function somewhere that I was unaware of? Just seems like it would be a pretty common task. Anyway, I just did want to invent the wheel if it was already available somewhere. Quote Link to comment Share on other sites More sharing options...
trevordev Posted November 13, 2018 Share Posted November 13, 2018 I'm not aware of this being built into the arcRotationCamera. You could use animations https://www.babylonjs-playground.com/#QYFDDP#1 for this but personally I would manually move the position/rotation within an scene.onBeforeRenderFrame callback Quote Link to comment Share on other sites More sharing options...
JonVarner Posted November 13, 2018 Author Share Posted November 13, 2018 Ok thanks. I will try and post whatever I and up with here for others that might run into something similar. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 14, 2018 Share Posted November 14, 2018 Hi Guys! I once did some mesh "spin" and "spinTo" funcs, and they work for arcCams too. https://www.babylonjs-playground.com/#HH1U5#87 Lines 2-6 temporarily adds spinTo() onto this-scene-created arcCams. Some demo calls are in lines 75-85. I'm not a pro coder, so there could be tweaks needed. I think there are 10 types of easing available in BJS. I used CubicEase cuzzzz... it seemed to work nice. You might run into SOME issues... for camera.alpha... in regards to WHICH WAY TO SPIN to get to new target-alpha value. Possibly, spinTo() needs a 4th parameter, a "positive" or "negative" to indicate which direction to rotate to new target. Sorry if I ruined the adventure-fun of writing an arcCam spinTo() animator. Note: Internet Explorer may dislike the ()=> usage in lines 75-85 demo calls. If problems in IE occur, use this format: setTimeout(function(){camera.spinTo("beta", 1.2, 20), 1000}); Quote Link to comment Share on other sites More sharing options...
JonVarner Posted November 14, 2018 Author Share Posted November 14, 2018 Oh cool, thanks. I will check it out. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 15, 2018 Share Posted November 15, 2018 I think... you can also use your CURRENT SpinTo animator... to animate the camera.target. Just change the whichProp to 'target'. An ArcCam target is a vector3 value (like invisibleMesh.position). An ArcCam lockedTarget is EITHER a mesh or a vector3. Animating arcCam targets and lockedTargets... is often used for "click on mesh to make cam look at clicked mesh". When user clicks a mesh, you can animate camera.target to clickedMesh.position. It's not really a "spinTo" in the classic sense, but it still works. It's more like moveTo(), eh? *nod* 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.