What is the best way to align an object's rotation with a Vive controller's rotation when the trigger is pulled in A-Frame?

Exploring the possibilities of creating A-Frame applications, I decided to dive into the world of A-Frame Dominoes. In my current project, objects are spawned in response to the Vive trigger being pressed.

While I have successfully managed to align the position of the newly created object with that of the Vive controller at trigger activation, I am facing challenges when it comes to matching the rotation of the new object with that of the controller.

I have attempted the following approach:

onTriggerDown: function () {
  var sceneEl = d3.select(this.el.sceneEl);
  var controllerWorldPosition = this.el.object3D.getWorldPosition();
  var controllerWorldRotation = this.el.object3D.getWorldRotation();

  sceneEl.append('a-obj-model')
         .attr('id', 'base-street-children')
         .attr('scale', '0.01 0.01 0.01')
         .attr('position', controllerWorldPosition)
         .attr('rotation', controllerWorldRotation)
         .attr('src', '#base-street-obj')
         .attr('mtl', '#base-street-mtl');
},

I am wondering if there is a specific method or technique in JavaScript for setting the rotation of a new object that I might be overlooking?

Answer №1

In the world of Three.js, rotation is measured in radians, but in A-Frame, rotation is measured in degrees. When extracting rotation data from a Three.js Object3D, it's important to remember this distinction and convert the values accordingly before applying them to an A-Frame entity.

Here is one way this conversion can be implemented in your specific case:

.attr('rotation', function() {
  var controllerWorldRotationX = controllerWorldRotation._x / (Math.PI / 180);
  var controllerWorldRotationY = controllerWorldRotation._y / (Math.PI / 180);
  var controllerWorldRotationZ = controllerWorldRotation._z / (Math.PI / 180);

  return controllerWorldRotationX + ' ' + controllerWorldRotationY + ' ' + controllerWorldRotationZ;
})

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

developing a custom modal using a button in a React project with Material UI

Hello everyone, I have a question regarding React. I am fairly new to React and need some assistance with adding a new function that creates a Modal. I want to call this function onClick when the add icon is pressed (line 43). Any help would be appreciated ...

When the page loads, a JavaScript function is triggered

My switchDiv function in Javascript is being unexpectedly called when the page loads. It goes through each case in the switch statement, except for the default case. Does anyone know how to solve this issue? $(document).ready(function() { $("#be-button" ...

Verify if the date surpasses the current date and time of 17:30

Given a date and time parameters, I am interested in determining whether that date/time is greater than the current date at 17:30. I am hoping to achieve this using moment js. Do you think it's possible? This is what I have been attempting: let ref ...

Exploring the world of shapes and angles in three.js

I'm attempting to recreate a scene similar to this one, where the shapes have an outline: Unfortunately, neither of these two options are working: const material = new THREE.MeshNormalMaterial(); const material = new THREE.MeshBasicMaterial({ color: ...

Different types of outputs that are suitable for a callback

I am currently developing a small node.js project focused on retrieving search terms from a Twitter feed. Although the search functionality is in place, I am facing difficulties in displaying this data on my webpage. The information I wish to showcase is s ...

Strategies for managing repeated executions of UseEffect caused by fetching data from Firestore database

edit: made significant changes to the content of this question I am currently in the process of developing a booking application. I have noticed a considerable amount of rerenders occurring and, following the advice of @jpmarks, I have been attempting to ...

Vue.js is limited in its ability to efficiently partition code into easily loadable modules

My current issue: I am facing a challenge with splitting my vue.js code into chunks. Despite trying multiple examples from tutorials, I am unable to successfully separate the components and load them only when necessary. Whenever I attempt to divide the c ...

Callback Method Ajaxify

Just started using Ajaxify and so far it's been a great experience. However, I'm wondering if there is a callback function available that doesn't require any specific inputs in the script. I've searched around but haven't found wh ...

When trying to invoke an Angular function from a JavaScript function, it is returning as undefined

When attempting to invoke an Angular function from a JavaScript function, I am encountering an issue where it is displaying as undefined. Below is an example demonstration I have created: import { Component, NgZone, OnInit } from '@angular/core&apo ...

What are the key distinctions between Cordova and PhoneGap?

After reviewing multiple documents, it appears that Cordova is often described as a power booster for PhoneGap. However, I am interested in understanding the differences between the two during implementation. When creating a project using Cordova via the ...

The problem with the pathLength property is causing my path animation to malfunction

I'm struggling to animate SVG graphics and haven't been able to find much information on this topic online. Recently, I attempted to animate an SVG using framer-motion in a React component. The animation configuration I used is as follows: const ...

What strategies can I employ to speed up the slow build times in next.js?

Having thoroughly explored the Next JS documentation and delved into related inquiries like Slow page build time in development with Next.js and TypeScript (although that pertains to TypeScript specifically - this concern revolves around JavaScript without ...

Using JQuery, identify cells located in the first column of a table excluding those in the header section

In the past, I had code that looked like this: $(elem).parents('li').find(...) I used this code when elem was an item in a list, making it easy to reference all items in the list. But now, I've made some changes and decided to use a table ...

Creating a hover effect for a specific card while maintaining the rest of the cards unaffected

When hovering over a card, all icons are displayed instead of just the icons for that specific card. I want to show only the icons for the card being hovered on (example output: image). The cards are generated automatically using v-for and fetching data fr ...

What is the best way to ensure the parent element adjusts to fit its floated children, without exceeding the width of the window?

I am attempting to center a group of floating elements, but due to them being displayed in masonry style, I cannot set them as inline. It is clear that a container is necessary, but I have been unable to find information on how to achieve this: Please dis ...

The Dropzone feature fails to function properly when displayed on a modal window that is being shown via

After attempting to integrate Dropzone and JavaScript into a Bootstrap Modal called through AJAX, I encountered issues. Due to the high number of records, I avoided placing the Modal in a foreach loop and instead used AJAX to call a controller method upon ...

React Redux in conjunction with redux persist ensures that only a portion of the data remains stored persistently

This app is built using React Native with the Redux pattern and redux-persist to store data for offline use. However, only some of the data is persisting correctly. For example, the `auth` data is persisting and loading from `AsyncStorage` without any issu ...

The plugin needed for the 'autoprefixer' task could not be located

Starting out in the world of Angular 2 development can be overwhelming, especially when trying to integrate with the Play framework on the back-end side. I recently came across a helpful post by Denis Sinyakov that walks through setting up this integratio ...

Encountering issues while attempting to pass a function into axios.then and catch and receiving errors

axios.post('http://localhost:3000/api/v1/login', { email: this.state.email, password: this.state.password }, { headers: { "Access-Control-Allow-Origin": "*", ...

Creating a cascade of falling balls with a single click: Here's how!

I'm currently working on a project where I have a ball dropping from the cursor location and redropping when the cursor moves to another position. However, I want to be able to create a new ball every time I click the mouse. I attempted the following ...