How to use the three.Quaternion function in three

To help you get started, we’ve selected a few three examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pchen66 / panolens.js / src / lib / controls / DeviceOrientationControls.js View on Github external
var setCameraQuaternion = function( quaternion, alpha, beta, gamma, orient ) {

        var zee = new THREE.Vector3( 0, 0, 1 );

        var euler = new THREE.Euler();

        var q0 = new THREE.Quaternion();

        var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis

        var vectorFingerY;
        var fingerQY = new THREE.Quaternion();
        var fingerQX = new THREE.Quaternion();

        if ( scope.screenOrientation == 0 ) {

            vectorFingerY = new THREE.Vector3( 1, 0, 0 );
            fingerQY.setFromAxisAngle( vectorFingerY, -rotX );

        } else if ( scope.screenOrientation == 180 ) {

            vectorFingerY = new THREE.Vector3( 1, 0, 0 );
            fingerQY.setFromAxisAngle( vectorFingerY, rotX );

        } else if ( scope.screenOrientation == 90 ) {

            vectorFingerY = new THREE.Vector3( 0, 1, 0 );
            fingerQY.setFromAxisAngle( vectorFingerY, rotX );
github cjdell / web-blocks / lib / StereoEffect.js View on Github external
THREE.StereoEffect = function ( renderer ) {

	// API

	this.separation = 2;

	// internals

	var _width, _height;

	var _position = new THREE.Vector3();
	var _quaternion = new THREE.Quaternion();
	var _scale = new THREE.Vector3();

	var _cameraL = new THREE.PerspectiveCamera();
	var _cameraR = new THREE.PerspectiveCamera();

	// initialization

	renderer.autoClear = false;

	this.setSize = function ( width, height ) {

		_width = width / 2;
		_height = height;

		renderer.setSize( width, height );
github iTowns / itowns / src / Utils / OrientationUtils.js View on Github external
function quaternionIdentity(coordinates, target = new THREE.Quaternion()) {
    return coordinates ? target.set(0, 0, 0, 1) : quaternionIdentity;
}
github wonderunit / storyboarder / src / js / express-xr / src / SceneManagerXR.js View on Github external
return !oldValue
            })
          } else if (button === 'hand') {
            setFlipHand(oldValue => {
              return !oldValue
            })
          } else if (button === 'help') {
            setHelpToggle(oldValue => {
              return !oldValue
            })
          } else if (button === 'camera') {
            setAddMode('gui_camera')

            const guiCam = scene.getObjectByName('guiCam')
            const pos = guiCam.getWorldPosition(new THREE.Vector3())
            const rot = guiCam.getWorldQuaternion(new THREE.Quaternion())
            const euler = new THREE.Euler().setFromQuaternion(rot, 'YXZ')

            const id = THREE.Math.generateUUID()
            createObject({
              id,
              type: 'camera',
              fov: guiCamFOV,
              x: pos.x,
              y: pos.z,
              z: pos.y,
              rotation: euler.y,
              roll: euler.z,
              tilt: euler.x
            })

            setTimeout(() => {
github facebook / react-360 / React360 / js / Compositor / Environment / Environment.js View on Github external
_setRotateTransform(rotateTransform?: Array) {
    const quat = new THREE.Quaternion();
    if (rotateTransform) {
      const mat = new THREE.Matrix4();
      mat.set.apply(mat, rotateTransform);
      const pos = new THREE.Vector3();
      const scale = new THREE.Vector3();
      mat.decompose(pos, quat, scale);
    }
    this._panoMeshQuat = quat;
    this._applyPanoRotation();
    this._panoMesh.needsUpdate = true;
  }
github MageStudio / Mage / src / controls / Transform.js View on Github external
this._cameraPosition = new Vector3();
        this.setAndDispatch('cameraPosition', new Vector3());

    	this._cameraQuaternion = new Quaternion();
        this.setAndDispatch('cameraQuaternion', new Quaternion());

    	this.cameraScale = new Vector3();

    	this.parentPosition = new Vector3();
    	this._parentQuaternion = new Quaternion();
    	this.parentScale = new Vector3();

    	this._worldPositionStart = new Vector3();
        this.setAndDispatch('worldPositionStart', new Vector3());

    	this._worldQuaternionStart = new Quaternion();
        this.setAndDispatch('worldQuaternionStart', new Quaternion());

    	this.worldScaleStart = new Vector3();

    	this._worldPosition = new Vector3();
        this.setAndDispatch('worldPosition', new Vector3());

    	this._worldQuaternion = new Quaternion();
        this.setAndDispatch('worldQuaternion', new Quaternion());

    	this.worldScale = new Vector3();

    	this._eye = new Vector3();
        this.setAndDispatch('eye', new Vector3());

    	this._positionStart = new Vector3();
github capnmidnight / Primrose / src / Primrose / Input / PoseInputProcessor.js View on Github external
/*
pliny.class({
  parent: "Primrose.Input",
  name: "PoseInputProcessor",
  baseClass: "Primrose.Input.InputProcessor",
  description: "| [under construction]"
});
*/

const DEFAULT_POSE = {
    position: [0, 0, 0],
    orientation: [0, 0, 0, 1]
  },
  EMPTY_SCALE = new Vector3(),
  IE_CORRECTION = new Quaternion(1, 0, 0, 0);

import { Vector3, Quaternion, Matrix4 } from "three";

import { isMobile, isIE } from "../../flags";

import InputProcessor from "./InputProcessor";

export default class PoseInputProcessor extends InputProcessor {
  constructor(name, commands, axisNames) {
    super(name, commands, axisNames);

    this.currentDevice = null;
    this.lastPose = null;
    this.currentPose = null;
    this.posePosition = new Vector3();
    this.poseQuaternion = new Quaternion();
github kinetecharts / openPerform / src / libs / trail.js View on Github external
THREE.TrailRenderer.prototype.updateNodePositionsFromTransformMatrix = function() {

    var tempMatrix4 = new THREE.Matrix4();
    var tempMatrix3 = new THREE.Matrix3();
    var tempQuaternion = new THREE.Quaternion();
    var tempPosition = new THREE.Vector3();
    var tempOffset = new THREE.Vector3();
    var worldOrientation = new THREE.Vector3();
    var tempDirection = new THREE.Vector3();

    var tempLocalHeadGeometry = [];
    for ( var i = 0; i < THREE.TrailRenderer.MaxHeadVertices; i ++ ) {

        var vertex = new THREE.Vector3();
        tempLocalHeadGeometry.push( vertex );

    }

    function getMatrix3FromMatrix4( matrix3, matrix4) {

        var e = matrix4.elements;
github povdocs / webvr-starter-kit / src / vr-object.js View on Github external
VRObject.repeat = function (count, options) {
		var i,
			change = false,
			lastObject = this,
			currentPosition = new THREE.Vector3(),
			deltaPosition = new THREE.Vector3(),
			currentQuaternion = new THREE.Quaternion(),
			deltaQuaternion = new THREE.Quaternion();

		if (!options) {
			return;
		}

		if (options.offset) {}

		for (i = 0; i < count; i++) {

		}
	};
github mozilla / Spoke / src / editor / controls / TransformControls.js View on Github external
this.pointStart = new Vector3();
    this.pointEnd = new Vector3();
    this.rotationAxis = new Vector3();
    this.rotationAngle = 0;

    this.cameraPosition = new Vector3();
    this.cameraQuaternion = new Quaternion();
    this.cameraScale = new Vector3();

    this.parentPosition = new Vector3();
    this.parentQuaternion = new Quaternion();
    this.parentScale = new Vector3();

    this.worldPositionStart = new Vector3();
    this.worldQuaternionStart = new Quaternion();
    this.worldScaleStart = new Vector3();

    this.worldPosition = new Vector3();
    this.worldQuaternion = new Quaternion();
    this.worldScale = new Vector3();

    this.eye = new Vector3();

    this.positionStart = new Vector3();
    this.quaternionStart = new Quaternion();
    this.rotationStart = new Euler();
    this.scaleStart = new Vector3();

    this.gizmo = new TransformControlsGizmo(this);
    this.add(this.gizmo);