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


TypeScript vec3.dot方法代码示例

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


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

示例3:

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