Unusual vibrations experienced when using Orbit Controls to rotate the camera in Three.js

I am currently working on a project to create a model of the Solar System. Here is the metric I am using:

scale = 0.001;
// 1 unit - 1 kilometer
var AU = 149597871 * scale;

To set up the camera, renderer, and controls, I have defined them as follows:

camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1 * scale, 0.1 * AU);
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
controls = new THREE.OrbitControls(camera, renderer.domElement);

When the user selects a planet or moon to view, I adjust the camera position accordingly with this function:

function cameraGoTo() {
    for (var i = scene.children.length - 1; i >= 0 ; i--) {
        var obj = scene.children[i];
        if (obj.name == parameters.selected) {
            controls.target = obj.position;
            camera.position.copy(obj.position);
            camera.position.y += obj.radius * 2;
        }
    }
}

The Issue arises when viewing small planets or moons (radius <= 1000 km) as the camera shakes while rotating around the object. I have limited knowledge in computer graphics and I'm unsure if this problem originates from the Orbit Controls or the renderer itself. I attempted to resolve it by setting logarithmicDepthBuffer = true but had no success. Adjusting the scale parameter also did not make any difference.

Thank you in advance for any guidance or assistance provided.

EDIT:

A fiddle demonstration can be found here: http://jsfiddle.net/twxyz/8kxcdkjj/

It is evident that the shaking increases under the following conditions:

  • the smaller the object,
  • the further away the object is from the center of the scene,

What could be causing this issue? It appears unrelated to the near/far spectrum values of the camera and more related to the distance of objects from the scene's center.

Answer №1

I've found the solution to my issue.

The problem I encountered stemmed from floating point precision errors when working with objects that are located far from the origin point. This is a common issue with various solutions available. The one I utilized can be found at this link:

In essence, rather than moving the camera/player directly, the entire scene is transformed relative to the camera/player's position, which remains fixed at the origin point. With this approach, Orbit Controls always target the origin point.

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

Implement a FOR loop in conjunction with an AJAX request

My goal is to send an AJAX request with multiple form fields and use an array for validations. I would like to also pass these values via AJAX: Although I haven't used a for loop in JavaScript before, it looks familiar. The current approach of the l ...

Bluebird guarantees that no information will be collected

I'm currently in the process of integrating promises into the API for my application. When I try to access the following route, I get a "No data received" error in Postman, even though the commented-out block of code is working perfectly fine. import ...

Tips for leveraging _.union function from lodash to eliminate duplicate elements from several arrays in a TypeScript project

I attempted to use import _ from 'lodash-es' and _.union(user.users.map(user => user.city)). However, the result was not as expected, such as: ["city_id1", "city_id2", "city_id3", "city_id4"] What is th ...

Add an HTML template tag in Vuetify using scripting

This is my current template tag: <template> <h1>Explore in VR</h1> </template> Within my script tag, I've included the following code: var viewer = new AFrame.WebVRViewer(); viewer.setSize(window.innerWidth, window.innerHeig ...

issue with brightcove player's complete event not triggering upon video replay

I have a videoplayer with an event listener added in an onTemplateReady function. Upon completion of the video, I want to replay it: videoPlayer.addEventListener(brightcove.api.events.MediaEvent.COMPLETE, completedCallback); function completedCallback(){ ...

"Troubleshooting the failure of the alert function to work properly when loading content

I am working on a webpage named index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Co ...

Tips for passing a "NULL" value into a nullable field when making a call from JavaScript to an ASP.NET WebService

Is there a way to pass the value of "NULL" into a nullable field when calling an ASP.NET WebService from JavaScript? I am currently calling the method in this manner from JavaScript: ws_data.SaveTasks(eval({"MyValue":"null"}), OnSaveComplete, OnError, On ...

Using async await in node.js allows you to bypass the need for a second await statement when

As I dive into using await async in my Node.js ES6 code... async insertIngot(body, callback) { console.log('*** ItemsRepository.insertIngot'); console.log(body); const data = await this.getItemsTest(); console.log('*** ge ...

Error: Failed to retrieve the name property of an undefined value within the Array.forEach method

Upon pressing the button to display the task pane, I encountered an error message in the console window that reads: "Uncaught (in promise) TypeError: Cannot read property 'name' of undefined". This error persists and I am unable to resolve or com ...

Reverting a concealed segment

Can anyone make sense of my unconventional explanation? I've set up a hidden section as shown below: <section class="intro"> <label> <input type="checkbox"> <span class="menu"> <span class="hamburger"></span&g ...

Chosen option within the AntD Select component

Using the AntD select component, there seems to be an issue where it displays "id" instead of "name" when selecting options. Is there a solution available for this problem? const MyComponent = () => { const data = [ { id: "5c83c2d ...

Utilizing React Hooks and Firebase Firestore onSnapshot: A guide to implementing a firestore listener effectively in a React application

SITUATION Picture a scenario where you have a screen with a database listener established within a useEffect hook. The main goal of this listener is to update a counter on your screen based on changes in the database: (Utilizing the useEffect hook without ...

Searching for a JavaScript tool that offers syntax highlighting capabilities

I have come across some excellent RTE HTML text editors such as jsredaktor, TinyMCE, and FCK Editor, but I am in search of an HTML/JavaScript component that functions similarly to a TEXTAREA with built-in code syntax highlighting. ...

Typescript check for type with Jest

Assume there is an interface defined as follows: export interface CMSData { id: number; url: string; htmlTag: string; importJSComponent: string; componentData: ComponentAttribute[]; } There is a method that returns an array of this obj ...

Node.js schedule randomizer

I'm trying to figure out how to call a function within a random range of time intervals in Node.js. What I need is for the function to run once between 2 and 12 hours, then again at another random interval between 2 and 12 hours, and so on. However, I ...

Counting down in JavaScript until the desired MySQL datetime format is reached

I'm trying to display a countdown of hours and minutes to a date pulled from a MySQL database in the format 2010-09-24 11:30:12. I am not well-versed with dates in JavaScript, so any guidance would be greatly appreciated. Thank you. ...

What are the steps to integrate Webpack into an EJS Reactjs Express MongoDb application?

I have incorporated EJS, Express/NodeJs, and MongoDB into the project, along with ReactJs as an addition. My next step is to introduce Webpack for bundling both EJS and ReactJs files together. Although the end goal is to transition the p ...

Ways to update status in intervals of x seconds

I am trying to update the name of every avatar automatically every X seconds. I found a helpful solution that works well, but currently it is displaying the same name for all avatars from the RandomAcidName array. I believe I need to iterate through this ...

Retrieve the value of an input text within a table data cell using JavaScript

I have set up a table using CGridView, which includes input text fields for user input. The problem I'm facing is that I can retrieve the text from table cells without input fields, but not from those containing input fields. PHP: <?php $this-> ...

Inexperienced JavaScript user looking for help with handling XMLHttpRequest response data

It's been well over a decade since I last dabbled in JavaScript, so here I am again. My goal is to create a dynamic graph that updates in real time using data from either my backend database or my ESP32 micro-controller. While it's easy to genera ...