Rotation limited to z and x axes with Three.js TrackballControls.js

Is there a way to configure TracballControls in threejs to restrict movement to only two axes, specifically pan and tilt without roll? I am looking for a solution that can achieve this functionality. Here is the link to my current code: . The desired behavior for mouse movement should resemble this example: .

Answer №1

Here is a solution that worked for me:

If you're facing an issue, check your TrackballControl.js file and make the following change on line 148:

before:

_this.object.up.applyQuaternion( quaternion );

after:

_this.object.up.applyQuaternion( new THREE.Vector4(0,0,0,1) );

//Note: This fix applies to older versions only.

Answer №2

Even though this information may be outdated, I wanted to share how I successfully implemented it since it remains the top search result on Google.

To prevent rolling (locking the z-axis), you can stop rotateCamera() from modifying the camera's Up vector.

To achieve this, simply comment out the following line (approximately line 200):

_this.object.up.applyQuaternion(quaternion);

If desired, you can also restrict the camera's rotation vector by adding either:

_this.object.rotation.z = 0; 

or

_this.object.rotation.set(0, 0, 0);

to the end of the function. However, in my experience, this adjustment didn't have a significant impact since most of the rotation occurs due to the camera's movement in relation to its lookAt target (_this.target in the trackballControls.js file).

Answer №3

After making some adjustments, I modified the variable

this.noPan

at line 26 to be set as false. I also uncommented

_this.object.up.applyQuaternion( quaternion );

Additionally, I raised the value of

this.dynamicDampingFactor = 0.2;

to 0.8.

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

Is it Feasible to Incorporate HTML like <a href..in a JavaScript File?

Recently, I had a question about creating a custom mailto share button that would open a window for users to enter email addresses they want to send to. While seeking advice on this matter (How to Create a Mailto Share Button that Opens a Window in which O ...

In order for the Facebook share button to appear, a page reload is required when using Angular

I've been working on integrating Facebook's share plugin, but I've encountered an issue where the share button only shows up after reloading the page. If I navigate to the page through a link or URL, the button doesn't appear until afte ...

JQuery encountered a HTTP 404 error, signaling that the server was unable to locate anything that matched the requested URI

I am currently learning front-end development on my own and encountered an issue with implementing jQuery. You can find all the files for my site here: The problem I am facing is that there should be blog posts displayed between the header and navigation ...

Verify the placement within the text box

Are there methods available in JavaScript or any JavaScript framework to determine the position within a textbox? For example, being able to identify that figure 1 is at position 2 and figure 3 is at position 3. Figure 1 Figure 2 ...

Having trouble locating an element in Selenium Chrome using JavaScript

I'm automating a webpage using JavaScript and selenium, which involves clicking on several buttons. To start off, my code establishes a connection with the existing chrome window in the following way: var chrome = require("selenium-webdriver/chro ...

Using Meteor JS to save images in MongoDB

Looking to save an image uploaded via a file input into a database. Utilizing the redactor plugin to browse the image with the following code: $('.editor').redactor({ imageUpload:"/uploads" }); Once an image is selected or browsed, it is se ...

The functionality of jQuery .on() method does not apply to dynamically generated elements

Currently, I am in the process of developing a website where a logout button is dynamically inserted into a sidebar when the window reaches a specific size. Upon clicking the log out button, I intend to execute the method logOut(); The anchor tag ID is co ...

The database is not being updated with the new values

Is it possible to retrieve data from a database and modify it using AJAX? I tried changing the input, but AJAX keeps sending the original data stored in the database. <script> function showMore(str) { var xhttp; if (str.length == ...

JavaScript is limited to displaying values and does not have the capability to show XML

I am in the process of creating a manufacturing website that focuses on different types of cords used in various countries. The goal is to display information from an XML page once a country has been selected from the dropdown menu. However, I am currently ...

What is the best way to reference an ImageButton using jquery?

I created an HTML page with a special div in the body that contains a collection of buttons and images. <div id="div_one"> <button id="button_one"> <asp:Image id="image_button_one" ImageUrl=".." runat="server"> </button> </div& ...

Looping through JSON data to dynamically generate DIV elements

Currently, I have in my possession a JSON array that contains various values. To convert this List to JSONArray, I employed the JSON-lib and some groovy classes. Along with the JSON array, I also have a JS file and a JSF for the front end. My task at hand ...

Why is the state object empty in this React Native function?

One React-Native component I have is responsible for rendering an image gallery in a list format. This component is called once for each item on the parent list. It takes two props: "etiqueta," which contains the title of the item, and "galleries," which i ...

Combining Gulp with Browserify using Globs

After following the recipe from the official gulp repo for using browserify with multiple entry points, everything worked smoothly when I only had one file. However, now that I am trying to run the task for multiple files, it displays the following tasks ...

Is there a way to showcase array data on a datatable by utilizing Ajax?

I am currently utilizing a MongoDB database to store some important data. I am now looking to showcase this data on an HTML Datatable. The data that I am attempting to utilize is organized in arrays, and here is its structure: data: [[1848, 84857], [4944 ...

Compatible with pure vanilla JavaScript, but not jQuery

I am currently facing an issue with attaching VKI (Virtual Keyboard Interface) to an element that is dynamically added to the DOM using JavaScript. The scenario involves a table with initially only one row, along with "Add Row" and "Delete Row" functionali ...

Error: While testing an AngularJS controller with Karma, there was an issue accessing the property 'then' of an undefined variable

I'm currently working on writing unit tests for a controller that receives a promise from a service. However, when using Jasmine, I encounter the following error: TypeError: Cannot read property 'then' of undefined Within the controller, I ...

Guide for using JavaScript to obtain the current line position within a contenteditable div during a keypress event

I am in the process of developing a customized editor using a contenteditable div. I require a javascript code that can determine the line position of the current caret position during a keypress event. It should be able to adapt when new lines are added o ...

Transform asynchronous calls into synchronous calls

During my time building web applications in PHP, I was accustomed to handling tasks synchronously. Currently, my focus is on constructing a web scraper. The process involves: Obtaining a list of proxies Verifying the status of the proxies Scraping web c ...

Implicitly pass "this" by utilizing an inline event listener

var functionVariable = (function() { return { 'initialize': function(className) { // Here, I need to access the <a> tag and apply the specified className } }; }()); <a href="#" onmouseover="functionVariable.i ...

Find similarities between 2 observable arrays and store them in a new array using knockout data binding

There are three observable arrays set up as follows: a [1,3] b [ {"ID": 1, "Val": "Value1"}, {"ID":2, "Val":"Value2"}, {"ID":3, "Val":"Value3"}] c [] The goal is to compare array a with the IDs of elements in array b and then push the entire value of arr ...