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


TypeScript vec3.sub方法代码示例

本文整理汇总了TypeScript中gl-matrix.vec3.sub方法的典型用法代码示例。如果您正苦于以下问题:TypeScript vec3.sub方法的具体用法?TypeScript vec3.sub怎么用?TypeScript vec3.sub使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gl-matrix.vec3的用法示例。


在下文中一共展示了vec3.sub方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: barycoordFromPoint

export function barycoordFromPoint(point: vec3, a: vec3, b: vec3, c: vec3) {
  const v0 = vec3.create();
  const v1 = vec3.create();
  const v2 = vec3.create();

  vec3.sub(v0, c, a);
  vec3.sub(v1, b, a);
  vec3.sub(v2, point, a);

  const dot00 = vec3.dot(v0, v0);
  const dot01 = vec3.dot(v0, v1);
  const dot02 = vec3.dot(v0, v2);
  const dot11 = vec3.dot(v1, v1);
  const dot12 = vec3.dot(v1, v2);

  const denom = dot00 * dot11 - dot01 * dot01;

  const result = new Vector3();

  // collinear or singular triangle
  if (denom === 0) {
    // arbitrary location outside of triangle?
    // not sure if this is the best idea, maybe should be returning undefined
    return result.set(-2, -1, -1);
  }

  const invDenom = 1 / denom;
  const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  const v = (dot00 * dot12 - dot01 * dot02) * invDenom;

  // barycentric coordinates must always sum to 1
  return result.set(1 - u - v, v, u);
}
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:33,代码来源:Utils.ts

示例2: lookAt

export function lookAt(eye: vec3, target: vec3, up: vec3) {
  const quatOut = quat.create();
  const x = vec3.create();
  const y = vec3.create();
  const z = vec3.create();

  vec3.sub(z, eye, target);

  if (vec3.squaredLength(z) === 0) {
    // eye and target are in the same position
    z[2] = 1;
  }

  vec3.normalize(z, z);
  vec3.cross(x, up, z);

  if (vec3.squaredLength(x) === 0) {
    // eye and target are in the same vertical
    z[2] += 0.0001;
    vec3.cross(x, up, z);
  }

  vec3.normalize(x, x);
  vec3.cross(y, z, x);

  quat.setAxes(quatOut, z, x, y);
  quat.invert(quatOut, quatOut);

  return quatOut;
}
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:30,代码来源:Utils.ts

示例3: setFromCamera

  public setFromCamera(
    coords: Vector2,
    scene: Scene,
    camera: PerspectiveCamera,
    object: Mesh
  ) {
    if (camera && camera.isPespectiveCamera) {
      this.ray.origin.copy(camera.position);

      vec3.copy(cameraDirection, [coords.x, coords.y, 0.5]);

      mat4.multiply(
        inversedProjectionViewMatrix,
        camera.projectionMatrix,
        camera.worldInverseMatrix
      );
      mat4.invert(inversedProjectionViewMatrix, inversedProjectionViewMatrix);

      vec3.transformMat4(
        cameraDirection,
        cameraDirection,
        inversedProjectionViewMatrix
      );

      vec3.sub(cameraDirection, cameraDirection, camera.position.v);
      vec3.normalize(cameraDirection, cameraDirection);

      directionVector.set(
        cameraDirection[0],
        cameraDirection[1],
        cameraDirection[2]
      );

      this.ray.direction.copy(directionVector);
    }
  }
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:36,代码来源:Raycaster.ts

示例4:

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);
outVal = vec3.sqrDist(vec3A, vec3B);
开发者ID:DenisCarriere,项目名称:DefinitelyTyped,代码行数:31,代码来源:gl-matrix-tests.ts

示例5: intersectTriangle

  public intersectTriangle(a: Vector3, b: Vector3, c: Vector3, culling = true) {
    vec3.sub(edge1, b.v, a.v);
    vec3.sub(edge2, c.v, a.v);
    vec3.cross(normal, edge1, edge2);

    // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
    // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
    //   |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
    //   |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
    //   |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)

    // console.log('normal', normal);
    let DdN = vec3.dot(this.direction.v, normal);
    let sign;

    // console.log('normal', normal);

    if (DdN > 0) {
      if (culling) return null;
      sign = 1;
    } else if (DdN < 0) {
      sign = -1;
      DdN = -DdN;
    } else {
      return null;
    }

    vec3.sub(diff, this.origin.v, a.v);
    vec3.cross(edge2, diff, edge2);
    const DdQxE2 = sign * vec3.dot(this.direction.v, edge2);

    // b1 < 0, no intersection
    if (DdQxE2 < 0) {
      return null;
    }

    vec3.cross(edge1, edge1, diff);
    const DdE1xQ = sign * vec3.dot(this.direction.v, edge1);

    // b2 < 0, no intersection
    if (DdE1xQ < 0) {
      return null;
    }

    // b1+b2 > 1, no intersection
    if (DdQxE2 + DdE1xQ > DdN) {
      return null;
    }

    // Line intersects triangle, check if ray does.
    const QdN = -sign * vec3.dot(diff, normal);

    // t < 0, no intersection
    if (QdN < 0) {
      return null;
    }

    const result = new Vector3();
    result
      .copy(this.direction)
      .scale(QdN / DdN)
      .add(this.origin);

    return result;
  }
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:65,代码来源:Ray.ts


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