當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript vec3.subtract方法代碼示例

本文整理匯總了TypeScript中gl-matrix.vec3.subtract方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript vec3.subtract方法的具體用法?TypeScript vec3.subtract怎麽用?TypeScript vec3.subtract使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gl-matrix.vec3的用法示例。


在下文中一共展示了vec3.subtract方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: updateFaceNormal

  public updateFaceNormal() {
    // from threejs
    vec3.set(cb, 0, 0, 0);
    vec3.set(ab, 0, 0, 0);
    vec3.subtract(cb, this.vertices[2].v, this.vertices[1].v);
    vec3.subtract(ab, this.vertices[0].v, this.vertices[1].v);
    vec3.cross(cb, cb, ab);

    vec3.normalize(cb, cb);
    this.normal.set(cb[0], cb[1], cb[2]);
  }
開發者ID:davidpaulrosser,項目名稱:leonardo,代碼行數:11,代碼來源:Face.ts

示例2: moveAlong

    moveAlong(elapsedTime: number, speed: number): Vec3 {
        // If there is no further waypoint, we've arrived at the end and we
        // always return the current position.
        if (this.done) {
            return vec3.clone(this.currentPosition);
        }

        // The vector from the current position to the next waypoint.
        var vector        = vec3.subtract(vec3.create(), this.waypoints[0], this.currentPosition)
          , vectorLength  = vec3.length(vector)
          , distanceMoved = speed * elapsedTime;

        if (vectorLength < distanceMoved) {
            // The remaining distance in the current segment is less than what
            // we moved, jump to the next waypoint and move along the next path
            // segment from there.

            vec3.copy(this.currentPosition, this.waypoints.shift());
            this.currentHeading = normalizeHeading(Math.atan2(vector[1], vector[0]));

            return this.moveAlong(elapsedTime - vectorLength / speed, speed);
        }

        // We have not yet reached the next waypoint. Move along the vector
        // towards it and update the heading.
        vec3.add(this.currentPosition, this.currentPosition, vec3.scale(vec3.create(), vec3.normalize(vec3.create(), vector), distanceMoved));
        this.currentHeading = normalizeHeading(Math.atan2(vector[1], vector[0]));

        return vec3.clone(this.currentPosition);
    }
開發者ID:rmx,項目名稱:encounter,代碼行數:30,代碼來源:MovePath.ts

示例3: distanceSqToPoint

  public distanceSqToPoint(point: Vector3) {
    vec3.subtract(v1, point.v, this.origin.v);
    const directionDistance = vec3.dot(v1, this.direction.v);

    // point behind the ray
    if (directionDistance < 0) {
      return vec3.squaredDistance(this.origin.v, point.v);
    }

    vec3.copy(v1, this.direction.v);
    vec3.scale(v1, v1, directionDistance);
    vec3.add(v1, v1, this.origin.v);

    return vec3.squaredDistance(v1, point.v);
  }
開發者ID:davidpaulrosser,項目名稱:leonardo,代碼行數:15,代碼來源:Ray.ts

示例4: needRecomputeMovePath

    private needRecomputeMovePath(): boolean {
        var terrain  = lookupEntity<Terrain>(this.state, this.target.terrainId)
          , tpos     = getWorldCoordinates(terrain, this.target.terrainPosition)
          , fpos     = finalPosition(this.owner)
          , distance = Math.abs(vec3.length(vec3.subtract(vec3.create(), tpos, fpos)))
          , diff     = distance - (this.distance + this.target.boundingRadius);

        return 0.1 < diff;

        function finalPosition(entity: WorldObject): Vec3 {
            if (entity.movePath) {
                return entity.movePath.finalPosition;
            } else {
                return getWorldCoordinates(terrain, entity.terrainPosition);
            }
        }
    }
開發者ID:rmx,項目名稱:encounter,代碼行數:17,代碼來源:follow.ts

示例5: constructor

 constructor(
   readonly type: BoneType,
   readonly basis: Triple<vec3>,
   readonly prevJoint: vec3,
   readonly nextJoint: vec3,
   readonly width: number
 ) {
   const difference = vec3.subtract(vec3.create(), this.nextJoint, this.prevJoint);
   this.length = vec3.length(difference);
   this.basisMatrix = mat3.fromValues(
     this.basis[0][0], this.basis[0][1], this.basis[0][2],
     this.basis[1][0], this.basis[1][1], this.basis[1][2],
     this.basis[2][0], this.basis[2][1], this.basis[2][2]
   );
   this.left = mat3.determinant(this.basisMatrix) < 0;
   this.center = vec3.lerp(vec3.create(), this.prevJoint, this.nextJoint, 0.5);
   this.direction = Bone.createBoneDirection(this.basisMatrix);
   this.matrix = Bone.createBoneMatrix(this.basisMatrix, this.center, this.left);
 }
開發者ID:alexeden,項目名稱:dotstar-node,代碼行數:19,代碼來源:bone.ts

示例6:

outVec2 = vec2.transformMat3(outVec2, vec2A, mat3A);
outVec2 = vec2.transformMat4(outVec2, vec2A, mat4A);
vecArray = vec2.forEach(vecArray, 0, 0, 0, vec2.normalize);
outStr = vec2.str(vec2A);
outBool = vec2.exactEquals(vec2A, vec2B);
outBool = vec2.equals(vec2A, vec2B);
outVec2 = vec2.add(outVec2, [0, 1], [2, 3]); // test one method with number array input

// vec3
outVec3 = vec3.create();
outVec3 = vec3.clone(vec3A);
outVec3 = vec3.fromValues(1, 2, 3);
outVec3 = vec3.copy(outVec3, vec3A);
outVec3 = vec3.set(outVec3, 1, 2, 3);
outVec3 = vec3.add(outVec3, vec3A, vec3B);
outVec3 = vec3.subtract(outVec3, vec3A, vec3B);
outVec3 = vec3.sub(outVec3, vec3A, vec3B);
outVec3 = vec3.multiply(outVec3, vec3A, vec3B);
outVec3 = vec3.mul(outVec3, vec3A, vec3B);
outVec3 = vec3.divide(outVec3, vec3A, vec3B);
outVec3 = vec3.div(outVec3, vec3A, vec3B);
outVec3 = vec3.ceil(outVec3, vec3A);
outVec3 = vec3.floor(outVec3, vec3A);
outVec3 = vec3.min(outVec3, vec3A, vec3B);
outVec3 = vec3.max(outVec3, vec3A, vec3B);
outVec3 = vec3.round(outVec3, vec3A);
outVec3 = vec3.scale(outVec3, vec3A, 2);
outVec3 = vec3.scaleAndAdd(outVec3, vec3A, vec3B, 0.5);
outVal = vec3.distance(vec3A, vec3B);
outVal = vec3.dist(vec3A, vec3B);
outVal = vec3.squaredDistance(vec3A, vec3B);
開發者ID:DenisCarriere,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:gl-matrix-tests.ts

示例7: diagonal

 diagonal(): Vec3 {
     return vec3.subtract(vec3.create(), this.max, this.min);
 }
開發者ID:rmx,項目名稱:encounter,代碼行數:3,代碼來源:BoundingBox.ts

示例8: extrude

 extrude(delta: Vec3): void {
     vec3.add(this.max, this.max, delta);
     vec3.subtract(this.min, this.min, delta);
 }
開發者ID:rmx,項目名稱:encounter,代碼行數:4,代碼來源:BoundingBox.ts

示例9: nextCornerPathReconstruction

    // Reconstructs the path and returns waypoints connecting start and
    // target position with corners.
    private nextCornerPathReconstruction(current: HalfEdgeFace,
            path: HalfEdgeFace[]): Vec3[] {

        var nav_mesh_path  = this.reconstructPath(current, path)
        , reset          = true
        , best_left      = null
        , best_right     = null
        , best_right_dir = vec3.create()
        , best_left_dir  = vec3.create()
        , corner_path    = [];

        corner_path.push(this._current_pos);

        //while we have a next nav mesh face on the path we:
        //  - compute new line of sight, left & right corner and direction
        //  - check if we still "see" the new left & right corners
        //  - update best values or add corner "blocking" the line of sight
        //    to waypoint list
        while (nav_mesh_path.length > 1) {
            var current_face = nav_mesh_path.shift()
              , sharing_edge = this.getSharingEdge(current_face, nav_mesh_path[0])
              , right        = vec3.clone(sharing_edge.begin.pos)
              , left         = vec3.clone(sharing_edge.end.pos)
              , right_dir    = vec3.create()
              , left_dir     = vec3.create();

            vec3.subtract(right_dir, right, this._current_pos);
            vec3.subtract(left_dir, left, this._current_pos);

            if (reset === true) {
                best_left      = left;
                best_right     = right;
                best_left_dir  = left_dir;
                best_right_dir = right_dir;
                reset          = false;
                continue;
            }

            // The new corners are acceptable if the corridor gets narrower
            // or stays the same. In order to choose the correct corner
            // later (in case 3) we need to keep track which was updated.
            //FIXME: the narrowing should only be done if we hit a wall!
            var right_changed = false
              , left_changed  = false;

            if (this._isLeftEq(best_right_dir, right_dir)) {
                right_changed  = !vec3equal(best_right, right);
                best_right     = right;
                best_right_dir = right_dir;
            }

            if (this._isRightEq(best_left_dir, left_dir)) {
                left_changed  = !vec3equal(best_left, left);
                best_left     = left;
                best_left_dir = left_dir;
            }

            // Case 1: the new right direction is right of the best right
            // direction. This means the right corner blocks our view to
            // the next nav mesh face on the path.
            if (this._isRight(best_right_dir, right_dir)) {
                reset = true;
                this._current_pos = toNavmeshCoordinates(this.terrain, best_right);
                corner_path.push(this._current_pos);
            } else if (this._isLeft(best_left_dir, left_dir)) {
                // Case 2: same as case 1 for left direction.
                reset = true;
                this._current_pos = toNavmeshCoordinates(this.terrain, best_left);
                corner_path.push(this._current_pos);
            } else if (this._isRightEq(best_right_dir, best_left_dir)) {
                // Case 3: the best left direction is now right of the
                // best right direction (same as best left is left of best
                // right). To find the proper corner blocking the line of
                // sight we need to know which corner was updated in this
                // step.
                reset = true;

                var pos;
                if (right_changed) {
                    pos = toNavmeshCoordinates(this.terrain, best_left);
                } else {
                    pos = toNavmeshCoordinates(this.terrain, best_right);
                }

                this._current_pos = pos;
                corner_path.push(this._current_pos);
            }
        }

        // handle last nav face mesh (can be around the corner)
        if (!reset) {
            var target_dir = vec3.create();
            vec3.subtract(target_dir,
                    getWorldCoordinates(this.terrain, this.target_pos),
                    this._current_pos);
            if (this._isLeft(best_left_dir, target_dir)) {
                pos = toNavmeshCoordinates(this.terrain, best_left);
                corner_path.push(pos);
//.........這裏部分代碼省略.........
開發者ID:rmx,項目名稱:encounter,代碼行數:101,代碼來源:PathFinder.ts


注:本文中的gl-matrix.vec3.subtract方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。