How to use the gl-matrix.vec2.create function in gl-matrix

To help you get started, we’ve selected a few gl-matrix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github magcius / noclip.website / src / nns_g3d / nsbta.ts View on Github external
idx1 = idx1 % frames.length;
    
    const k0 = frames[idx0];
    const k1 = frames[idx1];

    const t = (frame - k0.frame) / (k1.frame - k0.frame);
    return lerp(k0.value, k1.value, t);
}

function rotationFromValue(dst: vec2, v: number): void {
    dst[0] = v & 0xFFFF;
    dst[1] = (v >>> 16) & 0xFFFF;
}

const scratchK0 = vec2.create();
const scratchK1 = vec2.create();
function sampleRotAnimationTrack(dst: vec2, track: AnimationTrack, frame: number) {
    const frames = track.frames;

    if (frames.length === 1)
        return rotationFromValue(dst, frames[0].value);

    // Find the right-hand frame.
    let idx1 = 0;
    for (; idx1 < frames.length; idx1++) {
        if (frame < frames[idx1].frame)
            break;
    }

    if (idx1 === 0)
        return rotationFromValue(dst, frames[0].value);
github Whatever-Inc / KAMRA-Deja-Vu / experiments / 04 - Face Deformation / src / main.js View on Github external
let q = vec2.transformMat3(vec2.create(), p, mtx);
        fpuv.push([q[0] / 128 - 1, q[1] / 128 - 1]);
      });

      {
        this.textureContext.fillStyle = 'red';
        let v1 = this.tracker.currentPosition[14];
        let v0 = this.tracker.currentPosition[0];
        let center = vec2.lerp(vec2.create(), v1, v0, 0.5);
        let xAxis = vec2.sub(vec2.create(), v1, center);
        let scale = vec2.len(xAxis);
        let rotation = mat3.create();
        mat3.rotate(rotation, rotation, Math.atan2(xAxis[1], xAxis[0]));
        for (let i = 71; i < this.featurePoints.length; i++) {
          let fp = this.featurePoints[i].initialPosition;
          let p = vec2.scale(vec2.create(), [fp.x, -fp.y], scale);
          vec2.transformMat3(p, p, rotation);
          vec2.add(p, p, center);
          vec2.transformMat3(p, p, mtx);
          // this.textureContext.fillRect(p[0] - 3, p[1] - 3, 6, 6);
          fpuv.push([p[0] / 128 - 1, p[1] / 128 - 1]);
        }
      }

      this.textureContext.fillStyle = 'rgba(0, 0, 255, 0.5)';

      let displacement = this.featurePoints.map((mesh, i) => {
        if (!mesh) return;
        let node = this.nodes[mesh.vertexIndex];
        return [fpuv[i][0] - node.position.x, -fpuv[i][1] - node.position.y];
      });
github 2d-inc / Flare-JS / source / ActorBasePath.js View on Github external
else
						{
							//let previous = renderPoints[(i-1+pointLength)%pointLength];
							let next = points[(i + 1) % pl];
							//previous = points[i-1];
							previous = previous.pointType === PointType.Straight ? previous.translation : previous.out;
							next = next.pointType === PointType.Straight ? next.translation : next.in;

							let pos = point.translation;

							let toPrev = vec2.subtract(vec2.create(), previous, pos);
							let toPrevLength = vec2.length(toPrev);
							toPrev[0] /= toPrevLength;
							toPrev[1] /= toPrevLength;

							let toNext = vec2.subtract(vec2.create(), next, pos);
							let toNextLength = vec2.length(toNext);
							toNext[0] /= toNextLength;
							toNext[1] /= toNextLength;

							let renderRadius = Math.min(toPrevLength, Math.min(toNextLength, radius));

							let translation = vec2.scaleAndAdd(vec2.create(), pos, toPrev, renderRadius);
							let current = {
								e: true, // Mark this is an ephemeral point
								o: point.o || point,
								n: previous,
								pointType: PointType.Disconnected,
								translation: translation,
								out: vec2.scaleAndAdd(vec2.create(), pos, toPrev, InverseCircleConstant * renderRadius),
								in: translation //vec2.scaleAndAdd(vec2.create(), translation, toPrev, arcConstant*renderRadius)
							};
github 2d-inc / Nima-WebGL / source / JellyComponent.js View on Github external
console.warn("Failed to invert transform space", bone.worldTransform);
			return;
		}
		
		if(this._InTarget)
		{
			let translation = this._InTarget.worldTranslation;
			vec2.transformMat2d(this._InPoint, translation, inverseWorld);
			vec2.normalize(this._InDirection, this._InPoint);
		}
		else if(parentBone)
		{
			if(parentBone._FirstBone === bone && parentBoneJelly && parentBoneJelly._OutTarget)
			{
				let translation = parentBoneJelly._OutTarget.worldTranslation;
				let localParentOut = vec2.transformMat2d(vec2.create(), translation, inverseWorld);
				vec2.normalize(localParentOut, localParentOut);
				vec2.negate(this._InDirection, localParentOut);
			}
			else
			{
				let d1 = vec2.set(vec2.create(), 1, 0);
				let d2 = vec2.set(vec2.create(), 1, 0);

				vec2.transformMat2(d1, d1, parentBone.worldTransform);
				vec2.transformMat2(d2, d2, bone.worldTransform);

				let sum = vec2.add(vec2.create(), d1, d2);
				let localIn = vec2.transformMat2(this._InDirection, sum, inverseWorld);
				vec2.normalize(localIn, localIn);
			}
			vec2.scale(this._InPoint, this._InDirection, this._EaseIn*bone._Length*CurveConstant);
github ggfolks / platform / src / input / input.ts View on Github external
  constructor (readonly position :vec2 = vec2.create(),
               readonly movement :vec2 = vec2.create(),
               readonly pressed :boolean = false) {}
}
github expo / expo-pixi / lib / core / signature / Perpendicular.js View on Github external
export function lineCreate() {
  return [vec2.create(), vec2.create()];
}
github expo / expo-pixi / lib / core / signature / Perpendicular.js View on Github external
export function linesPerpendicularToLine(pointA, pointB) {
  const lineVec = vec2.subtract(vec2.create(), pointB.point, pointA.point);

  return {
    first: linePerpendicularToLine(lineCreate(), lineVec, pointA.point, pointA.weight),
    second: linePerpendicularToLine(lineCreate(), lineVec, pointB.point, pointB.weight),
  };
}
github magcius / noclip.website / src / nns_g3d / nsbta.ts View on Github external
return rotationFromValue(dst, frames[0].value);

    const idx0 = idx1 - 1;
    idx1 = idx1 % frames.length;

    const k0 = frames[idx0];
    const k1 = frames[idx1];

    const t = (frame - idx0) / (k1.frame - k0.frame);
    rotationFromValue(scratchK0, k0.value);
    rotationFromValue(scratchK1, k1.value);
    dst[0] = lerp(scratchK0[0], scratchK1[0], t);
    dst[1] = lerp(scratchK0[1], scratchK1[1], t);
}

const scratchVec2 = vec2.create();
export class SRT0TexMtxAnimator {
    constructor(public animationController: AnimationController, public srt0: SRT0, public texData: SRT0_TexData) {
    }

    public calcTexMtx(dst: mat2d, texMtxMode: TexMtxMode, texScaleS: number, texScaleT: number, loopMode = LoopMode.REPEAT): void {
        const texData = this.texData;

        const frame = this.animationController.getTimeInFrames();
        const animFrame = getAnimFrame(this.srt0, frame, loopMode);

        const scaleS = sampleFloatAnimationTrack(texData.scaleS, animFrame);
        const scaleT = sampleFloatAnimationTrack(texData.scaleT, animFrame);
        sampleRotAnimationTrack(scratchVec2, texData.rot, animFrame);
        const translationS = sampleFloatAnimationTrack(texData.transS, animFrame);
        const translationT = sampleFloatAnimationTrack(texData.transT, animFrame);
        calcTexMtx(dst, texMtxMode, texScaleS, texScaleT, scaleS, scaleT, scratchVec2[0], scratchVec2[1], translationS, translationT);
github 2d-inc / Flare-JS / source / JellyComponent.js View on Github external
constructor()
	{
		super();

		this._EaseIn = 0.0;
		this._EaseOut = 0.0;
		this._ScaleIn = 0.0;
		this._ScaleOut = 0.0;
		this._InTargetIdx = 0;
		this._OutTargetIdx = 0;
		this._InTarget = null;
		this._OutTarget = null;

		this._Bones = [];
		this._InPoint = vec2.create();
		this._InDirection = vec2.create();
		this._OutPoint = vec2.create();
		this._OutDirection = vec2.create();
	}