4230-hw-1/Pendulum/common.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-07-01 08:46:52 +00:00
// common.js
2022-07-01 08:45:53 +00:00
// John Breaux 2022-06-30
2022-07-01 08:46:52 +00:00
// Common functions and global variables for Pendulum.js
2022-07-01 08:45:53 +00:00
2022-07-01 08:49:08 +00:00
"use strict";
2022-07-01 08:45:53 +00:00
//
// Global variables
//
// Point size of the anchor
var POINT_SIZE = 5;
// Radius of the bob
var BOB_RADIUS = 0.1;
// length of the wire
var PEN_LENGTH = 0.8;
// Rotation angle (degrees/second)
var A_VELOCITY = 45.0;
//
// Common functions:
//
// acquire_buffer: Get a vertex buffer object from gl
function acquire_buffer(gl) {
// Create a buffer object
var vertexBuffer = gl.createBuffer();
if (!vertexBuffer) {
console.log('Failed to create the buffer object');
return -1;
}
return vertexBuffer;
}
function enable_attribute(gl, name, size, type) {
// Acquire a reference to named attr
var attr = gl.getAttribLocation(gl.program, name);
if (attr < 0) {
console.log(`Failed to get the storage location of ${name}`);
return -1;
}
gl.vertexAttribPointer(attr, size, type, false, 0, 0);
// Switch GL state machine to use named attr
gl.enableVertexAttribArray(attr);
}
function acquire_uniform(gl, name) {
// Acquire a reference to named attr
var ret = gl.getUniformLocation(gl.program, name);
if (!ret) {
console.log(`Failed to get the storage location of ${name}`);
return -1;
}
return ret;
}