Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

Using comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl and if that helps you.

Please and thank you

JavaScript file:

function MVbuffer(size) {

var b = {};

b.buf = new Float32Array(size);

b.index = 0;

b.push = function(x) {

for(var i=0; i<x.length; i++) {

b.buf[b.index+i] = x[i];

}

b.index += x.length;

b.type = '';

}

return b;

}

function isVector(v) {

if(v.type == "vec2" || v.type == "vec3" || v.type == "vec4") return true;

return false;

}

function isMatrix(v) {

if(v.type == "mat2" || v.type == "mat3" || v.type == "mat4") return true;

return false;

}

function radians( degrees ) {

return degrees * Math.PI / 180.0;

}

//----------------------------------------------------------------------------



function patch() {

var out = new Array(4);

for(var i = 0; i< 4; i++) out[i] = new Array(4);

out.type = "patch";

return out;

}

function curve() {

var out = new Array(4);

out.type = "curve";

return out;

}

//

// Vector Constructors

//

function vec2()

{

var out = new Array(2);

out.type = 'vec2';

switch ( arguments.length ) {

case 0:

out[0] = 0.0;

out[1] = 0.0;

break;

case 1:

if(isVector(arguments[0] && (arguments[0].type != 'vec2'))) {

out[0] = arguments[0][0];

out[1] = arguments[0][1];

}

break;

case 2:

out[0] = arguments[0];

out[1] = arguments[1];

break;

}

return out;

}

function vec3()

{

//var result = _argumentsToArray( arguments );

var out = new Array(3);

out.type = 'vec3';

switch ( arguments.length ) {

case 0:

out[0] = 0.0;

out[1] = 0.0;

out[2] = 0.0;

return out;

case 1:

if(isVector(arguments[0]) && (arguments[0].type == "vec3")) {

out[0] = arguments[0][0];

out[1] = arguments[0][1];

out[2] = arguments[0][2];

return out;

}

case 3:

out[0] = arguments[0];

out[1] = arguments[1];

out[2] = arguments[2];

return out;

default:

throw "vec3: wrong arguments";

}

return out;

}

function vec4()

{

var out = new Array(4);

out.type = 'vec4';

switch ( arguments.length ) {

case 0:

out[0] = 0.0;

out[1] = 0.0;

out[2] = 0.0;

out[3] = 0.0;

return out;

case 1:

if(isVector(arguments[0])) {

if(arguments[0].type == "vec4") {

out[0] = arguments[0][0];

out[1] = arguments[0][1];

out[2] = arguments[0][2];

out[3] = arguments[0][3];

return out;

}

}

else if(arguments[0].type == "vec3") {

out[0] = arguments[0][0];

out[1] = arguments[0][1];

out[2] = arguments[0][2];

out[3] = 1.0;

return out;

}

else {

out[0] = arguments[0][0];

out[1] = arguments[0][1];

out[2] = arguments[0][2];

out[3] = arguments[0][3];

return out;

}




case 2:

if(typeof(arguments[0])=='number'&&arguments[1].type == 'vec3') {

out[0] = arguments[0];

out[1] = arguments[1][0];

out[2] = arguments[1][1];

out[3] = arguments[1][2];

return out;

}

return out;

case 4:

if(isVector(arguments[0])) {

out[0] = arguments[0][0];

out[1] = arguments[0][1];

out[2] = arguments[0][2];

out[3] = arguments[0][3];

return out;

}

out[0] = arguments[0];

out[1] = arguments[1];

out[2] = arguments[2];

out[3] = arguments[3];

return out;

case 3:

out[0] = arguments[0][0];

out[1] = arguments[0][1];

out[2] = arguments[0][2];

out[3] = 1.0;

return out;

default:

throw "vec4: wrong arguments";

}

}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education