本文整理汇总了TypeScript中THREE.Vector3.clone方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Vector3.clone方法的具体用法?TypeScript Vector3.clone怎么用?TypeScript Vector3.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类THREE.Vector3
的用法示例。
在下文中一共展示了Vector3.clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getPointAtDistance
/**
* Get the coords of a point on a line at some given percentage of the distance
* f(t) = A + t * N;
*
* @see https://stackoverflow.com/a/27430674/1092007
*
* @param a
* @param b
* @param percentage
*/
// TODO: Add tests
function getPointAtDistance(a: Vector3, b: Vector3, percentage: number) {
const dir = b.clone()
.sub(a);
const length = dir.length();
dir.normalize()
.multiplyScalar(length * percentage);
return a.clone()
.add(dir);
}
示例2: constructor
/**
* @param {Matrix} points - 3 by N matrix
*/
constructor (points: Matrix) {
// console.time( "PrincipalAxes" );
const n = points.rows
const n3 = n / 3
const pointsT = new Matrix(n, 3)
const A = new Matrix(3, 3)
const W = new Matrix(1, 3)
const U = new Matrix(3, 3)
const V = new Matrix(3, 3)
// calculate
const mean = meanRows(points)
subRows(points, mean)
transpose(pointsT, points)
multiplyABt(A, pointsT, pointsT)
svd(A, W, U, V)
// console.log( points, pointsT, mean )
// console.log( n, A, W, U, V );
// center
const vm = new Vector3(mean[0], mean[1], mean[2])
// normalized
const van = new Vector3(U.data[0], U.data[3], U.data[6])
const vbn = new Vector3(U.data[1], U.data[4], U.data[7])
const vcn = new Vector3(U.data[2], U.data[5], U.data[8])
// scaled
const va = van.clone().multiplyScalar(Math.sqrt(W.data[0] / n3))
const vb = vbn.clone().multiplyScalar(Math.sqrt(W.data[1] / n3))
const vc = vcn.clone().multiplyScalar(Math.sqrt(W.data[2] / n3))
// points
this.begA = vm.clone().sub(va)
this.endA = vm.clone().add(va)
this.begB = vm.clone().sub(vb)
this.endB = vm.clone().add(vb)
this.begC = vm.clone().sub(vc)
this.endC = vm.clone().add(vc)
//
this.center = vm
this.vecA = va
this.vecB = vb
this.vecC = vc
this.normVecA = van
this.normVecB = vbn
this.normVecC = vcn
// console.timeEnd( "PrincipalAxes" );
}
示例3: 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));
}
示例4: getPositionForRotation
function getPositionForRotation(camera: CameraProps, orientation: Quaternion) {
const position = new Vector3(...camera.position);
const center = camera.target
? new Vector3(...camera.target)
: new Vector3(0, 0, 0);
const dir = FORWARD.clone();
dir.applyQuaternion(orientation);
const radius = position.clone()
.sub(center)
.length();
return dir.negate()
.multiplyScalar(radius)
.add(center);
}
示例5: genMap
genMap() {
this._stars = [];
var numStars = 8;
var radius = 9 * this._step * numStars;
var center = new Vector3(radius, 0, 0);
var pointer = new Vector3(-radius, 0, 0);
for(var i = 0; i < numStars; i++) {
pointer.applyAxisAngle(new Vector3(0, 1, 0), Math.PI * 2 / (numStars + 1));
var star = Stars.genRandom(new Vector3());
if (i === 0) {
var pos = center.clone().add(pointer);
} else {
var pos = this._genStarPoint(center.clone().add(pointer), star, radius);
}
star.setPosition(pos);
this._stars.push(star);
}
this._genPoints(new Vector3(), new Vector3(0, 0, -this._step));
}
示例6: getControlPoints
function getControlPoints(p1: Vector3, p2: Vector3, p3: Vector3, tension: number){
var d12 = p1.clone().sub(p2).length();
var d23 = p2.clone().sub(p3).length();
var fa = tension * d12 / (d12+d23);
var fb = tension * d23 / (d12+d23);
var c1 = p2.clone().sub(p3.clone().sub(p1).multiplyScalar(fa));
var c2 = p2.clone().add(p3.clone().sub(p1).multiplyScalar(fb));
return {
left: c1,
right: c2
};
}
示例7: _genStarPoint
private _genStarPoint(point: Vector3, star: Star, radius: number) {
var distAdd = Section.size * 3;
if (star) {
distAdd += this._getDist(star);
}
var count = 0;
while (count < 10) {
var mag = radius * 0.7;
var p = point.clone().add(new Vector3(
randomRange(-mag, mag),
randomRange(-mag / 10, mag / 10),
randomRange(-mag, mag)
));
if (this._stars.every((star) => {
return dist(p, star.position) > distAdd + this._getDist(star);
})) {
return p;
}
}
throw "no";
}
示例8: cubic
function cubic(start: Vector3, end: Vector3, control1: Vector3, control2: Vector3, t: number) {
return start.clone().multiplyScalar(Math.pow(1 - t, 3))
.add(control1.clone().multiplyScalar(3 * Math.pow(1 - t, 2) * t))
.add(control2.clone().multiplyScalar(3 * (1 - t) * t * t))
.add(end.clone().multiplyScalar(t * t * t));
}
示例9: quadratic
function quadratic(start: Vector3, end: Vector3, control: Vector3, t: number) {
return start.clone().multiplyScalar(Math.pow(1 - t, 2))
.add(control.clone().multiplyScalar(2 * (1 - t) * t))
.add(end.clone().multiplyScalar(t * t));
}
示例10: _genPoints
private _genPoints(start: Vector3, end: Vector3) {
this._points = [];
var cur = start;
var connectPoints = [start];
var starInd = 0;
while (starInd < this._stars.length) {
var nextNextPoint: Vector3;
if (starInd + 1 < this._stars.length) {
nextNextPoint = this._stars[starInd + 1].position;
} else {
nextNextPoint = end;
}
var curStarPoint = this._stars[starInd].position;
var minDist = this._getDist(this._stars[starInd]);
var dir = nextNextPoint.clone().sub(cur).normalize();
var plane = new Plane().setFromNormalAndCoplanarPoint(dir, curStarPoint);
var starDir = curStarPoint.clone().sub(cur);
var randomDir = starDir.clone().normalize().add(new Vector3(
randomRange(-0.01, 0.01),
randomRange(-0.01, 0.01),
randomRange(-0.01, 0.01)
)).setLength(starDir.length() * 2);
var randomLine = new Line3(cur.clone(), cur.clone().add(randomDir));
var point = plane.intersectLine(randomLine)
.sub(curStarPoint)
.setLength(minDist)
.add(curStarPoint);
var connectLine = new Line3(
cur.clone().sub(dir.clone().setLength(9999999)),
nextNextPoint.clone().add(dir.clone().setLength(9999999)));
var starDir = plane.intersectLine(connectLine).sub(curStarPoint);
var pointDir = point.clone().sub(curStarPoint);
if (pointDir.clone().projectOnVector(starDir).add(starDir).length() > starDir.length()) {
point = curStarPoint.clone().sub(pointDir);
}
connectPoints.push(point);
cur = curStarPoint;
starInd += 1;
}
connectPoints.push(end);
var controlPoints: Vector3[] = [];
var pointToStar: number[] = [];
connectPoints.forEach((point, ind) => {
if (ind + 2 >= connectPoints.length) return;
var cur = point,
next = connectPoints[ind + 1],
nextNext = connectPoints[ind + 2];
var {left, right} = getControlPoints(cur, next, nextNext, 0.9);
controlPoints.push(left, right);
});
connectPoints.forEach((point, ind) => {
if (ind + 1 === connectPoints.length) return;
var nextPoint = connectPoints[ind + 1];
var numSteps = Math.ceil(nextPoint.clone().sub(point).length() / this._step);
var tstep = 1 / numSteps;
if (ind === 0) {
for (var i = 0; i < numSteps; i += 1) {
this._points.push(quadratic(point, nextPoint, controlPoints[0], i * tstep));
}
} else if (ind + 2 === connectPoints.length) {
for (var i = 0; i < numSteps; i+= 1) {
this._points.push(quadratic(point, nextPoint, controlPoints[ind * 2 - 1], i * tstep));
}
this._points.push(nextPoint);
} else {
for (var i = 0; i < numSteps; i+= 1) {
this._points.push(cubic(point, nextPoint, controlPoints[ind * 2 - 1], controlPoints[ind * 2], i * tstep));
}
}
if (ind > 0) {
for (var i = 0; i < numSteps / 2; i++) {
pointToStar.push(ind - 1);
}
} else {
for (var i = 0; i < numSteps / 2; i++) {
pointToStar.push(null);
}
}
if (ind + 2 < connectPoints.length) {
for (var i = Math.ceil(numSteps / 2); i < numSteps; i++) {
pointToStar.push(ind);
}
} else {
for (var i = Math.ceil(numSteps / 2); i <= numSteps; i++) {
pointToStar.push(null);
}
}
});
for (var i = 0; i < 30; i++) {
this._points = this._smooth(this._points, 1, pointToStar);
//.........这里部分代码省略.........