How can I pan/move the camera in Three.js using mouse movement without the need to click?

I am currently working on panning the camera around my scene using the mouse. I have successfully implemented this feature using TrackballControls by click and dragging.

function init(){
  camera = new THREE.PerspectiveCamera(45,window.innerWidth / window.innerHeight, 1, 1000);
  camera.position.z = 500;

  controls = new THREE.TrackballControls(camera);
  controls.addEventListener('change', render);
}

function animate(){
  requestAnimationFrame(animate);
  controls.update();
}

Is there a way to achieve this without the need for clicking? I am looking for a similar solution to the panning on this site ...

I have also created a codepen showcasing my progress so far.

Thank you :)

Answer №1

Figured it out on my own!

For those attempting a similar task, I implemented some changes to the TrackballControls.js file. You can view the adjustments I made here.

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

JSON parsing throws an error due to encountering an 'unexpected end of input' issue

Here's some code I'm working with: var default_links = '{ "name" : "Google", "url": "https://encrypted.google.com/", "fav_url": "https://encrypted.google.com/favicon.ico" }\n'+ '{ "name" : "Yahoo", "url": "http://www. ...

The height of the iframe with the id 'iframe' is not functioning as expected

I am trying to set the iFrame's height to 80% and have an advertisement take up the remaining 20%. Code <!DOCTYPE html> <html lang="en"> <head> </head> <body> <iframe id="iframe" src="xxxxxx" style="border: ...

Tips for effectively implementing a curried selector function with the useSelector hook in react-redux

In my project using react-redux with hooks, I encountered a situation where I needed a selector that takes a parameter which is not passed as a prop. Upon checking the documentation, it mentioned: The selector function does not receive an ownProps argum ...

How can I prevent clicks on child links using the :not() selector?

I am working on a script using JQuery where I want to add a click handler to a div while ignoring clicks on the children a tags within it. You can check out my attempt (which is not working as expected) on this JSFiddle link: http://jsfiddle.net/q15s25Lx/ ...

Retrieve the user-inputted data from an Electron BrowserView's input field

Consider this scenario where a BrowserWindow is set up with specific security settings, including enabling the webviewTag: true for project requirements. let webPrefs = { plugins: false, nodeIntegration: false, nodeIntegrationInWorker: false, ...

Exclusively utilize optgroup multiple functionality within bootstrap-select

I'm currently utilizing https://github.com/snapappointments/bootstrap-select/ version 1.13.18 and I am in need of a solution where only optgroup options can have multiple selections. This means that if a non-optgroup option is selected, all other opti ...

Determine browser compatibility by evaluating the DOM Level

Can we easily determine which browser versions and above are compatible with a certain DOM level? ...

Learn the steps to resolve pagination issues in React. When the first page loads, ensure all data is displayed properly. Click

Here is an excerpt from my code snippet: const Inventory = () => { const [products, setProducts] = useState([]); const [pageCount,setPageCount] = useState(0); //console.log(pageCount); const [page,setPage] = useState(0); const navigate = useNa ...

What is the process for displaying the current bitcoin price on an HTML page using API integration?

I'm looking to develop an application that can display the current Bitcoin price by fetching data from the API at . I want to showcase this information within an h2 element. Any suggestions on how I could achieve this? Thank you in advance. const e ...

Troubleshooting angular service jasmine test - unable to locate $http service

As I followed the tutorial at , I encountered an issue with the jasmine test provided. Despite simplifying the test to its core, it still fails to pass. Could someone point out where I might be going wrong? The service being tested is: var appServices = ...

Leveraging the power of Bootstrap and JavaScript to implement a custom Toast feature

I am utilizing Bootstrap 4 to design Toasts, and I am presently developing a JavaScript function to generate a toast. My attempt to create elements within the JS file did not properly style it. index.html <!doctype html> <html lang="en"> ...

Changing the map behavior when it is moved in Leaflet

I am currently using Leaflet to design a map that includes a personalized sound layer. Each tile on the map features an <audio> element, and I am exploring methods to adjust the audio playback as the user navigates around the map (specifically by mod ...

Sending information from Vue to Express for processing

Is there a way to pass data from Vue to an express server? For example, in the scenario below, I am looking to send the data logged in my Vue function to the "id" variable on the server side. expressApp.post('/delete' , function (request, respons ...

Tips for Preventing Unnecessary Ajax Requests

What I require When a click event is triggered, a service call should be made only once. Use case Dropdown1 Dropdown2 Dropdown3 1. There are three dropdowns on the HTML page. 2. When Dropdown1 is called - an AJAX call is made only onc ...

The issue with Mongoose populate failing to populate

I'm facing an issue with populating my users' car inventory. Each car has a userId attached to it upon creation, but for some reason, the population process isn't working as expected, and no errors are being displayed. Let's take a loo ...

What is the best method to transfer an array as a parameter from an Ipython notebook to an HTML file that includes specific javascript functions?

I have a unique HTML file named "file.html" that includes a distinctive JavaScript function described below: The Unique file.html <html> <head> </head> <script> function customFunction() { perform an action using ...

Encountering NPM install gyp errors in VSCode indicating that gyp is searching for Visual Studio

Running npm install on a local project has been quite challenging for me, as I keep encountering errors every time I try. Fortunately, some valuable information I found related to gyp and Python helped me make some progress. However, I'm currently fac ...

Place the Material-UI Drawer component beneath the Appbar in the layout

Currently, I am working on developing a single-page application using Material-UI. In this project, I have integrated the use of an AppBar along with a ToolBar and a Drawer. However, I have encountered an issue where the Drawer is overlapping the AppBar an ...

What is the best way to merge different Vue JS instances (each linked to different html divs) into one cohesive unit using Vue

Essentially, I have a scenario where I've created two HTML divs named vueapp1 and vueapp2. Both of these divs serve the same purpose of displaying information and are linked to their individual Vue instances for extracting JSON data and presenting it. ...

Creating a project that utilizes Bing Translate and the Node.js programming language

As I work on developing a web application that enables users to translate text using the Bing translator API, I am facing an issue. I attempted to execute a translator.js file via a script tag, but encountered a roadblock since Node.js code cannot be run t ...