当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript THREE.Quaternion类代码示例

本文整理汇总了TypeScript中THREE.Quaternion的典型用法代码示例。如果您正苦于以下问题:TypeScript Quaternion类的具体用法?TypeScript Quaternion怎么用?TypeScript Quaternion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Quaternion类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: addElement

function addElement( elem ) {
  const scene = elem.getScene();

  const geo = elem.getAttribute( "geo" );
  const type = geo.type.split( "Buffer" )[ 0 ];
  let sceneIndex = sceneList.indexOf( scene );

  if ( sceneIndex === -1 ) {
    exportData.createWorld( scene );
    sceneIndex = sceneList.indexOf( scene );
  }

  objectList[ sceneIndex ].push( elem );

  const position = elem.coreObject.getWorldPosition();
  const quaternion = elem.coreObject.getWorldQuaternion();
  const scale = elem.coreObject.getWorldScale();

  if ( type === "Cylinder" ) {
    quaternion.multiply( tmpQuat.multiplyQuaternions(
      cylinderQuat,
      rotateQuat.setFromAxisAngle( rotateVec, Math.PI / cylinderAngle( geo.value[ 3 ] ) )
    ) );
  }

  return {
    position: { x: position.x, y: position.y, z: position.z },
    quaternion: { w: quaternion.w, x: quaternion.x, y: quaternion.y, z: quaternion.z },
    scale: { x: scale.x, y: scale.y, z: scale.z },
    sceneIndex,
    size: geo.value.slice( 0, type === "Cylinder" ? 4 : type === "Box" ? 3 : type === "Plane" ? 2 : 1/*Sphere*/ ),
    type,
  };
}
开发者ID:luca3104,项目名称:solufa,代码行数:34,代码来源:physics.ts

示例2: toAxisAngle

export function toAxisAngle(quaternion: number[]) {
    const q = new Quaternion(...quaternion);

    if (q.z > 1) {
        q.normalize();
    }

    const {x, y, z, w} = q;

    const angle = 2 * Math.acos(w); // rad
    const s = Math.sqrt(1 - w * w);

    if (s < 0.001) {
        return [
            x || 1, // If x = 0, normalize it
            y,
            z,
            angle
        ];
    }

    return [
        x / s,
        y / s,
        z / s,
        angle
    ];
}
开发者ID:chevtche,项目名称:Brayns,代码行数:28,代码来源:quaternion.ts

示例3: function

      objects.forEach( function( object, I ) {
        if ( object.getAttribute( "physics" ).mass === 0 ) { return; }

        let i = I + 1; // index of GroundPlane == 0

        object.coreObject.position.set(
          e.data.dataList[ index ].positions[ 3 * i ],
          e.data.dataList[ index ].positions[ 3 * i + 1 ],
          e.data.dataList[ index ].positions[ 3 * i + 2 ]
        );

        object.coreObject.quaternion.set(
          e.data.dataList[ index ].quaternions[ 4 * i ],
          e.data.dataList[ index ].quaternions[ 4 * i + 1 ],
          e.data.dataList[ index ].quaternions[ 4 * i + 2 ],
          e.data.dataList[ index ].quaternions[ 4 * i + 3 ]
        );

        if ( /^Cylinder/.test( object.getAttribute( "geo" ).type ) ) {
          object.coreObject.quaternion.multiply( tmpQuat.multiplyQuaternions(
            cylinderQuat,
            rotateQuat.setFromAxisAngle( rotateVec, Math.PI / cylinderAngle( object.getAttribute( "geo" ).value[ 3 ] ) )
          ).inverse() );
        }

      });
开发者ID:luca3104,项目名称:solufa,代码行数:26,代码来源:physics.ts

示例4: setCameraRotation

export function setCameraRotation(camera: CameraProps, quaternion: number[]): CameraProps {
    const orientation = new Quaternion(...quaternion);
    const position = getPositionForRotation(camera, orientation);

    return {
        position: position.toArray(),
        orientation: orientation.toArray(),
        target: camera.target
    };
}
开发者ID:chevtche,项目名称:Brayns,代码行数:10,代码来源:camera.ts

示例5: rotateToBoundingBox

export function rotateToBoundingBox(camera: CameraProps, bb: BoundingBox): CameraProps {
    const orientation = new Quaternion(0, 0, 0, 1);
    const {center, target} = getBoundingBoxCenter(bb);

    const position = getPositionForRotation({
        ...camera,
        target: target.toArray(),
        position: FORWARD.toArray()
    }, orientation);

    return {
        position: position.toArray(),
        orientation: orientation.toArray(),
        target: center.toArray()
    };
}
开发者ID:chevtche,项目名称:Brayns,代码行数:16,代码来源:camera.ts

示例6: rotateCamera

export function rotateCamera(camera: CameraProps, rotation: Rotation): CameraProps {
    const orientation =  new Quaternion(...camera.orientation);

    const rotations = Object.entries(rotation)
        .filter(([, value]) => isNumber(value));

    for (const [axis, value] of rotations) {
        const angle = degToRad(value);
        const rotation = fromAxisAngle([...axes.get(axis), angle]);
        orientation.multiply(rotation);
    }

    const position = getPositionForRotation(camera, orientation);

    return {
        position: position.toArray(),
        orientation: orientation.toArray(),
        target: camera.target
    };
}
开发者ID:chevtche,项目名称:Brayns,代码行数:20,代码来源:camera.ts

示例7: _createQuaternion

  _createQuaternion(dimension: MTNX.Dimension, degrees: number) {
    const quaternion = new THREE.Quaternion();

    const rads = degreesToRadians(degrees);

    const Dimension = MTNX.Dimension;
    switch (dimension) {
      case Dimension.X:
        quaternion.setFromAxisAngle(new THREE.Vector3(1, 0, 0), rads);
        break;
      case Dimension.Y:
        quaternion.setFromAxisAngle(new THREE.Vector3(0, 1, 0), rads);
        break;
      case Dimension.Z:
        quaternion.setFromAxisAngle(new THREE.Vector3(0, 0, 1), rads);
        break;
      default:
        console.warn(`Didn't set quaternion value for ${$$hex(dimension)}`);
    }

    return quaternion;
  }
开发者ID:PartyPlanner64,项目名称:PartyPlanner64,代码行数:22,代码来源:MtnxToThreeJs.ts

示例8: rotateComponent

  rotateComponent (x: number, y: number) {
    if (!this.component) return

    const [ dx, dy ] = this._getRotateXY(x, y)

    tmpRotateMatrix.extractRotation(this.component.transform)
    tmpRotateMatrix.premultiply(this.viewer.rotationGroup.matrix)
    tmpRotateMatrix.getInverse(tmpRotateMatrix)
    tmpRotateVector.set(1, 0, 0)
    tmpRotateVector.applyMatrix4(tmpRotateMatrix)
    tmpRotateXMatrix.makeRotationAxis(tmpRotateVector, dy)
    tmpRotateVector.set(0, 1, 0)
    tmpRotateVector.applyMatrix4(tmpRotateMatrix)
    tmpRotateYMatrix.makeRotationAxis(tmpRotateVector, dx)
    tmpRotateXMatrix.multiply(tmpRotateYMatrix)
    tmpRotateQuaternion.setFromRotationMatrix(tmpRotateXMatrix)
    this.component.quaternion.premultiply(tmpRotateQuaternion)
    this.component.updateMatrix()
  }
开发者ID:arose,项目名称:ngl,代码行数:19,代码来源:trackball-controls.ts

示例9: fromEuler

export function fromEuler(euler: number[]) {
    const e = new Euler(...euler);
    const q = new Quaternion();
    return q.setFromEuler(e)
        .toArray();
}
开发者ID:chevtche,项目名称:Brayns,代码行数:6,代码来源:quaternion.ts

示例10: update

    update(world: World, control: Control) {
        var beta = control.motionTracker.getBeta();
        this._acceleration.copy(this._speed).divideScalar(30).clampLength(0.1, 3);
        this._acceleration.applyAxisAngle(yAxis, horizontalRotation(beta));

        this._speed.add(this._acceleration);
        this._speed.clampLength(0, 80);

        var newPos = new Vector3().addVectors(this._position, this._speed);
        this._playerTracker.updateSection(newPos);
        var collision = this._playerTracker.getCollision();
        if (collision) {
            newPos = collision;
            this._speed.multiplyScalar(0.3);
            newPos = this._playerTracker.getAdjusted(newPos);
            this._position.copy(newPos);
        } else {
            newPos = this._playerTracker.getAdjusted(newPos);

            this._acceleration.subVectors(newPos, this._position).sub(this._speed).clampLength(0, 5);
            this._speed.add(this._acceleration);
            this._position.add(this._speed);
        }

        this._direction.setFromUnitVectors(
            new Vector3(0, 0, 1),
            this._speed.clone().setY(0).setLength(1));

    }
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:29,代码来源:player.ts


注:本文中的THREE.Quaternion类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。