Home › Forums › Programming › zoomCamera Puzzle with Offset
- This topic has 4 replies, 4 voices, and was last updated 3 years, 2 months ago by gaso.
-
AuthorPosts
-
2021-09-22 at 10:15 am #45005webCustomer
I just had to extend the zoomCamera function with a offset. If anyone got the same “issue” here is the altered function:
// zoomCamera puzzle function zoomCamera(objSelector, duration, offset, doSlot) { duration = Math.max(0, duration); var objNames = retrieveObjectNames(objSelector); var zoomObjects = []; objNames.forEach(function(name) { var obj = getObjectByName(name); if (obj) { zoomObjects.push(obj); } }); if (!zoomObjects.length) { return; } var camera = appInstance.getCamera(); var pos = _pGlob.vec3Tmp, target = _pGlob.vec3Tmp2; v3d.CameraUtils.calcCameraZoomToObjectsParams(camera, zoomObjects, pos, target); if(offset){ pos.x += offset; pos.y += offset; pos.z += offset; } if (appInstance.controls && appInstance.controls.tween) { // orbit and flying cameras if (!appInstance.controls.inTween) { appInstance.controls.tween(pos, target, duration, doSlot); } } else { // TODO: static camera, just position it for now if (camera.parent) { camera.parent.worldToLocal(pos); } camera.position.copy(pos); camera.lookAt(target); doSlot(); } }
I just added the variable
offset
which is just a number, which gets added to the calculated position when set. This way I can control the distance of the camera to the object I would like to zoom on.There will be for sure a better approach, but this one is working for me. Maybe the devs can implement that functionality in the future to the function “the right way”.
2021-09-22 at 5:16 pm #45043xeonCustomerThis is great.
How / why did you need this? Whats the use case?Xeon
Route 66 Digital
Interactive Solutions - https://www.r66d.com
Tutorials - https://www.xeons3dlab.com2021-09-23 at 7:53 am #45107webCustomerGot some clickable objects where I want the camera to zoom on. I liked the idea of the zoomCamera puzzle but was never happy that you cant control the offset. Because the zoom tries to get the object into the full viewport size, which is much to big.
In the past I just created cameras by hand were I tweened the active camera to, but I was to lazy doing this to 11 objects, so I looked at the zoomCamera funtion a little bit closer.
2021-09-23 at 8:46 am #45120Yuri KovelenovStaff2021-10-02 at 5:20 pm #45728gasoCustomerSomething like this would be very useful for the camera tween as well, especially for responsive workflows.
I have project with info popups that are on the left side of the screen in desktop, and bottom of the screen for mobile devices. The camera zoom locations that work for desktop are not optimal for mobile users. I could do different zoom locations for both mobile & desktop and switch accordingly, but that’s quite a lot of work to set up… Being able to define camera offset & zoom amount for each target would save a ton of time.
-
AuthorPosts
- You must be logged in to reply to this topic.