當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。