本文整理匯總了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;
}
示例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]);
}
示例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);
示例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;
}