How to use the gl-matrix.vec3.fromValues 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 rms13 / WebGL2-Volumetric-Renderer / src / renderers / clusteredDeferred.js View on Github external
renderVolumePass(shaderProgram, debugVolume, debugShadow, camera, light1Col, light1Intensity, light1PosY, light1PosZ,
    light2Col, light2Intensity, light2PosX, light2PosZ,
    volPosX, volPosY, volPosZ,
    volScaleX, volScaleY, volScaleZ,
    upscaleFactor, heterogenous, scattering, absorption, density, dirLightCol)
  {
    // Update Volume Properties
    var volPos    = vec3.fromValues(volPosX, volPosY, volPosZ); // position of the volume
    var volScale  = vec3.fromValues(volScaleX, volScaleY, volScaleZ); // scale of the volume
    var volOrient = quat.create();
    quat.fromEuler(volOrient, 0.0, 0.0, 0.0);

    mat4.fromRotationTranslationScale(this.volTransMat, volOrient, volPos, volScale);
    mat4.invert(this.invVolTransMat, this.volTransMat);    
    mat4.transpose(this.invTranspVolTransMat, this.invVolTransMat);

    if(this._upscaleFactor != upscaleFactor || this._heterogenous != heterogenous) {
      this.updateVolume(upscaleFactor, heterogenous, volPos, volScale, volOrient);
      this._upscaleFactor = upscaleFactor;  
      this._heterogenous = heterogenous;
    }

    //--------------------------------------------------  
    // Volume Pass
    //--------------------------------------------------              
github shrekshao / minimal-gltf-loader / src / minimal-gltf-loader.js View on Github external
this.indexBuffer = null;


    this.shader = null;


    this.boundingBox = null;
    if (this.attributes.POSITION !== undefined) {
        var accessor = this.attributes.POSITION;
        if (accessor.max) {
            // @todo: handle cases where no min max are provided

            // assume vec3
            if (accessor.type === 'VEC3') {
                this.boundingBox = new BoundingBox(
                    vec3.fromValues(accessor.min[0], accessor.min[1], accessor.min[2]),
                    vec3.fromValues(accessor.max[0], accessor.max[1], accessor.max[2]),
                    false
                );
                this.boundingBox.calculateTransform();
                

                
            }
            
        }
    }
};
github andrevenancio / lowww / packages / physics / src / core / contacts.js View on Github external
export const AABBIntersectAABB = (a, b) => {
    // TODO: is this the fastest thing I can do?
    const amin = vec3.fromValues(
        a.collider.left,
        a.collider.bottom,
        a.collider.back
    );
    const amax = vec3.fromValues(
        a.collider.right,
        a.collider.top,
        a.collider.front
    );

    const bmin = vec3.fromValues(
        b.collider.left,
        b.collider.bottom,
        b.collider.back
    );
    const bmax = vec3.fromValues(
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 magcius / noclip.website / src / SuperMario64DS / scenes.ts View on Github external
private modelMatrixFromObjectAndScale(m: mat4, object: CRG1Object, scale: number, extraRotationY: number = 0): void {
        const translation = vec3.fromValues(object.Position.X, object.Position.Y, object.Position.Z);
        const rotationY = (object.Rotation.Y + extraRotationY) * MathConstants.DEG_TO_RAD;

        vec3.scale(translation, translation, GLOBAL_SCALE);
        mat4.translate(m, m, translation);
        mat4.rotateY(m, m, rotationY);

        // Don't ask, ugh.
        scale = scale * (GLOBAL_SCALE / 100);
        mat4.scale(m, m, [scale, scale, scale]);
    }
github Danielhu229 / CanvasToy / examples / deferredRendering / index.ts View on Github external
import * as CanvasToy from "CanvasToy";
import { vec3 } from "gl-matrix";
import { createCanvas, onMouseOnStart } from "global";

const renderer = new CanvasToy.Renderer(createCanvas());
const scene = new CanvasToy.Scene();
const camera = new CanvasToy.PerspectiveCamera()
  .setPosition(vec3.fromValues(0, 100, 100))
  .lookAt(vec3.fromValues(0, 0, -40));
const tile = new CanvasToy.Mesh(new CanvasToy.RectGeometry(renderer.gl), [
  new CanvasToy.StandardMaterial(renderer.gl).setMainTexture(
    new CanvasToy.Texture2D(renderer.gl, "resources/images/wood.jpg")
  )
])
  .translate(vec3.fromValues(0, -10, -40))
  .rotateX(-Math.PI / 2)
  .setScaling(vec3.fromValues(200, 200, 200));
scene.addObject(camera, tile);
const teapotProto = CanvasToy.OBJLoader.load(
  renderer.gl,
  "resources/models/teapot/teapot.obj"
);

teapotProto.setAsyncFinished(
  teapotProto.asyncFinished().then(() => {
    const material = (teapotProto.children[0] as CanvasToy.Mesh)
      .materials[0] as CanvasToy.StandardMaterial;
    material.setAlbedo(vec3.fromValues(1, 0.8, 0.2));
    material.setCastShadow(false);
    for (let i = 0; i < 40; ++i) {
      const teapot = new CanvasToy.Mesh(
github stephomi / sculptgl / src / editing / Gizmo.js View on Github external
var createGizmo = function (type, nbAxis = -1) {
  return {
    _finalMatrix: mat4.create(),
    _baseMatrix: mat4.create(),
    _color: vec3.create(),
    _colorSelect: vec3.fromValues(1.0, 1.0, 0.0),
    _drawGeo: null,
    _pickGeo: null,
    _isSelected: false,
    _type: type,
    _nbAxis: nbAxis,
    _lastInter: [0.0, 0.0, 0.0],
    updateMatrix() {
      mat4.copy(this._drawGeo.getMatrix(), this._finalMatrix);
      mat4.copy(this._pickGeo.getMatrix(), this._finalMatrix);
    },
    updateFinalMatrix(mat) {
      mat4.mul(this._finalMatrix, mat, this._baseMatrix);
    }
  };
};
github magcius / noclip.website / src / metroid_prime / script.ts View on Github external
function readTransform(buffer: ArrayBufferSlice, offs: number, ent: Entity, hasPos: boolean, hasRot: boolean, hasScale: boolean): number {
    const view = buffer.createDataView();
    const originalOffs = offs;

    let position: vec3 = vec3.fromValues(0, 0, 0);
    let rotation: vec3 = vec3.fromValues(0, 0, 0);
    let scale: vec3 = vec3.fromValues(1, 1, 1);

    if (hasPos) {
        const posX = view.getFloat32(offs + 0x00);
        const posY = view.getFloat32(offs + 0x04);
        const posZ = view.getFloat32(offs + 0x08);
        vec3.set(position, posX, posY, posZ);
        offs += 0x0C;
    }

    if (hasRot) {
        const rotX = view.getFloat32(offs + 0x00) * MathConstants.DEG_TO_RAD;
        const rotY = view.getFloat32(offs + 0x04) * MathConstants.DEG_TO_RAD;
        const rotZ = view.getFloat32(offs + 0x08) * MathConstants.DEG_TO_RAD;
        vec3.set(rotation, rotX, rotY, rotZ);
        offs += 0x0C;
    }
github austinEng / webgpu-samples / src / examples / rotatingCube.ts View on Github external
function getTransformationMatrix() {
    let viewMatrix = mat4.create();
    mat4.translate(viewMatrix, viewMatrix, vec3.fromValues(0, 0, -5));
    let now = Date.now() / 1000;
    mat4.rotate(viewMatrix, viewMatrix, 1, vec3.fromValues(Math.sin(now), Math.cos(now), 0));

    let modelViewProjectionMatrix = mat4.create();
    mat4.multiply(modelViewProjectionMatrix, projectionMatrix, viewMatrix);

    return modelViewProjectionMatrix;
  }
github magcius / noclip.website / src / DarkSouls / msb.ts View on Github external
function readVec3(): vec3 {
            const x = view.getFloat32(offs + 0x00, true);
            const y = view.getFloat32(offs + 0x04, true);
            const z = view.getFloat32(offs + 0x08, true);
            offs += 0x0C;
            return vec3.fromValues(x, y, z);
        }