When using Three.js, adjusting the TranslateX or Y values sometimes results in unexpected rotation instead of a straightforward movement along the axis,

In my Three.js project with TrackballControls, I am working on creating a dynamic 3D scene.

One of the key components is the PerspectiveCamera that I have initialized:

camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 10000);

To enhance user interactivity, I included various buttons for zooming in different directions. The code snippet for zooming in successfully reads:

var button = document.getElementById('ctrlin');
button.addEventListener('click', function (event) {
    camera.translateZ(-100);
}, false);

However, when attempting to use "camera.translateY" or "camera.translateX", it seems to cause unintended rotation of the camera.

I simply want the camera to move along a straight axis without any rotation.

It's possible that this issue relates to a locked gimbal setting, but I'm unsure about how to address it.

Would it be more effective to move the object instead of the camera? And if so, how can I achieve movement along a pure X or Y axis?

Answer №1

When adjusting the position of the camera along the X-axis, it's essential to also adjust the target of the camera by the same amount along the X-axis to prevent rotation. This ensures that the camera continues to focus on the same point.

You can try implementing this approach to resolve the issue you're facing.

Alternatively, you could group both the camera and the target within a container object and move the object as a whole to achieve the desired effect :)

UPDATE:

To see an example of the latter solution with detailed explanation, check out this answer on StackOverflow

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

Injecting CSS styles into a webpage using a Chrome extension before the page has completely loaded to achieve instant customization

As a newcomer to creating Chrome (or other browser) extensions, I am working on developing one that applies custom CSS rules to specific page elements. Overall, it seems to be functioning as intended, but with some minor issues. One issue I have encounter ...

AngularJS modal not functioning properly after sending $http request

I have successfully implemented a pop-up modal in my Angular page using code from a reliable source. However, when I include a button for an HTTP request on the same page, the functionality of the AngularJS modal stops working after the HTTP request is mad ...

Sort items in a list manually using Jquery sortable feature

Is there a way to sort the listitems using either sortList[0] or sortList[1]? Example: http://jsfiddle.net/wmaqb/20/ HTML <div id="sortable"> <div id="sort_18b0c79408a72">Berlin</div> <div id="sort_dkj8das9sd98a" ...

Ways to decrease font size and insert a line break within a constrained input space?

I am facing an issue where the input box remains static with old numbers when it overflows, and newly typed numbers do not appear at all. <!DOCTYPE html> <html> <body> <input type="text" id="output-area" placehold ...

Using flags to translate text on Google should not result in being redirected to another website

I have integrated Google's language picker with country flags into my WordPress template using the code below: <!-- Add English to Chinese (Simplified) BETA --> <a target="_blank" rel="nofollow" onclick="window.open('http://www.google. ...

Show the chosen option when the textarea is no longer in focus

My form includes a text box and a button: <p><textarea rows="4" cols="30">Aliquam erat volutpat.</textarea></p> <p><input type="button" value="Submit"></p> When the user selects text in the textarea and then cl ...

Unresponsive Vanilla Bootstrap Navbar Links

I recently started working with the vanilla version of Bootstrap to create a universal template for a friend's websites. Although I have previous experience with Bootstrap and have never encountered any issues, I am now facing a problem. I want to cla ...

Unable to resolve an unresolved issue with a jquery or javascript bug

I am currently facing some issues with my jQuery code in both Firebug and Chrome's developer tools. Any assistance would be greatly appreciated. Kindly make the necessary updates in the provided fiddle. Please follow this link to access the fiddle: ...

How can I achieve a similar layout in my .cshtml file?

https://i.sstatic.net/f1C0G.png Hey there, I'm looking to achieve a layout similar to the one shown in the image. Specifically, I want the left side panel to remain unchanged when expanding the Accordion control on the right side. Can someone guide ...

JQuery Load fails to load in real-time

I have a PHP file where I am using JQuery to load the content of another file called 'live.php' which should display the current time, but for some reason it is not loading live. Can anyone help me troubleshoot this issue? It used to work perfect ...

Adjust the top margin of content to account for the height of a fixed header

When dealing with a fixed header that has been removed from the HTML flow, it can be tricky to adjust the content below it. The challenge arises because the height of the header can vary based on screen size. How can we dynamically adjust the margin-top fo ...

Customize jqGrid Paging Input Size

Can the size of pginput in jqGrid be changed? By default, it appears like this: <input class="ui-pg-input" type="text" role="textbox" value="0" maxlength="7" size="2"> If no direct way is available, I solved it using the following code snippet: $( ...

Troubleshooting the non-responsive behavior of Bootstrap's hidden-sm-down

Why are the two images within the <div> with hidden-sm-down still visible on my laptop when I resize the page? I need them to be hidden on small devices for a different menu layout. <div class="row"> <div class="col-m ...

Troubleshooting issues with custom global components failing to apply styling in NuxtJs

I have designed various components such as buttons that I want to be able to use and reuse across my entire website. I have already developed plugins Object.entries(components).forEach((([name, component]) => { Vue.component(name, component) })) and ...

Customizing CSS by replacing link file styles with code in the HEAD section

UPDATE: After further examination, it appears that the code is functioning correctly. My apologies for any confusion. I am attempting to override certain CSS rules on specific pages. Below is an example of my approach. Can anyone confirm if this is a vali ...

How can I add animation to an HTML5 video using jQuery?

How can we add animation to an HTML5 video element? <div id="cont"> <video id="movie" width="320" height="240" preload controls> <source src="pr6.ogv" type='video/ogg; codecs="theora, vorbis"'> <source src="p ...

Leveraging the power of PHP includes with nested subdirectories

Hello, I recently configured my web server to run all .html files as .php files, allowing me to utilize the php include function, which has been very beneficial. However, I have various subdirectories with multiple files in each one. Homepage --banners ...

CSS styling does not apply to HTML elements that are dynamically created using JavaScript

A script containing dynamic HTML content is sourced from an external website, injected by RSS feeds. To access the content directly, visit this link. The script needs to be wrapped around HTML tags for front-end display. For example: <div>http://fe ...

The code is not executing properly in the javascript function

Hello there! I've created a basic login form with JavaScript validation, but for some reason, the code below isn't functioning properly. Here is my HTML and JS code: <head> <script type="text/javascript"> function ha ...

In JavaScript, you can ensure that only either :after or :before is executed, but not both

My html slider is causing me some trouble <div class="range-handle" style="left: 188.276px;">100,000</div> Upon loading the page, I noticed that in Firebug it appears like this https://i.sstatic.net/Rgqvo.png On the actual page, it looks li ...