How to use the gl-matrix.quat.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 MozillaReality / WebXR-emulator-extension / src / polyfill / EmulatedXRDevice.js View on Github external
constructor(global, config={}) {
    super(global);

    this.sessions = new Map();

    this.modes = config.modes || DEFAULT_MODES;

    // headset
    this.position = vec3.copy(vec3.create(), DEFAULT_HEADSET_POSITION);
    this.quaternion = quat.create();
    this.scale = vec3.fromValues(1, 1, 1);
    this.matrix = mat4.create();
    this.projectionMatrix = mat4.create();
    this.leftProjectionMatrix = mat4.create();
    this.rightProjectionMatrix = mat4.create();
    this.viewMatrix = mat4.create();
    this.leftViewMatrix = mat4.create();
    this.rightViewMatrix = mat4.create();

    // controllers
    this.gamepads = [];
    this.gamepadInputSources = [];
    this._initializeControllers(config);

    // other configurations
    this.stereoEffectEnabled = config.stereoEffect !== undefined ? config.stereoEffect : true;
github dmnsgn / frenet-serret-frames / index.js View on Github external
vec3.cross(normal, tangent, v);
    vec3.normalize(normal, normal);
  }

  let binormal = vec3.cross(vec3.create(), tangent, normal);
  vec3.normalize(binormal, binormal);

  frames.push({
    position: [...points[0]],
    normal: vec3.clone(normal),
    binormal: vec3.clone(binormal),
    tangent: vec3.clone(tangent)
  });

  // Compute the rest of the frames
  const rotation = quat.create();
  let previousTangent;

  for (let i = 1; i < points.length; i++) {
    const position = points[i];
    previousTangent = tangents[i - 1];
    tangent = tangents[i];
    normal = vec3.clone(normal);
    binormal = vec3.clone(binormal);

    vec3.cross(v, previousTangent, tangent);

    if (vec3.length(v) > Number.EPSILON) {
      vec3.normalize(v, v);

      let theta = Math.acos(clamp(vec3.dot(previousTangent, tangent), -1, 1));
      quat.setAxisAngle(rotation, v, theta);
github flowtsohg / mdx-m3-viewer / src / viewer / handlers / w3x / viewer.js View on Github external
// First see if the model is local.
      // Doodads refering to local models may have invalid variations, so if the variation doesn't exist, try without a variation.
      let mpqFile = this.mapMpq.get(fileVar) || this.mapMpq.get(file);
      let model;

      if (mpqFile) {
        model = this.load(mpqFile.name);
      } else {
        model = this.load(fileVar);
      }

      let instance = model.addInstance();

      instance.move(doodad.location);
      instance.rotateLocal(quat.setAxisAngle(quat.create(), VEC3_UNIT_Z, doodad.angle));
      instance.scale(doodad.scale);
      instance.setScene(scene);

      standOnRepeat(instance);
    }

    this.doodadsReady = true;
    this.anyReady = true;
  }
github cginternals / webgl-operate / source / trackballmodifier.ts View on Github external
/* Create rotation with respect to arbitrary camera center and up vector. */
        const centerToEye = vec3.sub(v3(), this._reference.eye, this._reference.center);
        vec3.normalize(centerToEye, centerToEye);
        const up = vec3.normalize(v3(), this._reference.up);

        /* Create vertical rotation axis. */
        const ortho = vec3.cross(v3(), centerToEye, up);
        vec3.scale(up, up, magnitudes[1]);
        vec3.scale(ortho, ortho, magnitudes[0]);

        /* Create overall rotation axis for quaternion based rotation. */
        const axis = vec3.cross(v3(), vec3.add(v3(), up, ortho), centerToEye);
        vec3.normalize(axis, axis);

        /* Create quaternion and modify rotation transformation. */
        const q = quat.setAxisAngle(quat.create(), axis, vec2.len(magnitudes));
        mat4.multiply(this._rotation, this._rotation, mat4.fromQuat(m4(), q));

        this.update();
    }
github d07RiV / wc3data / src / mdx / viewer / handlers / mdx / modelinstance.js View on Github external
import {vec3, quat} from 'gl-matrix';
import TexturedModelInstance from '../../texturedmodelinstance';
import {createSkeletalNodes} from '../../node';
import Node from './node';
import AttachmentInstance from './attachmentinstance';
import ParticleEmitterView from './particleemitterview';
import ParticleEmitter2View from './particleemitter2view';
import RibbonEmitterView from './ribbonemitterview';
import EventObjectEmitterView from './eventobjectemitterview';

// Heap allocations needed for this module.
let visibilityHeap = new Float32Array(1);
let translationHeap = vec3.create();
let rotationHeap = quat.create();
let scaleHeap = vec3.create();
let colorHeap = new Float32Array(3);
let alphaHeap = new Float32Array(1);
let textureIdHeap = new Float32Array(1);

/**
 * An MDX model instance.
 */
export default class ModelInstance extends TexturedModelInstance {
  /**
   * @param {MdxModel} model
   */
  constructor(model) {
    super(model);

    this.attachments = [];
github WoodNeck / css-camera / release / latest / lib / CSSCamera.js View on Github external
CSSCamera.prototype.focus = function (el) {
        var element = getElement(el);
        var focusMatrix = this._getFocusMatrix(element);
        var rotation = quat.create();
        var translation = vec3.create();
        mat4.getRotation(rotation, focusMatrix);
        mat4.getTranslation(translation, focusMatrix);
        var eulerAngle = quatToEuler(rotation);
        vec3.negate(eulerAngle, eulerAngle);
        this._rotation = eulerAngle;
        this._position = translation;
        return this;
    };
    CSSCamera.prototype.translateLocal = function (x, y, z) {
github screeny05 / openrw.js / packages / platform-graphics-three / mesh-provider.ts View on Github external
geometry.faces.push(new THREE.Face3(face.vertex1, face.vertex2, face.vertex3, normals, colors, face.materialId));
            geometry.faceVertexUvs[0].push([
                glVec2ToThreeVector2(faceUVCoordinates[face.vertex1]),
                glVec2ToThreeVector2(faceUVCoordinates[face.vertex2]),
                glVec2ToThreeVector2(faceUVCoordinates[face.vertex3]),
            ]);
        });
        geometry.uvsNeedUpdate = true;
        geometry.computeFaceNormals();

        geometry.boundingSphere = new THREE.Sphere(new THREE.Vector3(morphTarget.spherePosition[0], morphTarget.spherePosition[1], morphTarget.spherePosition[2]), morphTarget.sphereRadius);

        const mesh = new THREE.Mesh(geometry);
        mesh.name = name;

        const rotationQ = quat.create();
        quat.fromMat3(rotationQ, atomic.frame.rotation);

        mesh.position.set(atomic.frame.position[0], atomic.frame.position[1], atomic.frame.position[2]);
        mesh.quaternion.set(rotationQ[0], rotationQ[1], rotationQ[2], rotationQ[3]);
        mesh.visible = faces.length > 0;
        return mesh;
    }
github yiwenl / Alfrid / src / alfrid / objects / Object3D.js View on Github external
this._rx = 0;
		this._ry = 0;
		this._rz = 0;

		this._position = vec3.create();
		this._scale = vec3.fromValues(1, 1, 1);
		this._rotation = vec3.create();

		this._matrix = mat4.create();
		this._matrixParent = mat4.create();
		this._matrixRotation = mat4.create();
		this._matrixScale = mat4.create();
		this._matrixTranslation = mat4.create();
		this._matrixQuaternion = mat4.create();
		this._quat = quat.create();

		this._children = [];
	}
github GrimoireGL / GrimoireJS / src / Math / Matrix.ts View on Github external
public static rotationQuaternion(quat_: Quaternion): Matrix {
    const quaternion = quat.create();
    const newMat = mat4.create();
    quat.normalize(quaternion, quat_.rawElements);
    mat4.fromQuat(newMat, quaternion);
    return new Matrix(newMat);
  }
github GrimoireGL / GrimoireJS / src / Math / Quaternion.ts View on Github external
public static slerp(q1: Quaternion, q2: Quaternion, t: number): Quaternion {
    const newQuat = quat.create();
    return new Quaternion(quat.slerp(newQuat, q1.rawElements, q2.rawElements, +t));
  }