• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript THREE.Quaternion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript THREE.Scene类代码示例发布时间:2022-05-25
下一篇:
TypeScript THREE.PerspectiveCamera类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap