本文整理匯總了TypeScript中gl-matrix.vec3.create方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript vec3.create方法的具體用法?TypeScript vec3.create怎麽用?TypeScript vec3.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gl-matrix.vec3
的用法示例。
在下文中一共展示了vec3.create方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: moveAlong
moveAlong(elapsedTime: number, speed: number): Vec3 {
// If there is no further waypoint, we've arrived at the end and we
// always return the current position.
if (this.done) {
return vec3.clone(this.currentPosition);
}
// The vector from the current position to the next waypoint.
var vector = vec3.subtract(vec3.create(), this.waypoints[0], this.currentPosition)
, vectorLength = vec3.length(vector)
, distanceMoved = speed * elapsedTime;
if (vectorLength < distanceMoved) {
// The remaining distance in the current segment is less than what
// we moved, jump to the next waypoint and move along the next path
// segment from there.
vec3.copy(this.currentPosition, this.waypoints.shift());
this.currentHeading = normalizeHeading(Math.atan2(vector[1], vector[0]));
return this.moveAlong(elapsedTime - vectorLength / speed, speed);
}
// We have not yet reached the next waypoint. Move along the vector
// towards it and update the heading.
vec3.add(this.currentPosition, this.currentPosition, vec3.scale(vec3.create(), vec3.normalize(vec3.create(), vector), distanceMoved));
this.currentHeading = normalizeHeading(Math.atan2(vector[1], vector[0]));
return vec3.clone(this.currentPosition);
}
示例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;
}
示例3: 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);
}
示例4: angleAxis
/**
* Calculate the rotation quaternion represented as pair of angle and axis.
*/
public static angleAxis(angle: number, axis: Vector3): Quaternion {
const axisVec = vec3.create();
axisVec[0] = axis.X;
axisVec[1] = axis.Y;
axisVec[2] = axis.Z;
const newQuat = quat.create();
return new Quaternion(quat.setAxisAngle(newQuat, axisVec, +angle));
}
示例5: constructor
constructor(
readonly type: BoneType,
readonly basis: Triple<vec3>,
readonly prevJoint: vec3,
readonly nextJoint: vec3,
readonly width: number
) {
const difference = vec3.subtract(vec3.create(), this.nextJoint, this.prevJoint);
this.length = vec3.length(difference);
this.basisMatrix = mat3.fromValues(
this.basis[0][0], this.basis[0][1], this.basis[0][2],
this.basis[1][0], this.basis[1][1], this.basis[1][2],
this.basis[2][0], this.basis[2][1], this.basis[2][2]
);
this.left = mat3.determinant(this.basisMatrix) < 0;
this.center = vec3.lerp(vec3.create(), this.prevJoint, this.nextJoint, 0.5);
this.direction = Bone.createBoneDirection(this.basisMatrix);
this.matrix = Bone.createBoneMatrix(this.basisMatrix, this.center, this.left);
}
示例6: constructor
constructor() {
this.children = [];
this.localMatrix = mat4.create();
this.modelMatrix = mat4.create();
this.modelViewMatrix = mat4.create();
this.matrixAutoUpdate = true;
this.position = new Vector3();
this.rotation = new Vector3();
this.scale = new Vector3(1, 1, 1);
this.isObject3D = true;
this.quaternion = quat.create();
this.quaternionLookAt = quat.create();
this.lookAtUp = vec3.create(); // needs to be [0, 0, 0] although it should be [0, 1, 0]
}
示例7: needRecomputeMovePath
private needRecomputeMovePath(): boolean {
var terrain = lookupEntity<Terrain>(this.state, this.target.terrainId)
, tpos = getWorldCoordinates(terrain, this.target.terrainPosition)
, fpos = finalPosition(this.owner)
, distance = Math.abs(vec3.length(vec3.subtract(vec3.create(), tpos, fpos)))
, diff = distance - (this.distance + this.target.boundingRadius);
return 0.1 < diff;
function finalPosition(entity: WorldObject): Vec3 {
if (entity.movePath) {
return entity.movePath.finalPosition;
} else {
return getWorldCoordinates(terrain, entity.terrainPosition);
}
}
}
示例8:
let vec3B = vec3.fromValues(3, 4, 5);
let vec4A = vec4.fromValues(1, 2, 3, 4);
let vec4B = vec4.fromValues(3, 4, 5, 6);
let mat2A = mat2.fromValues(1, 2, 3, 4);
let mat2B = mat2.fromValues(1, 2, 3, 4);
let mat2dA = mat2d.fromValues(1, 2, 3, 4, 5, 6);
let mat2dB = mat2d.fromValues(1, 2, 3, 4, 5, 6);
let mat3A = mat3.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
let mat3B = mat3.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
let mat4A = mat4.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
let mat4B = mat4.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
let quatA = quat.fromValues(1, 2, 3, 4);
let quatB = quat.fromValues(5, 6, 7, 8);
let outVec2 = vec2.create();
let outVec3 = vec3.create();
let outVec4 = vec4.create();
let outMat2 = mat2.create();
let outMat2d = mat2d.create();
let outMat3 = mat3.create();
let outMat4 = mat4.create();
let outQuat = quat.create();
let outMat2Null: mat2 | null;
let outMat2dNull: mat2d | null;
let outMat3Null: mat3 | null;
let outMat4Null: mat4 | null;
// vec2
outVec2 = vec2.create();
outVec2 = vec2.clone(vec2A);
示例9: diagonal
diagonal(): Vec3 {
return vec3.subtract(vec3.create(), this.max, this.min);
}
示例10: updateFaceNormal
import { vec3 } from 'gl-matrix';
import Vector3 from '../math/Vector3';
const cb = vec3.create();
const ab = vec3.create();
export default class Face {
public indices: number[];
public vertices: Vector3[];
public uvs: number[];
public normal: Vector3;
constructor(
indiceA: number,
indiceB: number,
indiceC: number,
vertexA: Vector3,
vertexB: Vector3,
vertexC: Vector3
) {
this.indices = [indiceA, indiceB, indiceC];
this.vertices = [vertexA, vertexB, vertexC];
this.uvs = [indiceA, indiceB, indiceC];
this.normal = new Vector3();
this.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);