supermedium / superframe

:package: A super collection of A-Frame components.
https://supermedium.com/superframe/
MIT License
1.37k stars 423 forks source link

rotateTo #191

Open Perhelion opened 5 years ago

Perhelion commented 5 years ago

Could this function be added from the old https://github.com/tizzle/aframe-orbit-controls-component/ !?

Strae commented 5 years ago

Up! That would be great. I've been able to simulate the "look-at" swapping the orbit-controls.target value:

AFRAME.registerComponent( 'mytest-click', {
  schema: {
    active: { type: "boolean" }
  },
  init: function () {
    var data = this.data;
    var el = this.el;
    el.addEventListener( 'click', function ( evt ) {
      // Calculate real position
      var targetPosition = new THREE.Vector3();
      targetPosition.setFromMatrixPosition( evt.target.object3D.matrixWorld );
      var cameraPosition = document.querySelector( '#camera' ).getAttribute( 'position' );

      // camera height offset
      targetPosition.y -= cameraPosition.y;

      var currOrbit = document.querySelector( '#camera' ).getAttribute( 'orbit-controls' );
      currOrbit.target = targetPosition;

      document.querySelector( '#camera' ).setAttribute( 'orbit-controls', currOrbit );
    } );
  }
});

..I only need to understand how to animate the thing and to "move" the camera to another position

yyvus commented 5 years ago

Hi,

Here is a patch in which I have the rotateTo functionality available for three views: front, side and top. This can be changed by managing the azimuth and polar angles as desired in the rotateTo function. rotateTo.patch.txt