Is there a way to retrieve the current zoom level when using three.js perspectiveCamera with orbitControl?

I am attempting to determine the current zoom level in a Three.js scene. Specifically, I am interested in detecting the "zoom" or dolly effect applied by the mouse wheel action. For instance, imagine a simple scene consisting of a perspective camera, orbit controls, and an object.

1: `<= see the test here

controls = new THREE.OrbitControls( camera );
controls.dollyOut = function(){    }
controls.dollyIn = function(){    }

controls.addEventListener('change', renderlog); ....` 

Thank you!

Answer №1

When utilizing a PerspectiveCamera along with OrbitControls, it is important to note that the concept of "zooming" functions differently compared to an orthographic camera. Instead of adjusting a zoom variable, you achieve the effect of "zooming" by moving the camera closer to the target.

This implies that you can determine the zoom distance by calculating the distance between the target and the camera position.

var zoom = controls.target.distanceTo(controls.object.position)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Ajax to dynamically submit specific form fields

I'm just starting out with Jquery ajax, and I'm experimenting with submitting specific fields for validation instead of the entire form. I've created a function to check if a username is available, and it's working well. However, I want ...

Is it recommended to employ a switch statement in order to link CSS IDs with JavaScript variables?

function getVariableFromID(ID) { switch (ID) { case "GTA1": return GTA1; case "GTA2": return GTA2; case "GTA3": return GTA3; ... case "GTJ0": return GTJ0; } } In my code, I have implement ...

Can a File Object be transmitted to an AWS Lambda function via API Gateway using JavaScript?

Can a JavaScript File Object be passed from a browser to AWS Lambda via API Gateway (ultimately to S3)? I am working with TypeScript and React. Environment Frontend TypeScript React AWS Amplify (for API module) Backend(AWS Lambda) Node.js Expecta ...

The resizing effect in jQuery causes a blinking animation

I would like to create a functionality where, when the width of .tabla_gs_gm surpasses the width of .content, .tabla_gs_gm disappears and another div appears in its place. While this is already working, there seems to be a screen flicker between the two d ...

Is it possible to obtain a return value from Electron's webContents.executeJavaScript when NodeIntegration is disabled?

Is there a way to retrieve a return value without using NodeIntegration in Electron, similar to ipcRenderer when it's enabled? ...

excessive memory usage in a simple react-native application

My experience with creating my first react native app has been more challenging than I initially expected. I'm having trouble understanding what I might be doing wrong. Initially, the app is simple, fetching data through Redux. componentWillMount() ...

What is the best way to vertically align an InputLabel within a MUI Grid item?

I'm trying to vertically center the InputLabel inside a MUI Grid item. Here's what I've attempted: import { FormControl, Grid, Input, InputLabel, TextField } from "@mui/material"; export default function App() ...

Playing Sound Instantly in JavaScript without delay

I have successfully implemented playing sound with keys using HTML and .play. However, there is a delay as it waits for the track to finish playing before allowing me to play it again instantly upon each click. I am seeking a solution to trigger the sound ...

Repeatedly animate elements using jQuery loops

Whenever I click a button, a fish should appear and randomly move over a container at random positions. However, in my current code, the animation only occurs once and does not repeat continuously. I want to create a generic function that can be used for m ...

"Troubleshooting the issue of ng-init not functioning properly in conjunction

I need help with displaying a list of numbers inside a div element. I am attempting to achieve this using the following code snippet: <div ng-init="range=[1,10,3,4,5]" ng-repeat="n in range" > {{n}} </div> Unfortunately, the numbers withi ...

Determine the Orientation of an Accelerometer using a JavaScript function in Node-RED

Is there a way to determine the orientation of a sensor using a JavaScript function? I came across an example on 3D Accelerometer calculate the orientation, but I'm struggling to understand how to utilize the values of msg.payload.xAxis/yAxis/zAxis fo ...

Discover a method to obtain the indexof() starting from the last character of a string

I'm wondering how to determine the number of characters after the "|" symbol in this string: "354-567-3425 | John Doe". I did some research and only came across the javascript indexOf() method. While this method is useful for finding characters before ...

Looking for assistance with resizing and repositioning an image within a viewport?

The JSFiddle code can be found at this link - https://jsfiddle.net/pmi2018/smewua0k/211/ Javascript $('#rotate').click(function(e) { updateImage(90, 0) console.log("rotation"); }); $('#zoom-in').click(function() { updateImage(0 ...

Displaying a Key/Value pair as a clickable link using AngularJS

Having difficulty generating links from KeyValue pairs in an object using AngularJS. The object is created in C# with the code snippet below: Dictionary<int, string> page = new Dictionary<int, string>(); updatedCountryNodesLis ...

A guide to displaying PDF content within a React.js application

For a specific scenario, I need to fetch PDF content using axios.get and then display it on the UI. In my setup, React.js is used for the front end and Express.js serves as the backend. Due to restrictions, the front end React app cannot directly call th ...

Press on the menu <li> item to create additional submenus

A group of friends is facing a challenge. They want to create a dropdown sub-menu that appears directly below the selected item when clicking on a link from a menu. So far, they have been able to use ajax to send requests and generate a sub-menu. However, ...

Can I invoke a specific function from a controller in AngularJS?

I am new to developing in the MEAN stack and working on a Todo App where I create tasksheets and store todos within those specific tasksheets using AngularJS. Initially, I was retrieving all todos without considering which tasksheet they belonged to or cr ...

Attach a click event to images that are dynamically loaded through AJAX

I've been struggling with a particular block of code, and after careful investigation, I believe I have pinpointed the issue. Let me share with you the jQuery function in question... $(document).ready(function(e) { $('#formattingSection&apos ...

Create a video file using binary data obtained from a socket connection

I have successfully created a socket connection and am sending binary stream data to the server. On the server side, I am receiving the binary data and now I want to use this data to create a video file and save it on the server. However, I am struggling t ...

Select the input by clicking on the <a> text

Is there a way to ensure that clicking on the text within the <a> tag activates the checkbox instead of closing the drop-down menu? Currently, when someone clicks on the text of the checkbox, the drop-down menu closes. Here is the code snippet in que ...