本文整理汇总了TypeScript中THREE.Vector3.length方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Vector3.length方法的具体用法?TypeScript Vector3.length怎么用?TypeScript Vector3.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类THREE.Vector3
的用法示例。
在下文中一共展示了Vector3.length方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _applyRotation
private _applyRotation(camera: Camera): void {
if (camera == null) {
return;
}
let q: THREE.Quaternion = new THREE.Quaternion().setFromUnitVectors(camera.up, new THREE.Vector3( 0, 0, 1 ));
let qInverse: THREE.Quaternion = q.clone().inverse();
let offset: THREE.Vector3 = new THREE.Vector3();
offset.copy(camera.lookat).sub(camera.position);
offset.applyQuaternion(q);
let length: number = offset.length();
let phi: number = Math.atan2(offset.y, offset.x);
phi += this._rotationDelta.phi;
let theta: number = Math.atan2(Math.sqrt(offset.x * offset.x + offset.y * offset.y), offset.z);
theta += this._rotationDelta.theta;
theta = Math.max(0.1, Math.min(Math.PI - 0.1, theta));
offset.x = Math.sin(theta) * Math.cos(phi);
offset.y = Math.sin(theta) * Math.sin(phi);
offset.z = Math.cos(theta);
offset.applyQuaternion(qInverse);
camera.lookat.copy(camera.position).add(offset.multiplyScalar(length));
}
示例2: function
return function( deltaX, deltaY ) {
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
if ( scope.object instanceof three.PerspectiveCamera ) {
// perspective
var position = scope.object.position;
offset.copy( position ).sub( scope.target );
var targetDistance = offset.length();
// half of the fov is center to top of screen
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
// we actually don't use screenWidth, since perspective camera is fixed to screen height
panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
} else if ( scope.object instanceof three.OrthographicCamera ) {
// orthographic
panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
} else {
// camera neither orthographic nor perspective
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
scope.enablePan = false;
}
};
示例3: _update
_update () {
if (!this.getVisibility()) return
const s = this.element.style
const cp = this._canvasPosition
const vp = this._viewerPosition
const cr = this._clientRect
this._cameraPosition.copy(vp)
.add(this.viewer.translationGroup.position)
.applyMatrix4(this.viewer.rotationGroup.matrix)
.sub(this.viewer.camera.position)
if (this._cameraPosition.z < 0) {
s.display = 'none'
return
} else {
s.display = 'block'
}
const depth = this._cameraPosition.length()
const fog = this.viewer.scene.fog as any // TODO
s.opacity = (1 - smoothstep(fog.near, fog.far, depth)).toString()
s.zIndex = (Math.round((fog.far - depth) * 100)).toString()
this.stage.viewerControls.getPositionOnCanvas(vp, cp)
s.bottom = (this.offsetX + cp.y + cr.height / 2) + 'px'
s.left = (this.offsetY + cp.x - cr.width / 2) + 'px'
}
示例4: _getRt
private _getRt(node: Node): THREE.Matrix4 {
let axis: THREE.Vector3 = new THREE.Vector3(
node.apiNavImIm.rotation[0],
node.apiNavImIm.rotation[1],
node.apiNavImIm.rotation[2]);
let angle: number = axis.length();
axis.normalize();
let rt: THREE.Matrix4 = new THREE.Matrix4();
rt.makeRotationAxis(axis, angle);
rt.setPosition(new THREE.Vector3(
node.translation[0],
node.translation[1],
node.translation[2]));
return rt;
}
示例5: getPosition
getPosition (): HelixPosition {
const polymer = this.polymer
const structure = polymer.structure
const n = polymer.residueCount
const n3 = n - 3
const center = new Float32Array(3 * n)
const axis = new Float32Array(3 * n)
const diff = new Float32Array(n)
const radius = new Float32Array(n)
const rise = new Float32Array(n)
const twist = new Float32Array(n)
const resdir = new Float32Array(3 * n)
const r12 = new Vector3()
const r23 = new Vector3()
const r34 = new Vector3()
const diff13 = new Vector3()
const diff24 = new Vector3()
const v1 = new Vector3()
const v2 = new Vector3()
const vt = new Vector3()
const _axis = new Vector3()
const _prevAxis = new Vector3()
const _resdir = new Vector3()
const _center = new Vector3(0, 0, 0)
const type = 'trace'
const a1 = structure.getAtomProxy()
const a2 = structure.getAtomProxy(polymer.getAtomIndexByType(0, type))
const a3 = structure.getAtomProxy(polymer.getAtomIndexByType(1, type))
const a4 = structure.getAtomProxy(polymer.getAtomIndexByType(2, type))
for (let i = 0; i < n3; ++i) {
a1.index = a2.index
a2.index = a3.index
a3.index = a4.index
a4.index = polymer.getAtomIndexByType(i + 3, type)! // TODO
const j = 3 * i
// ported from GROMACS src/tools/gmx_helixorient.c
r12.subVectors(a2 as any, a1 as any) // TODO
r23.subVectors(a3 as any, a2 as any) // TODO
r34.subVectors(a4 as any, a3 as any) // TODO
diff13.subVectors(r12, r23)
diff24.subVectors(r23, r34)
_axis.crossVectors(diff13, diff24).normalize()
_axis.toArray(axis as any, j) // TODO
if (i > 0) {
diff[ i ] = _axis.angleTo(_prevAxis)
}
const tmp = Math.cos(diff13.angleTo(diff24))
twist[ i ] = 180.0 / Math.PI * Math.acos(tmp)
const diff13Length = diff13.length()
const diff24Length = diff24.length()
radius[ i ] = (
Math.sqrt(diff24Length * diff13Length) /
// clamp, to avoid instabilities for when
// angle between diff13 and diff24 is near 0
Math.max(2.0, 2.0 * (1.0 - tmp))
)
rise[ i ] = Math.abs(r23.dot(_axis))
//
v1.copy(diff13).multiplyScalar(radius[ i ] / diff13Length)
v2.copy(diff24).multiplyScalar(radius[ i ] / diff24Length)
v1.subVectors(a2 as any, v1) // TODO
v2.subVectors(a3 as any, v2) // TODO
v1.toArray(center as any, j + 3) // TODO
v2.toArray(center as any, j + 6) // TODO
//
_resdir.subVectors(a1 as any, _center) // TODO
_resdir.toArray(resdir as any, j) // TODO
_prevAxis.copy(_axis)
_center.copy(v1)
}
//
// calc axis as dir of second and third center pos
// project first traceAtom onto axis to get first center pos
//.........这里部分代码省略.........
示例6: calculateDirectionArray
export function getFixedLengthDashData<T extends CylinderBufferData|WideLineBufferData> (data: T, segmentLength: number = 0.1) {
const direction = calculateDirectionArray(data.position1, data.position2)
const pos1: number[] = []
const pos2: number[] = []
const col: number[] = []
const rad: number[]|undefined = (data as any).radius ? [] : undefined
const pick: number[]|undefined = (data as any).picking ? [] : undefined
const id: number[]|undefined = (data as any).primitiveId ? [] : undefined
const v = new Vector3()
const n = data.position1.length / 3
let k = 0
for (let i = 0; i < n; ++i) {
const i3 = i * 3
v.set(direction[ i3 ], direction[ i3 + 1 ], direction[ i3 + 2 ])
const vl = v.length()
const segmentCount = vl / segmentLength
const s = Math.floor(segmentCount / 2)
const step = 1 / segmentCount
const x = data.position1[ i3 ]
const y = data.position1[ i3 + 1 ]
const z = data.position1[ i3 + 2 ]
for (let j = 0; j < s; ++j) {
const j3 = k * 3 + j * 3
const f1 = step * (j * 2 + 1)
const f2 = step * (j * 2 + 2)
pos1[ j3 ] = x + v.x * f1
pos1[ j3 + 1 ] = y + v.y * f1
pos1[ j3 + 2 ] = z + v.z * f1
pos2[ j3 ] = x + v.x * f2
pos2[ j3 + 1 ] = y + v.y * f2
pos2[ j3 + 2 ] = z + v.z * f2
if (data.color) {
col[ j3 ] = data.color[ i3 ]
col[ j3 + 1 ] = data.color[ i3 + 1 ]
col[ j3 + 2 ] = data.color[ i3 + 2 ]
}
if (rad) rad[ k + j ] = (data as any).radius[ i ]
if (pick) {
if ((data as any).picking.array) {
pick[ k + j ] = (data as any).picking.array[ i ]
} else {
pick[ k + j ] = i
}
}
if (id) id[ k + j ] = (data as any).primitiveId[ i ]
}
k += s
}
const position1 = new Float32Array(pos1)
const position2 = new Float32Array(pos2)
const position = calculateCenterArray(position1, position2) as Float32Array
const color = new Float32Array(col)
const color2 = color
const d: any = { position, position1, position2, color, color2 }
if (rad) d.radius = new Float32Array(rad)
if (pick && data.picking) {
data.picking.array = new Float32Array(pick)
d.picking = data.picking
}
if (id) d.primitiveId = new Float32Array(id)
return d as T
}
示例7: getPotentialEdges
/**
* Returns the potential edges to destination nodes for a set
* of nodes with respect to a source node.
*
* @param {Node} node The source node
* @param {Array<Node>} nodes Potential destination nodes
* @param {Array<string>} fallbackKeys Keys for destination nodes that should
* be returned even if they do not meet
* the criteria for a potential edge.
*/
public getPotentialEdges(node: Node, nodes: Node[], fallbackKeys: string[]): IPotentialEdge[] {
if (!node.worthy || !node.merged) {
return [];
}
let currentDirection: THREE.Vector3 =
this._spatial.viewingDirection(node.apiNavImIm.rotation);
let currentVerticalDirection: number =
this._spatial.angleToPlane(currentDirection.toArray(), [0, 0, 1]);
let potentialEdges: IPotentialEdge[] = [];
for (let potential of nodes) {
if (!potential.merged ||
potential.key === node.key) {
continue;
}
let enu: number[] = this._geoCoords.geodeticToEnu(
potential.latLon.lat,
potential.latLon.lon,
potential.apiNavImIm.calt,
node.latLon.lat,
node.latLon.lon,
node.apiNavImIm.calt);
let motion: THREE.Vector3 = new THREE.Vector3(enu[0], enu[1], enu[2]);
let distance: number = motion.length();
if (distance > this._settings.maxDistance &&
fallbackKeys.indexOf(potential.key) < 0) {
continue;
}
let motionChange: number = this._spatial.angleBetweenVector2(
currentDirection.x,
currentDirection.y,
motion.x,
motion.y);
let verticalMotion: number = this._spatial.angleToPlane(motion.toArray(), [0, 0, 1]);
let direction: THREE.Vector3 =
this._spatial.viewingDirection(potential.apiNavImIm.rotation);
let directionChange: number = this._spatial.angleBetweenVector2(
currentDirection.x,
currentDirection.y,
direction.x,
direction.y);
let verticalDirection: number = this._spatial.angleToPlane(direction.toArray(), [0, 0, 1]);
let verticalDirectionChange: number = verticalDirection - currentVerticalDirection;
let rotation: number = this._spatial.relativeRotationAngle(
node.apiNavImIm.rotation,
potential.apiNavImIm.rotation);
let worldMotionAzimuth: number =
this._spatial.angleBetweenVector2(1, 0, motion.x, motion.y);
let sameSequence: boolean = potential.sequence != null &&
node.sequence != null &&
potential.sequence.key === node.sequence.key;
let sameMergeCc: boolean =
(potential.apiNavImIm.merge_cc == null && node.apiNavImIm.merge_cc == null) ||
potential.apiNavImIm.merge_cc === node.apiNavImIm.merge_cc;
let potentialEdge: IPotentialEdge = {
apiNavImIm: potential.apiNavImIm,
directionChange: directionChange,
distance: distance,
fullPano: potential.fullPano,
motionChange: motionChange,
rotation: rotation,
sameMergeCc: sameMergeCc,
sameSequence: sameSequence,
verticalDirectionChange: verticalDirectionChange,
verticalMotion: verticalMotion,
worldMotionAzimuth: worldMotionAzimuth,
};
potentialEdges.push(potentialEdge);
}
return potentialEdges;
}