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


TypeScript vec3.cross方法代码示例

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


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

示例1: 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

示例2: 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

示例3:

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);
outVal = vec3.length(vec3A);
outVal = vec3.len(vec3A);
outVal = vec3.squaredLength(vec3A);
outVal = vec3.sqrLen(vec3A);
outVec3 = vec3.negate(outVec3, vec3A);
outVec3 = vec3.inverse(outVec3, vec3A);
outVec3 = vec3.normalize(outVec3, vec3A);
outVal = vec3.dot(vec3A, vec3B);
outVec3 = vec3.cross(outVec3, vec3A, vec3B);
outVec3 = vec3.lerp(outVec3, vec3A, vec3B, 0.5);
outVec3 = vec3.hermite(outVec3, vec3A, vec3B, vec3A, vec3B, 0.5);
outVec3 = vec3.bezier(outVec3, vec3A, vec3B, vec3A, vec3B, 0.5);
outVec3 = vec3.random(outVec3);
outVec3 = vec3.random(outVec3, 5.0);
outVec3 = vec3.transformMat3(outVec3, vec3A, mat3A);
outVec3 = vec3.transformMat4(outVec3, vec3A, mat4A);
outVec3 = vec3.transformQuat(outVec3, vec3A, quatA);
outVec3 = vec3.rotateX(outVec3, vec3A, vec3B, Math.PI);
outVec3 = vec3.rotateY(outVec3, vec3A, vec3B, Math.PI);
outVec3 = vec3.rotateZ(outVec3, vec3A, vec3B, Math.PI);
vecArray = vec3.forEach(vecArray, 0, 0, 0, vec3.normalize);
outVal = vec3.angle(vec3A, vec3B);
outStr = vec3.str(vec3A);
outBool = vec3.exactEquals(vec3A, vec3B);
开发者ID:DenisCarriere,项目名称:DefinitelyTyped,代码行数:31,代码来源:gl-matrix-tests.ts

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