How to use the gl-matrix.vec3.add 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 yoo2001818 / kkiro3d / src / system / blenderController.js View on Github external
setPosition(entity) {
    if (entity.blenderController == null) return;
    if (entity.transform == null) return;
    // Update camera position
    vec3.transformQuat(vecTemp, [0, 0, entity.blenderController.radius],
      entity.transform.rotation);
    vec3.add(vecTemp, vecTemp, entity.blenderController.center);
    this.engine.actions.transform.setPosition(entity, vecTemp);
  }
}
github yoo2001818 / webglue / src / contrib / blenderController.js View on Github external
if (!this.mouseHeld) return;
      let offsetX = e.clientX - this.mouseX;
      let offsetY = e.clientY - this.mouseY;
      this.mouseX = e.clientX;
      this.mouseY = e.clientY;
      let transform = this.camera.transform;
      if (e.shiftKey) {
        // Do translation instead - we'd need two vectors to make translation
        // relative to the camera rotation
        let vecX = vec3.create();
        let vecY = vec3.create();
        vec3.transformQuat(vecX, [-offsetX * this.radius / 600, 0, 0],
          transform.rotation);
        vec3.transformQuat(vecY, [0, offsetY * this.radius / 600, 0],
          transform.rotation);
        vec3.add(this.center, this.center, vecX);
        vec3.add(this.center, this.center, vecY);
        this.hasChanged = true;
        return;
      }
      // rotation....
      let rot = quat.create();
      quat.rotateY(rot, rot, Math.PI / 180 * -offsetX *
        this.rotateDir / 4);
      quat.multiply(transform.rotation, rot, transform.rotation);
      quat.rotateX(transform.rotation, transform.rotation,
        Math.PI / 180 * -offsetY / 4);
      this.hasChanged = true;
    });
    this.node.addEventListener('contextmenu', e => {
github Kitware / paraviewweb / src / Rendering / Image / DepthCompositeImageBuilder / sxyz-light-compositor.js View on Github external
vec3.normalize(right, right);
  vec3.subtract(t0, right, viewDir);
  vec3.subtract(t1, at, viewDir);
  const up = vec3.create();
  vec3.cross(up, t0, t1);
  vec3.normalize(up, up);
  // scale down so we can alway have room before normalization
  const rm = vec3.create();
  vec3.scale(rm, right, relativeLightPosition.x);
  const um = vec3.create();
  vec3.scale(um, up, relativeLightPosition.y);
  const scaledView = vec3.create();
  vec3.scale(scaledView, viewDir, 0.3);
  const lightDirection = vec3.create();
  vec3.add(lightDirection, scaledView, rm);
  vec3.add(lightDirection, lightDirection, um);
  vec3.normalize(lightDirection, lightDirection);
  return {
    lightDir: lightDirection,
    viewDir,
  };
}
github stephomi / sculptgl / src / editing / Gizmo.js View on Github external
_computeCenterGizmo(center = [0.0, 0.0, 0.0]) {
    var meshes = this._main.getSelectedMeshes();

    var acc = [0.0, 0.0, 0.0];
    var icenter = [0.0, 0.0, 0.0];
    for (var i = 0; i < meshes.length; ++i) {
      var mesh = meshes[i];
      vec3.transformMat4(icenter, mesh.getCenter(), mesh.getEditMatrix());
      vec3.transformMat4(icenter, icenter, mesh.getMatrix());
      vec3.add(acc, acc, icenter);
    }
    vec3.scale(center, acc, 1.0 / meshes.length);
    return center;
  }
github Danielhu229 / CanvasToy / src / lights / DirectionalLight.ts View on Github external
public setDirection(_direction: vec3) {
        const lookPoint = vec3.add(vec3.create(), this._position, _direction);
        this.lookAt(lookPoint);
        return this;
    }
github 4eb0da / war3-model / renderer / modelRenderer.ts View on Github external
private generateGeosetVertices (geosetIndex: number): void {
        let geoset: Geoset = this.model.Geosets[geosetIndex];
        let buffer = this.vertices[geosetIndex];

        for (let i = 0; i < buffer.length; i += 3) {
            let index = i / 3;
            let group = geoset.Groups[geoset.VertexGroup[index]];

            vec3.set(tempPos, geoset.Vertices[i], geoset.Vertices[i + 1], geoset.Vertices[i + 2]);
            vec3.set(tempSum, 0, 0, 0);
            for (let j = 0; j < group.length; ++j) {
                vec3.add(
                    tempSum, tempSum,
                    vec3.transformMat4(tempVec3, tempPos, this.rendererData.nodes[group[j]].matrix)
                );
            }
            vec3.scale(tempPos, tempSum, 1 / group.length);
            buffer[i]     = tempPos[0];
            buffer[i + 1] = tempPos[1];
            buffer[i + 2] = tempPos[2];
        }
        gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer[geosetIndex]);
        gl.bufferData(gl.ARRAY_BUFFER, buffer, gl.DYNAMIC_DRAW);
    }
github Whatever-Inc / KAMRA-Deja-Vu / experiments / 19 - Particle to Face / src / deformable-face-geometry.js View on Github external
let displacement = featurePoints.map((p, i) => {
      let fp = this.standardFace.getFeatureVertex(i)
      return vec3.sub([], p, fp)
    })

    let position = this.positionAttribute.array
    let n = position.length / 3
    for (let i = 0; i < n; i++) {
      let p = vec3.create()
      let b = 0
      this.standardFace.data.face.weight[i].forEach((w) => {
        vec3.add(p, p, vec3.scale(vec3.create(), displacement[w[0]], w[1]))
        b += w[1]
      })
      vec3.scale(p, p, 1 / b)
      vec3.add(p, p, this.standardFace.getVertex(i))

      position[i * 3 + 0] = p[0]
      position[i * 3 + 1] = p[1]
      position[i * 3 + 2] = p[2]
    }
    this.positionAttribute.needsUpdate = true
  }
github magcius / noclip.website / src / SuperMarioGalaxy / RailRider.ts View on Github external
const speed = totalLength / nPoints;
        const ctx = getDebugOverlayCanvas2D();
        let lastPartIdx = -1;

        for (let i = 0; i < nPoints; i++) {
            const coord = i * speed;

            const partIdx = this.bezierRail.getIncludedSectionIdx(coord, 1);
            this.bezierRail.calcPos(scratchVec3c, coord);
            drawWorldSpacePoint(ctx, camera, scratchVec3c, partIdx !== lastPartIdx ? Cyan : Magenta, 10);

            lastPartIdx = partIdx;

            this.bezierRail.calcDirection(scratchVec3b, coord);
            vec3.scale(scratchVec3b, scratchVec3b, 100);
            vec3.add(scratchVec3b, scratchVec3b, scratchVec3c);
            drawWorldSpaceLine(ctx, camera, scratchVec3c, scratchVec3b, Yellow);

            /*
            const partIdx = this.bezierRail.getIncludedSectionIdx(coord, 1);
            const part = this.bezierRail.railParts[partIdx];
            const param = part.getParam(this.bezierRail.getCoordForRailPartIdx(partIdx, coord));
            drawWorldSpaceText(ctx, camera, scratchVec3a, param.toFixed(2), Yellow);
            */
        }
    }
}
github cruise-automation / webviz / packages / regl-worldview / src / stories / cameraState.stories.js View on Github external
},
      scale: { x: 20, y: 3, z: 3 },
      color: { r: 1, g: 0, b: 1, a: 1 },
    };

    const arrowLength = 10;
    const cameraPosition = cameraState.perspective
      ? vec3.copy(
          [0, 0, 0],
          cameraStateSelectors.position({
            ...cameraState,
            distance: cameraState.distance + arrowLength,
          })
        )
      : [0, 0, cameraState.distance + arrowLength];
    vec3.add(cameraPosition, cameraPosition, cameraState.targetOffset);
    vec3.rotateZ(cameraPosition, cameraPosition, [0, 0, 0], -targetHeading);
    vec3.add(cameraPosition, cameraPosition, cameraState.target);

    const cameraOrientation = [0, 0, 0, 1];
    quat.rotateZ(cameraOrientation, cameraOrientation, -targetHeading);
    quat.multiply(cameraOrientation, cameraOrientation, cameraStateSelectors.orientation(cameraState));
    quat.rotateY(cameraOrientation, cameraOrientation, Math.PI / 2);

    const cameraArrowMarker = {
      pose: {
        position: vec3ToPoint(cameraPosition),
        orientation: vec4ToOrientation(cameraOrientation),
      },
      scale: { x: arrowLength, y: 2, z: 2 },
      color: { r: 0, g: 1, b: 1, a: 0.5 },
    };
github flowtsohg / mdx-m3-viewer / src / viewer / camera.js View on Github external
move(offset) {
    vec3.add(this.location, this.location, offset);

    this.dirty = true;
  }