本文整理汇总了TypeScript中gl-matrix.vec2类的典型用法代码示例。如果您正苦于以下问题:TypeScript vec2类的具体用法?TypeScript vec2怎么用?TypeScript vec2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了vec2类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: tileToViewport
/**
* viewportPos = viewportFromSquare * squareFromMap * mapFromTile * tilePos
* viewportPos = (viewportFromClip * verticalFlip * clipFromSquare) * squareFromMap * (verticalFlip * mapFromTile) * tilePos
*/
tileToViewport(...pos : number[]) : PosXY{
let vec = pos as any as vec2;
vec2.transformMat2d(vec, vec, this.mapFromTileMatrix);
vec2.transformMat2d(vec, vec, this.squareFromMapMatrix);
vec2.transformMat2d(vec, vec, this.viewportFromSquareMatrix);
return vec as any as PosXY;
}
示例2: viewportToTile
/**
* tilePos = mapToTile * squareToMap * viewportToSquare * viewportPos
* tilePos = (mapToTile * verticalFlip) * squareToMap * (clipToSquare * verticalFlip * viewportToClip) * viewportPos
*/
viewportToTile(...pos : number[]) : PosXY{
let vec = pos as any as vec2;
vec2.transformMat2d(vec, vec, this.viewportToSquareMatrix);
vec2.transformMat2d(vec, vec, this.squareToMapMatrix);
vec2.transformMat2d(vec, vec, this.mapToTileMatrix);
return vec as any as PosXY;
}
示例3: reset
/** Resets to fit tiles in viewport */
reset({top, left, bottom, right} : Box){
const topLeft = [left, top] as PosXY;
const bottomRight = [right, bottom] as PosXY;
vec2.transformMat2d(topLeft as any, topLeft, this.mapFromTileMatrix);
vec2.transformMat2d(bottomRight as any, bottomRight, this.mapFromTileMatrix);
this.transformMapToSquare(
[topLeft, [-1,1]],
[bottomRight, [ 1,-1]]
);
}
示例4: constructor
constructor(gl : WebGLRenderingContext, image : HTMLImageElement){
super(gl, 0);
this.width = image.width;
this.height = image.height;
this.image = image;
vec2.set(this.size, image.width, image.height);
vec2.set(this.halfSize, image.width/2, image.height/2);
vec2.set(this.inverseSize, 1/image.width, 1/image.height);
this.update();
}
示例5: constructor
constructor(gl : WebGLRenderingContext, width=0, height=width){
this.gl = gl;
this.texture = gl.createTexture() || (() => {throw new Error("Could not make texture")})();
this.width = width;
this.height = height;
this.size = vec2.fromValues(width, height);
this.halfSize = vec2.fromValues(width/2, height/2);
this.inverseSize = vec2.fromValues(1/width, 1/height);
this.bind();
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
}
示例6: intersectObject
public intersectObject(object: Mesh) {
if (!object.visible) return;
let intersect;
let uv;
let face;
// Check sphere
if (object.boundingSphere === undefined) object.computeBoundingSphere();
sphere.copy(object.boundingSphere);
// Apply object modelMatrix, incase object has been transformed
sphere.applyMatrix(object.modelMatrix);
// Exit if the ray doesn't intersect the sphere
if (!this.ray.intersectsSphere(sphere)) {
return;
}
for (const f of object.geometry.faces) {
vec3.copy(fvA.v, f.vertices[0].v);
vec3.copy(fvB.v, f.vertices[1].v);
vec3.copy(fvC.v, f.vertices[2].v);
// Multiply vertices by object matrix
vec3.transformMat4(fvA.v, fvA.v, object.modelMatrix);
vec3.transformMat4(fvB.v, fvB.v, object.modelMatrix);
vec3.transformMat4(fvC.v, fvC.v, object.modelMatrix);
intersect = this.ray.intersectTriangle(fvA, fvB, fvC);
if (intersect) {
// Get uv intersection
vec2.copy(uvA.v, object.geometry.uvs[f.uvs[0]].v);
vec2.copy(uvB.v, object.geometry.uvs[f.uvs[1]].v);
vec2.copy(uvC.v, object.geometry.uvs[f.uvs[2]].v);
face = f;
uv = this.uvIntersection(intersect, fvA, fvB, fvC);
break;
}
}
return intersect ? { point: intersect, uv, face } : null;
}
示例7: distance
public distance(vector2: Vector2) {
return vec2.distance(this.v, vector2.v);
}
示例8: constructor
constructor(x = 0, y = 0) {
this.v = vec2.create();
this.set(x, y);
return this;
}
示例9: scale
public scale(value: number) {
vec2.scale(this.v, this.v, value);
return this;
}
示例10: subtractVectors
public subtractVectors(vector0: Vector2, vector1: Vector2) {
const out = vec2.create();
vec2.subtract(out, vector0.v, vector1.v);
return out;
}