The rotation of the camera in three.js around the Y Axis appears to be improper

Our project involves developing a VR/Stereoscopic web application using three.js to showcase the camera's viewing angle.

For instance, we have set up a "room" scenario with the camera positioned in the center. The camera's rotation is linked to orbital controls.

# create a camera and place it in the scene
camera = new THREE.PerspectiveCamera(90, 1, 0.1, 2000);
camera.position.set(0, 35, 60);
# Attach Orbital controls
controls = new THREE.OrbitControls(camera, element);
controls.target.set(camera.position.x + 0.1, camera.position.y, camera.position.z);
controls.enableZoom = true;
controls.enablePan = true;
# Attach DeviceOrientationControls
controls = new THREE.DeviceOrientationControls(camera, true);
controls.connect();
controls.update();

During each animationFrame call, we examine the camera's vector:

vector = camera.getWorldDirection();
theta = Math.atan2(vector.x, vector.z);
phi = Math.sqrt((vector.x * vector.x) + (vector.z * vector.z));
pitch = Math.atan2(phi, vector.y);

We anticipate the following measurements in radians:

  • Theta represents the deviation from the original view direction (Z), similar to looking down from the (Y) axis (imagine a clock on the ground beneath the camera).
  • Phi indicates the inclination from the initial view direction (Z) upwards or downwards (think of a clock on the side of the camera).
  • Pitch denotes the rotation around the Z-axis when observing down the original Z vector (visualize a clock on the back of the camera).

However, there appears to be a consistent discrepancy in Theta, while Phi and Pitch appear accurate. We convert radians into degrees by applying a formula such as: pitch * (180/Math.PI)

The environment and camera update and rotate effectively, and moving the phone/VR glasses left or right results in a natural "look around the room" effect.

These measurements involve assessing the rotation over one axis at a time while keeping the other two axes facing the original direction mostly unchanged.

What could we possibly overlook in this process?

Answer №1

After extensive testing, we delved deeper into the matter at hand. Utilizing a CNC rotating table, we meticulously measured angles on various phones and compared our findings with the input provided to the computer-controlled rotating table.

The results were striking: Chrome performed disappointingly, failing to generate accurate or consistent data. It was deemed unreliable and unsuitable for our purposes.

In contrast, Firefox yielded more promising results on the same phones. Although there were minor issues with axis flipping at certain points, potentially attributed to gimbal lock or rotation overflow, it closely mirrored our intended input (deviating by less than 1%) and demonstrated remarkable reliability and repeatability.

Answer №2

If you need to retrieve euler angles, simply use the method camera.getWorldRotation().

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 possible to create a TypeScript generic type that transforms a Record into a type by utilizing the `as const` keyword?

Imagine this scenario: I define const foo = { myKey: 'myValue' } as const Now, when I ask for typeof foo, I get { readonly myKey: 'myValue' } If I have a type MyType = Record<string, string>, and I want to create a modifier (let ...

Filtering objects by their properties or attributes in AngularJS can be achieved by using forEach, but encountering an error stating "forEach is

In my AngularJS application, I have a page that displays multiple widgets. One widget shows a table with details about a monitored system. Currently, the table has two columns: 'Type' and 'Data', displaying information and values respec ...

When the checkbox is ticked, icheck will make a POST request, but it won't

I am currently experimenting with using icheck to handle POST requests for a temporary table. My goal is to add an entry when a box is checked and remove it when unchecked. Currently, when I check the box, it alerts me and successfully stores the informati ...

Tips for transforming a UTF16 document into a UTF8 format using node.js

My dilemma involves an xml file that is encoded in UTF16, and I need to convert it to UTF8 for processing purposes. When I use the following command: iconv -f UTF-16 -t UTF-8 file.xml > converted_file.xml The conversion process goes smoothly with the ...

What is the best way to choose all the checkboxes in a checkbox list, such as a ToDo List?

I am currently working on developing a to-do list where each item includes a checkbox. My goal is to be able to select these checkboxes individually by clicking on them. Furthermore, I would like the checkboxes to toggle between being checked and unchecked ...

Is it possible to dynamically utilize document.getElementById()?

I am attempting to print an HTML page using window.print after each REST API call updates the content. Is it possible to print continuously for each REST API call? var myPrintContent = document.getElementById("data-box"); var myPrintWindow = wind ...

Go to a specific component located in a different module within Angular

I have a default app.component that contains a button. When this button is clicked, I want to navigate to the login.component. Below is a snippet from my app.module.ts file: import { BrowserModule } from '@angular/platform-browser'; ...

Using Node.js to handle reading files and dealing with undefined or null values

The get method is responsible for receiving a userid with an initial total number of points defined in the stcok.json file, along with various transactions stored in another file. Below are some sample entries from the stock JSON: [ { "user" ...

How can I retrieve console log information in POSTMAN when a test fails?

Having an issue with this test. I am trying to trigger a console.log when the installment value in my JSON is less than 100 (resulting in a test FAIL). However, I am receiving both PASS and FAIL results in the test, but no information is showing up in th ...

The .env file is functioning properly for the current keys, but any new ones I include remain undefined

Recently, I took over a Vue application that utilizes axios. Within the dataService.js file, it retrieves URLs from a project's .env file using process.env.FOO_BAR for GET requests. The pre-existing key-value pairs such as VUE_APP_DATA_URL function p ...

Output the word 'Days', 'Months', or 'Years' depending on the value of N, which represents the number of days

I am currently utilizing moment.js in conjunction with vue 3. I've implemented a function that calculates the disparity between two dates. The functionality works as expected, but here's where my query comes in. The function is structured like so ...

Unable to establish a value within the function

I am encountering an issue where I cannot set a value inside a function. When I attempt to alert this value, it returns as undefined. How can I retrieve this value outside of the function? var startingLatitude; L.esri.Geocoding.geocode() .text(document ...

The integration of <form> with jQuery Ajax error

I have come across this HTML form function FormSubmit (){ $.ajax({ url:'dotar.php', type:'post', data:$('form').serialize(), success:function(){ setTi ...

What is the best way to create a straightforward menu for my HTML game?

I have been working on a basic HTML game and it seems to be functioning more or less. I'm wondering if it's possible to create a simple menu with an image in the background and a "click to start" button within the same file. Any suggestions or ti ...

"Tree panel items in ExtJS 4 are displaying correctly in Firefox, but are mysteriously missing from

While working on my Tree Panel project, I encountered an issue with the display of items in different browsers. The items show up correctly in Firefox but appear empty in Chromium. How is this possible? Here's the JSON data sent to the server: {"tex ...

Vue.js: Issue with updating list in parent component when using child component

I'm encountering an issue when utilizing a child component, the list fails to update based on a prop that is passed into it. When there are changes in the comments array data, the list does not reflect those updates if it uses the child component < ...

I am looking to sort users based on their chosen names

I have a task where I need to filter users from a list based on the name selected from another field called Select Name. The data associated with the selected name should display only the users related to that data in a field called username. Currently, wh ...

Manipulating a link within a span element with Puppeteer

I'm currently working on a project where I need to scrape a manga website and save all the pages. The code I have is able to navigate through the page and save the images successfully. However, I'm facing an issue when trying to click on a link ...

Formatting JSON with two fields

I attempted to organize JSON data based on city names using this fiddle code. Now, I am trying to group the data by city name and city code. Any suggestions or hints regarding the logic would be greatly appreciated. CurrentDataFormat = [{ "Id": 1 ...

Uploading an image to the server using JQuery library and FormData

I have reviewed numerous solutions, but I am unable to identify the issue in my code. HTML: <div id='image-uploader-view'> <input type='text' id='rename' name='rename'/> <input id='fileu ...