Issues with rotation of Earth and camera in Three.js

Have you seen the website ? I find it really interesting!

I'm curious about how to click on a marker on the map and have it centered on the screen. Once I know the latitude and longitude of the marker, what steps should I take after clicking on it? I'm a bit confused.

Answer №1

After experimenting with Matrix to determine the correct orientation, I found that the results were a bit peculiar. Switching to a spherical coordinates system proved to be a more effective approach.

To begin, we must obtain the coordinates of two points on the sphere: one being the point on the sphere surface closest to the camera (denoted as P), and the other being the point where we clicked on the sphere surface (denoted as Q).

We utilized raycaster to acquire the Cartesian Coordinates of points P and Q, which were then converted to Spherical Coordinates denoted as (r,θ,φ).

Next, we calculated the angular displacement from point Q to point P and incorporated this displacement into the sphere's rotation.

The following code snippet demonstrates this process:

// Code snippet omitted for brevity

At the conclusion, an animation library was leveraged to ensure a smooth rotation.

To address previous issues related to incorrect rotations when tilting the earth up and down, adjustments were made in the OnDocumentClick function. By incorporating Sphere matrix calculations and conversion of world space axises to object space coordinates, we achieved the desired rotation outcome.

The modified function is outlined below:

// Code snippet for updated function omitted for brevity

An updated demonstration showcasing these enhancements can be viewed here: rotate earth new version.

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

Retrieve JSON or JavaScript property with a string reference

Consider the following JSON array: _htaItems = [ {"ID":1, "parentColumnSortID":"0", "description":"Precondition", "columnSortID":"1", "itemType":0}, {"ID":2, "parentColumnSortID":"0", "description":"Precondition", ...

Attention: Issue with 'className did not match' error in react-material-ui-carousel

I am currently utilizing React, NextJS, and Material UI in my project I recently integrated the react-material-ui-carousel package, but encountered the following error: Warning: Prop className did not match. Server: "MuiButtonBase-root MuiIconButton ...

Return the outcome of an Axios POST request

Upon integrating JWT verifyToken into my non-JWT api call, my Axios POST request now returns an empty result set. Function 2 (/userget) is functioning correctly and displays results on HTML, whereas Function 7 (/api/userget) can retrieve data and token but ...

What is the best way to leverage multiple random YouTube v3 API keys simultaneously?

I have the following code snippet and I am looking to randomly select an API key from a list of keys: function search() { // Clear Results $('#results').html(''); $('#buttons').html(''); // Get Form Input ...

Can we send a dynamic form using AJAX?

I am seeking a method to submit a page filled with quantities to another page and then retrieve their values. Here is my setup: <input type="number" name="item1" /> <input type="number" name="item2" /> <input type="number" name="item3" /> ...

Stop the page from refreshing when the Struts button is clicked - Here's how!

I've included the code below: <s:submit type="input" value="clickme" onclick="func()"/> Inside the func() function, there's an alert("hereee") command. When I click the button, it displays "hereee" in an alert window but also refreshes th ...

The Node.js POST request is unexpectedly returning 'undefined'

I'm currently working on a project for an online course and I'm encountering an issue with making an API call. It seems that I am getting undefined responses to my post request because the user input is not being retrieved properly. Below are the ...

Create a pop-up window within a single controller using Angular.js

I followed a tutorial to create this code. I am interested in learning how to utilize just one controller for generating the dialog box. Currently, I am using two controllers for this project. Any guidance or tips would be greatly appreciated. View my cod ...

Retrieve the JSON file only upon the first input change

On my backend, I have a JSON file containing suggested words for autocomplete in the search field. To improve performance, I don't want the JSON to load every time the page loads; instead, I only want it to load when someone wants to use the search f ...

Error with replacing regular expressions in IE11 for the variable $0

Having both a string and a message: str = "Test $0 $1 $2"; message = "Hi %2 Hello %2" ; The goal is to replace all occurrences of %2 with str in the message using RegExp, like so: message = message.replace(new RegExp("%2" , "g"), str); While this works ...

Using the CSS to set the alt attribute and title of an image based on its file name

Is it feasible to dynamically set the ALT and title attributes of an image element to match the file name? It seems like this could potentially be achieved using the CSS content property, although I am not very familiar with the process. For example: < ...

Difficulties arise when debugging asynchronous functions

Having trouble testing asynchronous code lately. Here's the function I'm dealing with: export default base64String => new Promise((resolve, reject) => { const image = new Image(); image.onload = () => { const dimension ...

MongoDB was successfully updated, however the changes are not being displayed on the redirected

I have implemented the delete action in Node/Express as a web framework, where it is structured within a higher-level route: .delete((req, res) => { db.collection('collection-name').findOneAndDelete({ topic_title: req.body.topic_title}, ...

Negative vibes with for/in loop

My script is short and simple: hideElements = arguments.shift().split(','); for (iterator in hideElements) { console.log('--> hiding ' + hideElements[iterator]); lg_transitions({kind:"slide-up"}, {target: hideElements[iterat ...

foreverjs neglects to log the child process's console.log output to any log files

I currently have a nodejs server running that fetches data using the setInterval function every x seconds. Here is a snippet of that part of the app: startPolling () { debug('Snmp poller started'); timers.setInterval( this.poll( ...

Tips for triggering a sound with a click?

I've encountered an issue with a JavaScript app I created. I want a sound to play when I click on something, and if I click again, the sound should restart. However, due to the delay in playing the sound, multiple clicks don't start the sound ane ...

Access the current page's URL using JavaScript

I have a unique URL structure that looks like this: index.html#page:page.php As I am loading my pages dynamically using AJAX, I want to create hotlinks to load specific pages. Currently, I am using the following function: function getdata(file){ $ ...

What is the best way to disable list items in a UI?

Check out my assortment: <ul class="documents"> <li class="list_title"><div class="Srequired">NEW</div></li> <li class="doc_price>1</li> <li class="doc_price>2</li> <li c ...

Tips for ensuring the Google+ JavaScript tag is W3C compliant

I have a Google+ button on my website that is functioning properly. However, when I run it through the W3C validator, an error is detected: The text content of the script element does not meet the required format: It was expecting a space, tab, newlin ...

Variations in AmbientLight Screen Presentations

While working on illuminating the model using AmbientLight in three.js, I noticed a difference in color rendering between the test environment and production environment, despite using the same light source. Despite my efforts to troubleshoot the issue, I ...