Limit or deactivate the rotation along the XY axes in Three.js device orientation controls

I'm currently utilizing DeviceOrientationControls to connect to and rotate an item in Three.js.

Typically, these controls will allow rotation on all three XYZ axes.

Is there a method available to deactivate rotation on the X and Y axes so that the object only rotates on the Z axis?

Hopefully, this explanation is sufficient. Please inform me if you require an example. Thank you.

Answer №1

If you're looking for an alternative approach, I was able to achieve the desired functionality without relying on the Three DeviceOrientationControls library.

All you need to do is attach an event listener for 'deviceorientation' and utilize the gamma rotation data to update the object's rotation dynamically. Here's a snippet of the code:

window.addEventListener('deviceorientation', function(e) {
  var gammaRotation = e.gamma ? e.gamma * (Math.PI / 180) : 0;
  bottleGroup.rotation.y = gammaRotation;
});

Answer №2

To achieve camera motion only in the y direction when using DeviceOrientationControls js, you can make a simple modification in the code. All you need to do is add the following lines of code after setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient ); within the update function:

this.object.rotation.x = 0;
this.object.rotation.z = 0;

By doing this, your camera will move exclusively along the y-axis.

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

The jQuery .animate function seems to be malfunctioning

I recently came across this jsfiddle link: http://jsfiddle.net/2mRMr/3/ However, the code provided is not functioning as expected: setInterval(function () { box.animate({ left: function (i, v) { return newv(v, 37, 39); }, ...

Combining and sorting cursor data from multiple collections based on date

Can you combine two or more different collections and arrange them by createdAt? For example, suppose we have data like this: CollectionA.insert({ createdAt: new Date(), field1: value1, field2: value3, field3: value2, ...

mongoose.js now prevents update methods from returning documents

Is it feasible to avoid fetching any data from the database after performing the SOME_MODEL.findOneAndUpdate() operation? I could potentially utilize the lean() and select() methods. However, all I really require is a callback confirming the successful up ...

What is the best way to connect a string to a scoped variable in a view?

I'm looking to connect a string to a scope variable that will be determined by user input in an input field located within a specific view. The goal is for the combined string and scope variable value to appear in another div within the view. Here&ap ...

Determine the total cost based on the quantity purchased

I created a webpage for employees to select an item from a dropdown menu, and it will automatically display the price of that item. Check out my code below: <script> $(document).ready(function() { $('#price_input').on('change' ...

Is there a way to execute a javascript function that is located outside of my Angular application without having to import it?

I need to be able to trigger a JavaScript function that is located outside of my Angular app when a button is clicked. Unfortunately, it seems that importing the JavaScript directly into my Angular app isn't feasible for this task. The platform I am ...

Print the content from the selected tab in AngularJS UI tab

In my AngularJS application, I have implemented nested tabs and encountered an issue. I am trying to enable users to print the selected content list from both parent and child tabs. Is there a way to achieve this so that when a user clicks on "print list ...

Is there a neat method in React and Material UI for de-structuring the props that I am passing to useStyles?

When passing props to useStyles based on the Material docs, our code looks like this: const useStyles = makeStyles({ // style rule foo: props => ({ backgroundColor: props.backgroundColor, }), bar: { // CSS property color: props => ...

The LinkedIn API encountered an error when attempting to retrieve historical follower data, resulting in a HTTP

I've scoured the depths of the internet in search of a solution to my problem, but none seem to fit what I need. My goal is to retrieve historical follower data from LinkedIn's API using this call: ${companyId}/historical-follow-statistics?time- ...

Next.js Refresh Screen

Is there a way to refresh my client's web page from the server at a specific time? I need the client's page to be refreshed at 12pm, and although I'm using a scheduler, it doesn't seem to be automatically refreshing the web page on the ...

Struggling to retrieve information from a template and transfer it to a controller in AngularJS

Currently, I am encountering issues with user authentication in my template. Oddly enough, everything works fine when testing with Postman. Firstly, I initiate an API call to /users/authenticate to retrieve a token. Next, I verify the token by making anoth ...

C# GridView using a modal popup

Currently, I am working on incorporating a lightbox into a gridview. The lightbox I have chosen to use can be found here on Particle Tree's website Essentially, in order to make the lightbox function correctly, you need to include a css and rel attr ...

"What is the best way to retrieve the value of an HTML input in

I am looking to store a variable that can be retrieved from JavaScript and then utilized in PHP upon form submission. For this purpose, I have added an input field in the HTML code: HTML <input type="hidden" name="videoname_var" id="videoname_var" me ...

Populate a bootstrap-select dropdown menu with an array of choices

After creating a table using datatables and adding an empty dropdown select on the footer with Bootstrap-select, here is the code snippet: <tfoot> <tr> <th><select class="selectpicker" multiple></select>< ...

Utilizing ReactJS alongside either jQuery or vanilla JavaScript

As a newcomer to ReactJS, I find myself struggling with using it for more complex tasks. While I grasp the fundamentals, my mind often defaults to jQuery or plain JavaScript when attempting more advanced projects. For example, if I were to create a web a ...

Why does the response.json() method in the Fetch API return a JavaScript object instead of a JSON string?

After using Body.json() to read the response stream and parse it as JSON, I expected to receive a JSON string when I logged the jsonData. Instead, I received a Javascript object. Shouldn't jsonData return a JSON string until we call JSON.parse() to co ...

Creating an aperture in a form using a different shape in THREE.js

Currently, I am utilizing the D3-threeD2.js library to convert SVG files into THREE.Shape(s) that can be extruded with three.js. The process works smoothly, however, when it comes to incorporating holes, I encounter an issue. Imagine a shape resembling a ...

Is there a method available to minimize the size of a local storage list containing strings?

Hey there, I am trying to load a large 2.5MB json file in my browser so that I can use it for some typeAhead functions. Unfortunately, I'm facing an issue with my local storage being constantly full. When using Firefox, I receive the following error ...

How can I insert a variable into the URL for fetching data in React?

Here's a fetch request I have: fetch(`https://example/e1/e11/${variable1}?param=A1&include=metadata`, { "method": "GET"... Is there an issue with declaring the variable1 in this manner? It seems to work fine when written lik ...

Is there a way to show the value of a variable in several locations within my HTML <p> element?

Why is my variable value (test) only displaying in one instance in my HTML <p> tag? After correctly showing in the first place, it appears blank in the second. What mistake am I making? var name = document.querySelector("#NameInput").value; fu ...