本文整理汇总了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,
};
}
示例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
];
}
示例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() );
}
});
示例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
};
}
示例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()
};
}
示例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
};
}
示例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;
}
示例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()
}
示例9: fromEuler
export function fromEuler(euler: number[]) {
const e = new Euler(...euler);
const q = new Quaternion();
return q.setFromEuler(e)
.toArray();
}
示例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));
}