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


TypeScript Vector3.clone方法代码示例

本文整理汇总了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);
}
开发者ID:chevtche,项目名称:Brayns,代码行数:20,代码来源:utils.ts

示例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" );
  }
开发者ID:arose,项目名称:ngl,代码行数:59,代码来源:principal-axes.ts

示例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));

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

示例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);
}
开发者ID:chevtche,项目名称:Brayns,代码行数:17,代码来源:camera.ts

示例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));
    }
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:20,代码来源:map_generator.ts

示例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
    };
}
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:13,代码来源:map_generator.ts

示例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";
 }
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:21,代码来源:map_generator.ts

示例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));
}
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:6,代码来源:map_generator.ts

示例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));
}
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:5,代码来源:map_generator.ts

示例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);
//.........这里部分代码省略.........
开发者ID:yyjhao,项目名称:galaxy-tunnel,代码行数:101,代码来源:map_generator.ts


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