コード例 #1
1
 accelToQuaternion_(accel) {
   var normAccel = new Vector3();
   normAccel.copy(accel);
   normAccel.normalize();
   var quat = new Quaternion();
   quat.setFromUnitVectors(new Vector3(0, 0, -1), normAccel);
   quat.inverse();
   return quat;
 }
コード例 #2
0
ファイル: Mantle.js プロジェクト: goldbuick/src
            RenderObject.animate(mantleGems, (mantleGem, anim, index) => {
                tween.primary(anim, 'scale', tween.CONST.smallScale, 1);
                tween.setScale(anim, mantleGem);

                if (tween.secondary(anim, 'toQuatRatio', 0, 1)) {
                    const eachRow = Mantle.EACH_ROW;
                    const tiltAmount = Mantle.TILT_AMOUNT;

                    const offset = index % eachRow;
                    const ratio = offset / eachRow;
                    const row = Math.floor(index / eachRow);
                    const singleRow = mantleGems.length <= eachRow;
                    const angleStep = (Math.PI * 2) / eachRow;

                    const tiltAngle = singleRow ? 0 : (row ? -tiltAmount : tiltAmount);
                    const tilt = new THREE.Quaternion();
                    tilt.setFromEuler(new THREE.Euler(tiltAngle, 0, 0, 'XYZ'));

                    const spinAngle = ratio * Math.PI * 2 + (singleRow ? 0 : row ? 0 : angleStep * 0.5);
                    const spin = new THREE.Quaternion();
                    spin.setFromEuler(new THREE.Euler(0, spinAngle, 0, 'XYZ'));

                    anim.toQuat = new THREE.Quaternion();
                    anim.toQuat.multiplyQuaternions(spin, tilt);

                    const forward = new THREE.Vector3(0, 0, 1);
                    const from = new THREE.Vector3(0, 0, 0);
                    anim.fromQuat = new THREE.Quaternion(); 
                    anim.fromQuat.setFromUnitVectors(forward, from);
                }

                mantleGem.quaternion.copy(anim.fromQuat);
                mantleGem.quaternion.slerp(anim.toQuat, anim.toQuatRatio);
            });            
コード例 #3
0
ファイル: trackball_controls.js プロジェクト: mralex/minicity
		return function () {

			var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() );

			if ( angle ) {

				axis.crossVectors( _rotateStart, _rotateEnd ).normalize();

				angle *= _this.rotateSpeed;

				quaternion.setFromAxisAngle( axis, -angle );

				_eye.applyQuaternion( quaternion );
				_this.object.up.applyQuaternion( quaternion );

				_rotateEnd.applyQuaternion( quaternion );

				if ( _this.staticMoving ) {

					_rotateStart.copy( _rotateEnd );

				} else {

					quaternion.setFromAxisAngle( axis, angle * ( _this.dynamicDampingFactor - 1.0 ) );
					_rotateStart.applyQuaternion( quaternion );

				}

			}
		}
コード例 #4
0
	var createQuaternion = function () {

		var finalQuaternion = new THREE.Quaternion();

		var deviceEuler = new THREE.Euler();

		var screenTransform = new THREE.Quaternion();

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

		var minusHalfAngle = 0;

		return function (alpha, beta, gamma, screenOrientation) {

			deviceEuler.set(beta, alpha,  - gamma, 'YXZ');

			finalQuaternion.setFromEuler(deviceEuler);

			minusHalfAngle =  - screenOrientation / 2;

			screenTransform.set(0, Math.sin(minusHalfAngle), 0, Math.cos(minusHalfAngle));

			finalQuaternion.multiply(screenTransform);

			finalQuaternion.multiply(worldTransform);

			return finalQuaternion;

		}

	}
コード例 #5
0
ファイル: VRCursor.js プロジェクト: nishioka/vr-globe
 function updatePositionInFOV(headQuat) {
     var headQuat = self.headQuat();
     var headQuatInv = new THREE.Quaternion().copy(headQuat).inverse();
     var cursorPivot = self.cursorPivot;
     var pivotQuat = new THREE.Quaternion();
     var mouseQuat = self.mouseQuat();
     if (self.cameraCursorAngle >= (Math.PI / 5)) {
         self.lockQuat = self.lockQuat || self.validCameraCursorQuat;
         // cameraCursorEuler =  new THREE.Euler().setFromQuaternion(self.lockQuat);
         // console.log("CAMERA CURSOR " + self.cameraCursorAngle);
         // console.log("ANGLE " + JSON.stringify(cameraCursorEuler.x));
         // console.log("MOUSE " + JSON.stringify(self.rotation.x));
         // self.rotation.x = cameraCursorEuler.x;
         // self.rotation.y = cameraCursorEuler.y;
         pivotQuat.multiply(headQuat).normalize().multiply(self.lockQuat);
     } else {
         self.lockQuat = undefined;
         pivotQuat.multiply(headQuat).multiply(mouseQuat).multiply(headQuatInv);
     }
     if (self.quaternionsAngle(headQuat, pivotQuat) >= (Math.PI / 5)) {
       pivotQuat.multiply(self.mouseQuat.inverse());
     }
     cursorPivot.quaternion.copy(pivotQuat);
     self.validCameraCursorQuat = cameraCursorQuat(cursorPivot.quaternion || new THREE.Quaternion());
     self.cameraCursorAngle = quaternionsAngle(headQuat, cursorPivot.quaternion);
 }
コード例 #6
0
ファイル: PosePredictor.js プロジェクト: rlugojr/Primrose
  getPrediction(currentQ, gyro, timestampS, outQ) {
    if (!this.previousTimestampS) {
      this.previousQ.copy(currentQ);
      this.previousTimestampS = timestampS;
      return currentQ;
    }

    // Calculate axis and angle based on gyroscope rotation rate data.
    AXIS.copy(gyro);
    AXIS.normalize();

    var angularSpeed = gyro.length();

    // If we're rotating slowly, don't do prediction.
    if (angularSpeed < DEG2RAD * 20) {
      outQ.copy(currentQ);
      this.previousQ.copy(currentQ);
      return;
    }

    // Get the predicted angle based on the time delta and latency.
    var deltaT = timestampS - this.previousTimestampS;
    var predictAngle = angularSpeed * this.predictionTimeS;

    this.deltaQ.setFromAxisAngle(AXIS, predictAngle);
    outQ.copy(this.previousQ);
    outQ.multiply(this.deltaQ);

    this.previousQ.copy(currentQ);
    this.previousTimestampS = timestampS;
  }
コード例 #7
0
  update(dt) {
    super.update(dt);

    if (this.currentDevice) {
      var pose = this.currentPose || this.lastPose || DEFAULT_POSE;
      this.lastPose = pose;
      this.inPhysicalUse = this.hasOrientation || this.inPhysicalUse;
      var orient = this.currentPose && this.currentPose.orientation,
        pos = this.currentPose && this.currentPose.position;
      if (orient) {
        this.poseQuaternion.fromArray(orient);
        if(isMobile && isIE){
          this.poseQuaternion.multiply(IE_CORRECTION);
        }
      }
      else {
        this.poseQuaternion.set(0, 0, 0, 1);
      }
      if (pos) {
        this.posePosition.fromArray(pos);
      }
      else {
        this.posePosition.set(0, 0, 0);
      }
    }
  }
コード例 #8
0
		this.update = function ( rotation, eye2 ) {

			THREE.TransformGizmo.prototype.update.apply( this, arguments );

			var group = {

				handles: this[ "handles" ],
				pickers: this[ "pickers" ],

			};

			var tempMatrix = new THREE.Matrix4();
			var worldRotation = new THREE.Euler( 0, 0, 1 );
			var tempQuaternion = new THREE.Quaternion();
			var unitX = new THREE.Vector3( 1, 0, 0 );
			var unitY = new THREE.Vector3( 0, 1, 0 );
			var unitZ = new THREE.Vector3( 0, 0, 1 );
			var quaternionX = new THREE.Quaternion();
			var quaternionY = new THREE.Quaternion();
			var quaternionZ = new THREE.Quaternion();
			var eye = eye2.clone();

			worldRotation.copy( this.planes[ "XY" ].rotation );
			tempQuaternion.setFromEuler( worldRotation );

			tempMatrix.makeRotationFromQuaternion( tempQuaternion ).getInverse( tempMatrix );
			eye.applyMatrix4( tempMatrix );

			this.traverse( function( child ) {

				tempQuaternion.setFromEuler( worldRotation );

				if ( child.name === "X" ) {

					quaternionX.setFromAxisAngle( unitX, Math.atan2( - eye.y, eye.z ) );
					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
					child.quaternion.copy( tempQuaternion );

				}

				if ( child.name === "Y" ) {

					quaternionY.setFromAxisAngle( unitY, Math.atan2( eye.x, eye.z ) );
					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
					child.quaternion.copy( tempQuaternion );

				}

				if ( child.name === "Z" ) {

					quaternionZ.setFromAxisAngle( unitZ, Math.atan2( eye.y, eye.x ) );
					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
					child.quaternion.copy( tempQuaternion );

				}

			} );

		};
コード例 #9
0
ファイル: VRCursor.js プロジェクト: nishioka/vr-globe
 function updatePositionCentered(headQuat) {
     var headQuat = self.headQuat();
     var cursorPivot = self.cursorPivot;
     var pivotQuat = new THREE.Quaternion();
     pivotQuat.multiply(headQuat);
     cursorPivot.setRotationFromQuaternion(pivotQuat);
     cursorPivot.position.copy(self.camera.position)
 }
コード例 #10
0
  exports.build = function(humanNotation, rotation) {
    rotation = typeof rotation !== 'undefined' ? rotation : "[0,0,0]";

    var rotationArray = JSON.parse(rotation);

    scene = new THREE.Scene();
    figure = new THREE.Object3D();
    figure.useQuaternion = true;
    figure.quaternion = new THREE.Quaternion();
    figure.quaternion.setFromEuler(new THREE.Vector3(rotationArray[0] * Math.PI / 180, rotationArray[1] * Math.PI / 180, rotationArray[2] * Math.PI / 180));
    scene.add(figure);
    prisms = [];
    var computerNotation = parseNotation(humanNotation);

    // after adding a new prism its exit direction
    // is cumulated in this quaternion to be used to
    // orient the next prism
    var Q = new THREE.Quaternion();
    var previous = null;

    for (var i = 0; i < computerNotation.length; i++) {
      var mesh;
      if (i % 2) {
        mesh = THREE.SceneUtils.createMultiMaterialObject(geometryOdd, materialOdd);
      } else {
        if (useFirstColor === true && i === 0) {
          mesh = THREE.SceneUtils.createMultiMaterialObject(geometryEven, materialFirst);
        } else {
          mesh = THREE.SceneUtils.createMultiMaterialObject(geometryEven, materialEven);
        }
      }
      mesh.useQuaternion = true;
      figure.add(mesh);
      prisms.push(mesh);

      mesh.quaternion.copy(Q);
      mesh.updateMatrix();

      Q.multiplyQuaternions(advanceQuaternion(mesh, computerNotation[i]), Q);

      if (previous !== null) {
        connectPrisms(previous, mesh);
      }
      previous = mesh;
    }

    // center each figure around 0,0,0
    var positions = prisms.map(function(prism) {
      return prism.position;
    });
    var center = computeCenter(positions);
    prisms.forEach(function(prism) {
      prism.position.sub(center);
    });

    setupCamera();
  };
コード例 #11
0
	var calculateCameraLocalQuaternion = function (q_camW, q_robotW) {
		var q_camL = new THREE.Quaternion();
		var q_robotW_Inv = new THREE.Quaternion();
		q_robotW_Inv.copy(q_robotW);
		q_robotW_Inv.inverse();
		//TODO: try switching the order of multiply
		q_camL.multiplyQuaternions(q_robotW_Inv,q_camW );
		return q_camL;
	};
コード例 #12
0
 gyroToQuaternionDelta_(gyro, dt) {
   // Extract axis and angle from the gyroscope data.
   var quat = new Quaternion();
   var axis = new Vector3();
   axis.copy(gyro);
   axis.normalize();
   quat.setFromAxisAngle(axis, gyro.length() * dt);
   return quat;
 }
コード例 #13
0
ファイル: Viewport.js プロジェクト: markdalgleish/kansas
    (function update() {

      window.requestAnimationFrame(update.bind(this));

      if (this.freeze) return;

      // should not need this
      var orientation = getOrientation();
      if (orientation !== this.screenOrientation) {
        this.screenOrientation = orientation;
        this.autoAlign = true;
      }

      this.alpha = this.deviceOrientation.gamma ?
        THREE.Math.degToRad(this.deviceOrientation.alpha) : 0; // Z
      this.beta = this.deviceOrientation.beta ?
        THREE.Math.degToRad(this.deviceOrientation.beta) : 0; // X'
      this.gamma = this.deviceOrientation.gamma ?
        THREE.Math.degToRad(this.deviceOrientation.gamma) : 0; // Y''
      this.orient = this.screenOrientation ?
        THREE.Math.degToRad(this.screenOrientation) : 0; // O

      // The angles alpha, beta and gamma
      // form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''

      // 'ZXY' for the device, but 'YXZ' for us
      euler.set(this.beta, this.alpha, - this.gamma, 'YXZ');

      quaternion.setFromEuler(euler);
      quaternionLerp.slerp(quaternion, 0.5); // interpolate

      // orient the device
      if (this.autoAlign) this.orientationQuaternion.copy(quaternion); // interpolation breaks the auto alignment
      else this.orientationQuaternion.copy(quaternionLerp);

      // camera looks out the back of the device, not the top
      this.orientationQuaternion.multiply(q1);

      // adjust for screen orientation
      this.orientationQuaternion.multiply(q0.setFromAxisAngle(zee, - this.orient));

      finalQuaternion.copy(this.alignQuaternion);
      finalQuaternion.multiply(this.orientationQuaternion);

      finalEuler.setFromQuaternion(finalQuaternion, 'YXZ');

      if (this.autoAlign && this.alpha !== 0) {

        this.autoAlign = false;

        this.align();

      }

      this.setState({ euler: finalEuler });

    }).call(this);
コード例 #14
0
 updateCameraQuaternion(alpha, beta, gamma, orientation) {
   const zee = new THREE.Vector3(0, 0, 1);
   const euler = new THREE.Euler();
   const q0 = new THREE.Quaternion();
   const q1 = new THREE.Quaternion(- Math.sqrt(0.5), 0, 0, Math.sqrt(0.5));
   euler.set(beta, alpha, - gamma, 'YXZ'); // 'ZXY' for the device, but 'YXZ' for us
   this.camera.quaternion.setFromEuler(euler); // orient the device
   this.camera.quaternion.multiply(q1); // camera looks out the back of the device, not the top
   this.camera.quaternion.multiply(q0.setFromAxisAngle(zee, - orientation)); // adjust orientation
 }
コード例 #15
0
ファイル: PlanarControls.js プロジェクト: IGNF/itowns
    this.goToTopView = function goToTopView() {
        const topViewPos = new THREE.Vector3();
        const targetQuat = new THREE.Quaternion();

        // the top view position is above the camera focus point, at an altitude = distanceToPoint
        topViewPos.copy(this.getWorldPointAtScreenXY({ x: 0.5 * this.domElement.clientWidth, y: 0.5 * this.domElement.clientHeight }));
        topViewPos.z += Math.min(this.maxAltitude, this.camera.position.distanceTo(topViewPos));

        targetQuat.setFromAxisAngle(new THREE.Vector3(1, 0, 0), 0);

        // initiate the travel
        this.initiateTravel(topViewPos, 'auto', targetQuat, true);
    };
コード例 #16
0
function createMatrix(scale = 1){
  var matrix = new THREE.Matrix4();
  matrix.multiplyScalar(0.01);
  return matrix;

  //var euler = new THREE.Euler( Math.PI, 0, 0, 'YXZ' );
  var q = new THREE.Quaternion();
  q.setFromEuler(euler) 

  var p = new THREE.Vector3(0,0,0),
    s = new THREE.Vector3(scale,scale,scale);

  matrix.compose(p, q, s)
}
コード例 #17
0
ファイル: VRCursor.js プロジェクト: nishioka/vr-globe
 function updatePositionMouseSync(headQuat) {
     var headQuat = self.headQuat();
     self.rotation.x = self.clampAngleTo(self.rotation.x, Math.PI / 6);
     self.rotation.y = self.clampAngleTo(self.rotation.y, Math.PI / 6);
     var rotation = new THREE.Euler(self.rotation.x, self.rotation.y, 0);
     var mouseQuat = new THREE.Quaternion().setFromEuler(rotation, true);
     var cursorPivot = self.cursorPivot;
     var pivotQuat = new THREE.Quaternion();
     pivotQuat
         .multiply(headQuat)
         .multiply(mouseQuat)
         .normalize();
     cursorPivot.setRotationFromQuaternion(pivotQuat);
 }
コード例 #18
0
ファイル: Viewport.js プロジェクト: markdalgleish/kansas
    this.align = function() {

      tempVector3
        .set(0, 0, -1)
        .applyQuaternion( tempQuaternion.copy(this.orientationQuaternion).inverse(), 'ZXY' );

      tempEuler.setFromQuaternion(
        tempQuaternion.setFromRotationMatrix(
          tempMatrix4.lookAt(tempVector3, v0, up)
       )
     );

      tempEuler.set(0, tempEuler.y, 0);
      this.alignQuaternion.setFromEuler(tempEuler);

    };
コード例 #19
0
ファイル: physi.js プロジェクト: rockjins/whitestorm.js
addObjectChildren = function (parent, object) {
  var i;

  for (i = 0; i < object.children.length; i++) {
    if (object.children[i]._physijs) {
      object.children[i].updateMatrix();
      object.children[i].updateMatrixWorld();

      _temp_vector3_1.setFromMatrixPosition(object.children[i].matrixWorld);
      _quaternion_1.setFromRotationMatrix(object.children[i].matrixWorld);

      object.children[i]._physijs.position_offset = {
        x: _temp_vector3_1.x,
        y: _temp_vector3_1.y,
        z: _temp_vector3_1.z
      };

      object.children[i]._physijs.rotation = {
        x: _quaternion_1.x,
        y: _quaternion_1.y,
        z: _quaternion_1.z,
        w: _quaternion_1.w
      };

      parent._physijs.children.push(object.children[i]._physijs);
    }

    addObjectChildren(parent, object.children[i]);
  }
};
コード例 #20
0
ファイル: FeatureProcessing.js プロジェクト: IGNF/itowns
 context.scheduler.execute(command).then((result) => {
     // if request return empty json, WFSProvider.getFeatures return undefined
     if (result) {
         // call onMeshCreated callback if needed
         if (layer.onMeshCreated) {
             layer.onMeshCreated(result);
         }
         node.layerUpdateState[layer.id].success();
         if (!node.parent) {
             ObjectRemovalHelper.removeChildrenAndCleanupRecursively(layer.id, result);
             return;
         }
         // We don't use node.matrixWorld here, because feature coordinates are
         // expressed in crs coordinates (which may be different than world coordinates,
         // if node's layer is attached to an Object with a non-identity transformation)
         const tmp = node.extent.center().as(context.view.referenceCrs).xyz().negate();
         quaternion.setFromRotationMatrix(node.matrixWorld).inverse();
         // const quaternion = new THREE.Quaternion().setFromUnitVectors(new THREE.Vector3(0, 0, 1), node.extent.center().geodesicNormal).inverse();
         applyOffset(result, tmp, quaternion, result.minAltitude);
         if (result.minAltitude) {
             result.position.z = result.minAltitude;
         }
         result.layer = layer;
         node.add(result);
         node.updateMatrixWorld();
     } else {
         node.layerUpdateState[layer.id].failure(1, true);
     }
 },
コード例 #21
0
ファイル: puck.js プロジェクト: keratagpro/tagpro-3d
	updatePosition(player) {
		this.position.x = player.sprite.x;
		this.position.z = player.sprite.y;

		tempQuaternion.setFromAxisAngle(AXIS_Y, -(player.a || 0) * this.params.rotationCoefficient);
		this.quaternion.multiplyQuaternions(tempQuaternion, this.quaternion);
	}
コード例 #22
0
      this.update = (delta) => {
        if (scope.enabled === false) return;

        delta = delta || 0.5;
        delta = Math.min(delta, 0.5);

        inputVelocity.set(0, 0, 0);

        const speed = velocityFactor * delta * params.speed * runVelocity;

        if (moveForward) inputVelocity.z = -speed;
        if (moveBackward) inputVelocity.z = speed;
        if (moveLeft) inputVelocity.x = -speed;
        if (moveRight) inputVelocity.x = speed;

        // Convert velocity to world coordinates
        euler.x = pitchObject.rotation.x;
        euler.y = yawObject.rotation.y;
        euler.order = 'XYZ';

        quat.setFromEuler(euler);

        inputVelocity.applyQuaternion(quat);

        player.applyCentralImpulse({x: inputVelocity.x * 10, y: 0, z: inputVelocity.z * 10});
        player.setAngularVelocity({x: inputVelocity.z * 10, y: 0, z: -inputVelocity.x * 10});
        player.setAngularFactor({x: 0, y: 0, z: 0});

        yawObject.position.copy(player.position);
      };
コード例 #23
0
  constructor(kFilter) {
    this.kFilter = kFilter;

    // Raw sensor measurements.
    this.currentAccelMeasurement = new SensorSample();
    this.currentGyroMeasurement = new SensorSample();
    this.previousGyroMeasurement = new SensorSample();

    // Set default look direction to be in the correct direction.
    if (isiOS) {
      this.filterQ = new Quaternion(-1, 0, 0, 1);
    } else {
      this.filterQ = new Quaternion(1, 0, 0, 1);
    }
    this.previousFilterQ = new Quaternion();
    this.previousFilterQ.copy(this.filterQ);

    // Orientation based on the accelerometer.
    this.accelQ = new Quaternion();
    // Whether or not the orientation has been initialized.
    this.isOrientationInitialized = false;
    // Running estimate of gravity based on the current orientation.
    this.estimatedGravity = new Vector3();
    // Measured gravity based on accelerometer.
    this.measuredGravity = new Vector3();

    // Debug only quaternion of gyro-based orientation.
    this.gyroIntegralQ = new Quaternion();
  }
コード例 #24
0
ファイル: api.js プロジェクト: shawnwanderson/whitestorm.js
const addObjectChildren = function (parent, object) {
  for (let i = 0; i < object.children.length; i++) {
    if (object.children[i]._physijs) {
      object.children[i].updateMatrix();
      object.children[i].updateMatrixWorld();

      temp1Vector3.setFromMatrixPosition(object.children[i].matrixWorld);
      temp1Quat.setFromRotationMatrix(object.children[i].matrixWorld);

      object.children[i]._physijs.position_offset = {
        x: temp1Vector3.x,
        y: temp1Vector3.y,
        z: temp1Vector3.z
      };

      object.children[i]._physijs.rotation = {
        x: temp1Quat.x,
        y: temp1Quat.y,
        z: temp1Quat.z,
        w: temp1Quat.w
      };

      parent._physijs.children.push(object.children[i]._physijs);
    }

    addObjectChildren(parent, object.children[i]);
  }
};
コード例 #25
0
ファイル: entity.js プロジェクト: razh/flying-machines
  update( dt ) {
    this.velocity.addScaledVector( this.acceleration, dt );
    this.position.addScaledVector( this.velocity, dt );

    vector.copy( this.angularVelocity ).multiplyScalar( dt / 2 );
    quaternion.set( vector.x, vector.y, vector.z, 1 ).normalize();
    this.quaternion.multiply( quaternion );
  }
コード例 #26
0
ファイル: VRCursor.js プロジェクト: nishioka/vr-globe
 function updatePositionHides(headQuat) {
     var rotation = new THREE.Euler(self.rotation.x, self.rotation.y, 0);
     var mouseQuat = new THREE.Quaternion().setFromEuler(rotation, true);
     var cursorPivot = self.cursorPivot;
     var headQuat = self.headQuat();
     var pivotQuat = new THREE.Quaternion();
     var showQuat = self.showQuat || new THREE.Quaternion();
     var cameraCursorAngle;
     pivotQuat.multiply(showQuat);
     pivotQuat.multiply(mouseQuat).normalize();
     cursorPivot.quaternion.copy(pivotQuat);
     cameraCursorAngle = quaternionsAngle(headQuat, cursorPivot.quaternion);
     // if the cursor lives the FOV it hides
     if (cameraCursorAngle >= Math.PI / 3) {
         self.hide(0);
     }
 }
コード例 #27
0
		return function (alpha, beta, gamma, screenOrientation) {

			deviceEuler.set(beta, alpha,  - gamma, 'YXZ');

			finalQuaternion.setFromEuler(deviceEuler);

			minusHalfAngle =  - screenOrientation / 2;

			screenTransform.set(0, Math.sin(minusHalfAngle), 0, Math.cos(minusHalfAngle));

			finalQuaternion.multiply(screenTransform);

			finalQuaternion.multiply(worldTransform);

			return finalQuaternion;

		}
コード例 #28
0
			this.traverse( function( child ) {

				tempQuaternion.setFromEuler( worldRotation );

				if ( child.name === "X" ) {

					quaternionX.setFromAxisAngle( unitX, Math.atan2( - eye.y, eye.z ) );
					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
					child.quaternion.copy( tempQuaternion );

				}

				if ( child.name === "Y" ) {

					quaternionY.setFromAxisAngle( unitY, Math.atan2( eye.x, eye.z ) );
					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
					child.quaternion.copy( tempQuaternion );

				}

				if ( child.name === "Z" ) {

					quaternionZ.setFromAxisAngle( unitZ, Math.atan2( eye.y, eye.x ) );
					tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
					child.quaternion.copy( tempQuaternion );

				}

			} );
コード例 #29
0
	this.getYawPitchRollFromDeviceQuaternion = function (quaternion) {

		var deviceQuaternion = new THREE.Quaternion();
		var screenTransform = new THREE.Quaternion();
		var worldTransform = new THREE.Quaternion(0, Math.sqrt(0.5), 0, Math.sqrt(0.5));

		deviceQuaternion.set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);

		var minusHalfAngle = -45; //-90/2

		screenTransform.set(0, Math.sin(minusHalfAngle), 0, Math.cos(minusHalfAngle));

		//deviceQuaternion.multiply( screenTransform );

		deviceQuaternion.multiply(worldTransform);

		return this.getYawPitchRollFromQuaternion(deviceQuaternion);
	};
コード例 #30
0
ファイル: NodeProcess.js プロジェクト: pblottiere/itowns2
NodeProcess.prototype.frustumCullingOBB = function(node, camera) {
    //position in local space
    var position = node.OBB().worldToLocal(camera.position().clone());
    position.z -= node.distance;

    quaternion.multiplyQuaternions( node.OBB().quadInverse(), camera.camera3D.quaternion);

    return camera.getFrustumLocalSpace(position, quaternion).intersectsBox(node.OBB().box3D);
};