SlideShare a Scribd company logo
1 of 8
Download to read offline
How do I modify this code in order to create a rotating pyramid instead of a rotating cube?
HTML :
<!DOCTYPE html>
<html>
<script id="vertex-shader" type="x-shader/x-vertex">
#version 300 es
in vec4 aPosition;
in vec4 aColor;
out vec4 vColor;
uniform vec3 uTheta;
void main()
{
// Compute the sines and cosines of theta for each of
// the three axes in one computation.
vec3 angles = radians(uTheta);
vec3 c = cos(angles);
vec3 s = sin(angles);
// Remeber: thse matrices are column-major
mat4 rx = mat4(1.0, 0.0, 0.0, 0.0,
0.0, c.x, s.x, 0.0,
0.0, -s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0);
mat4 ry = mat4(c.y, 0.0, -s.y, 0.0,
0.0, 1.0, 0.0, 0.0,
s.y, 0.0, c.y, 0.0,
0.0, 0.0, 0.0, 1.0);
mat4 rz = mat4(c.z, s.z, 0.0, 0.0,
-s.z, c.z, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
vColor = aColor;
gl_Position = rz * ry * rx * aPosition;
gl_Position.z = -gl_Position.z;
}
</script>
<script id="fragment-shader" type="x-shader/x-fragment">
#version 300 es
precision mediump float;
in vec4 vColor;
out vec4 fColor;
void
main()
{
fColor = vColor;
}
</script>
<script type="text/javascript" src="initShaders.js"></script>
<script type="text/javascript" src="MV.js"></script>
<script type="text/javascript" src="RLSlProj4.js"></script>
<script type="text/javascript" src="webgl-utils.js"></script>
<body>
<canvas id="gl-canvas" width="512"" height="512">
Oops ... your browser doesn't support the HTML5 canvas element
</canvas>
<br/>
<button id= "xButton">Rotate X</button>
<button id= "yButton">Rotate Y</button>
<button id= "zButton">Rotate Z</button>
</body>
</html>
Javascript :
"use strict";
var canvas;
var gl;
var numPositions = 36;
var positions = [];
var colors = [];
var xAxis = 0;
var yAxis = 1;
var zAxis = 2;
var axis = 0;
var theta = [0, 0, 0];
var thetaLoc;
window.onload = function init()
{
canvas = document.getElementById("gl-canvas");
gl = canvas.getContext('webgl2');
if (!gl) alert("WebGL 2.0 isn't available");
colorCube();
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(1.0, 1.0, 1.0, 1.0);
gl.enable(gl.DEPTH_TEST);
//
// Load shaders and initialize attribute buffers
//
var program = initShaders(gl, "vertex-shader", "fragment-shader");
gl.useProgram(program);
var cBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, cBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(colors), gl.STATIC_DRAW);
var colorLoc = gl.getAttribLocation( program, "aColor" );
gl.vertexAttribPointer( colorLoc, 4, gl.FLOAT, false, 0, 0 );
gl.enableVertexAttribArray( colorLoc );
var vBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer);
gl.bufferData(gl.ARRAY_BUFFER, flatten(positions), gl.STATIC_DRAW);
var positionLoc = gl.getAttribLocation(program, "aPosition");
gl.vertexAttribPointer(positionLoc, 4, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(positionLoc);
thetaLoc = gl.getUniformLocation(program, "uTheta");
//event listeners for buttons
document.getElementById( "xButton" ).onclick = function () {
axis = xAxis;
};
document.getElementById( "yButton" ).onclick = function () {
axis = yAxis;
};
document.getElementById( "zButton" ).onclick = function () {
axis = zAxis;
};
render();
}
function colorCube()
{
quad(1, 0, 3, 2);
quad(2, 3, 7, 6);
quad(3, 0, 4, 7);
quad(6, 5, 1, 2);
quad(4, 5, 6, 7);
quad(5, 4, 0, 1);
}
function quad(a, b, c, d)
{
var vertices = [
vec4(-0.5, -0.5, 0.5, 1.0),
vec4(-0.5, 0.5, 0.5, 1.0),
vec4(0.5, 0.5, 0.5, 1.0),
vec4(0.5, -0.5, 0.5, 1.0),
vec4(-0.5, -0.5, -0.5, 1.0),
vec4(-0.5, 0.5, -0.5, 1.0),
vec4(0.5, 0.5, -0.5, 1.0),
vec4(0.5, -0.5, -0.5, 1.0)
];
var vertexColors = [
vec4(0.0, 0.0, 0.0, 1.0), // black
vec4(1.0, 0.0, 0.0, 1.0), // red
vec4(1.0, 1.0, 0.0, 1.0), // yellow
vec4(0.0, 1.0, 0.0, 1.0), // green
vec4(0.0, 0.0, 1.0, 1.0), // blue
vec4(1.0, 0.0, 1.0, 1.0), // magenta
vec4(0.0, 1.0, 1.0, 1.0), // cyan
vec4(1.0, 1.0, 1.0, 1.0) // white
];
// We need to parition the quad into two triangles in order for
// WebGL to be able to render it. In this case, we create two
// triangles from the quad indices
//vertex color assigned by the index of the vertex
var indices = [a, b, c, a, c, d];
for ( var i = 0; i < indices.length; ++i ) {
positions.push( vertices[indices[i]] );
//colors.push( vertexColors[indices[i]] );
// for solid colored faces use
colors.push(vertexColors[a]);
}
}
function render()
{
gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
theta[axis] += 2.0;
gl.uniform3fv(thetaLoc, theta);
gl.drawArrays(gl.TRIANGLES, 0, numPositions);
requestAnimationFrame(render);
}

More Related Content

Similar to How do I modify this code in order to create a rotating pyramid instea.pdf

Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slidestamillarasan
 
A Novice's Guide to WebGL
A Novice's Guide to WebGLA Novice's Guide to WebGL
A Novice's Guide to WebGLKrzysztof Kula
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil Witecki
 
ITS 630 – Residency Project Circuit City was an American c.docx
ITS 630 – Residency Project Circuit City was an American c.docxITS 630 – Residency Project Circuit City was an American c.docx
ITS 630 – Residency Project Circuit City was an American c.docxvrickens
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-CNissan Tsafrir
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
Five things for you - Yahoo developer offers
Five things for you - Yahoo developer offersFive things for you - Yahoo developer offers
Five things for you - Yahoo developer offersChristian Heilmann
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at NackademinRobert Nyman
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
INTERVIEW QUESTIONS_Verilog_PART-2.pdf
INTERVIEW QUESTIONS_Verilog_PART-2.pdfINTERVIEW QUESTIONS_Verilog_PART-2.pdf
INTERVIEW QUESTIONS_Verilog_PART-2.pdfDrViswanathKalannaga1
 
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門nakamura001
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wireRené Domínguez
 

Similar to How do I modify this code in order to create a rotating pyramid instea.pdf (20)

Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
OpenGL L06-Performance
OpenGL L06-PerformanceOpenGL L06-Performance
OpenGL L06-Performance
 
Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
 
A Novice's Guide to WebGL
A Novice's Guide to WebGLA Novice's Guide to WebGL
A Novice's Guide to WebGL
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, code
 
ITS 630 – Residency Project Circuit City was an American c.docx
ITS 630 – Residency Project Circuit City was an American c.docxITS 630 – Residency Project Circuit City was an American c.docx
ITS 630 – Residency Project Circuit City was an American c.docx
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-C
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Marat-Slides
Marat-SlidesMarat-Slides
Marat-Slides
 
3
33
3
 
Five things for you - Yahoo developer offers
Five things for you - Yahoo developer offersFive things for you - Yahoo developer offers
Five things for you - Yahoo developer offers
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at Nackademin
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
INTERVIEW QUESTIONS_Verilog_PART-2.pdf
INTERVIEW QUESTIONS_Verilog_PART-2.pdfINTERVIEW QUESTIONS_Verilog_PART-2.pdf
INTERVIEW QUESTIONS_Verilog_PART-2.pdf
 
Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門Learning WebGLで学ぶWebGL入門
Learning WebGLで学ぶWebGL入門
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wire
 

More from krishnac481

How does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdf
How does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdfHow does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdf
How does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdfkrishnac481
 
How I can change the output size in insert import tkinter as tk imp.pdf
How I can change the output size in insert    import tkinter as tk imp.pdfHow I can change the output size in insert    import tkinter as tk imp.pdf
How I can change the output size in insert import tkinter as tk imp.pdfkrishnac481
 
How does PowerBI relate to digital transformation- (Minimum 200 words).pdf
How does PowerBI relate to digital transformation- (Minimum 200 words).pdfHow does PowerBI relate to digital transformation- (Minimum 200 words).pdf
How does PowerBI relate to digital transformation- (Minimum 200 words).pdfkrishnac481
 
How does Any Rand view the American idea of -making money-- A- Nega.pdf
How does Any Rand view the American idea of -making money-- A-    Nega.pdfHow does Any Rand view the American idea of -making money-- A-    Nega.pdf
How does Any Rand view the American idea of -making money-- A- Nega.pdfkrishnac481
 
How has social media impacted consumer behavior pre and post covid19-.pdf
How has social media impacted consumer behavior pre and post covid19-.pdfHow has social media impacted consumer behavior pre and post covid19-.pdf
How has social media impacted consumer behavior pre and post covid19-.pdfkrishnac481
 
How is Peru being impacted by Climate Change- Compare and contrast the.pdf
How is Peru being impacted by Climate Change- Compare and contrast the.pdfHow is Peru being impacted by Climate Change- Compare and contrast the.pdf
How is Peru being impacted by Climate Change- Compare and contrast the.pdfkrishnac481
 
How is each group classified- Parasitic worms Fungi Protozoa What is t.pdf
How is each group classified- Parasitic worms Fungi Protozoa What is t.pdfHow is each group classified- Parasitic worms Fungi Protozoa What is t.pdf
How is each group classified- Parasitic worms Fungi Protozoa What is t.pdfkrishnac481
 
How do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdf
How do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdfHow do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdf
How do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdfkrishnac481
 
How is long-run economic growth measured- What is the basis of long-ru.pdf
How is long-run economic growth measured- What is the basis of long-ru.pdfHow is long-run economic growth measured- What is the basis of long-ru.pdf
How is long-run economic growth measured- What is the basis of long-ru.pdfkrishnac481
 
How do I calculate the following for relative error by hand- I'm aware.pdf
How do I calculate the following for relative error by hand- I'm aware.pdfHow do I calculate the following for relative error by hand- I'm aware.pdf
How do I calculate the following for relative error by hand- I'm aware.pdfkrishnac481
 
How is global human resource management different from domestic HRM- Q.pdf
How is global human resource management different from domestic HRM- Q.pdfHow is global human resource management different from domestic HRM- Q.pdf
How is global human resource management different from domestic HRM- Q.pdfkrishnac481
 
How has Europe benefited from its location and its major physical feat.pdf
How has Europe benefited from its location and its major physical feat.pdfHow has Europe benefited from its location and its major physical feat.pdf
How has Europe benefited from its location and its major physical feat.pdfkrishnac481
 
How each of this happens and their clinical correlates-a- Inversion du.pdf
How each of this happens and their clinical correlates-a- Inversion du.pdfHow each of this happens and their clinical correlates-a- Inversion du.pdf
How each of this happens and their clinical correlates-a- Inversion du.pdfkrishnac481
 
How is the beginning of intramembranous ossification different from en.pdf
How is the beginning of intramembranous ossification different from en.pdfHow is the beginning of intramembranous ossification different from en.pdf
How is the beginning of intramembranous ossification different from en.pdfkrishnac481
 
How do the architecture and design of these systems reflect the functi.pdf
How do the architecture and design of these systems reflect the functi.pdfHow do the architecture and design of these systems reflect the functi.pdf
How do the architecture and design of these systems reflect the functi.pdfkrishnac481
 
How does the fluid mosaic model represents the structure of the plasma.pdf
How does the fluid mosaic model represents the structure of the plasma.pdfHow does the fluid mosaic model represents the structure of the plasma.pdf
How does the fluid mosaic model represents the structure of the plasma.pdfkrishnac481
 
How do you differentiate a crypto exchange from a traditional stock ex.pdf
How do you differentiate a crypto exchange from a traditional stock ex.pdfHow do you differentiate a crypto exchange from a traditional stock ex.pdf
How do you differentiate a crypto exchange from a traditional stock ex.pdfkrishnac481
 
How does the heterozygous condition for sickle cell disease confer an.pdf
How does the heterozygous condition for sickle cell disease confer an.pdfHow does the heterozygous condition for sickle cell disease confer an.pdf
How does the heterozygous condition for sickle cell disease confer an.pdfkrishnac481
 
How does Celebrity Cruises collect data about the customer experience-.pdf
How does Celebrity Cruises collect data about the customer experience-.pdfHow does Celebrity Cruises collect data about the customer experience-.pdf
How does Celebrity Cruises collect data about the customer experience-.pdfkrishnac481
 
How do retail stores display their merchandise taking into account sub.pdf
How do retail stores display their merchandise taking into account sub.pdfHow do retail stores display their merchandise taking into account sub.pdf
How do retail stores display their merchandise taking into account sub.pdfkrishnac481
 

More from krishnac481 (20)

How does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdf
How does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdfHow does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdf
How does excitation pass from cell 1 to cell 2- By acetylcholine By pa.pdf
 
How I can change the output size in insert import tkinter as tk imp.pdf
How I can change the output size in insert    import tkinter as tk imp.pdfHow I can change the output size in insert    import tkinter as tk imp.pdf
How I can change the output size in insert import tkinter as tk imp.pdf
 
How does PowerBI relate to digital transformation- (Minimum 200 words).pdf
How does PowerBI relate to digital transformation- (Minimum 200 words).pdfHow does PowerBI relate to digital transformation- (Minimum 200 words).pdf
How does PowerBI relate to digital transformation- (Minimum 200 words).pdf
 
How does Any Rand view the American idea of -making money-- A- Nega.pdf
How does Any Rand view the American idea of -making money-- A-    Nega.pdfHow does Any Rand view the American idea of -making money-- A-    Nega.pdf
How does Any Rand view the American idea of -making money-- A- Nega.pdf
 
How has social media impacted consumer behavior pre and post covid19-.pdf
How has social media impacted consumer behavior pre and post covid19-.pdfHow has social media impacted consumer behavior pre and post covid19-.pdf
How has social media impacted consumer behavior pre and post covid19-.pdf
 
How is Peru being impacted by Climate Change- Compare and contrast the.pdf
How is Peru being impacted by Climate Change- Compare and contrast the.pdfHow is Peru being impacted by Climate Change- Compare and contrast the.pdf
How is Peru being impacted by Climate Change- Compare and contrast the.pdf
 
How is each group classified- Parasitic worms Fungi Protozoa What is t.pdf
How is each group classified- Parasitic worms Fungi Protozoa What is t.pdfHow is each group classified- Parasitic worms Fungi Protozoa What is t.pdf
How is each group classified- Parasitic worms Fungi Protozoa What is t.pdf
 
How do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdf
How do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdfHow do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdf
How do I print the lists vertically- sizes -- -Small-- -Medium-- -Larg.pdf
 
How is long-run economic growth measured- What is the basis of long-ru.pdf
How is long-run economic growth measured- What is the basis of long-ru.pdfHow is long-run economic growth measured- What is the basis of long-ru.pdf
How is long-run economic growth measured- What is the basis of long-ru.pdf
 
How do I calculate the following for relative error by hand- I'm aware.pdf
How do I calculate the following for relative error by hand- I'm aware.pdfHow do I calculate the following for relative error by hand- I'm aware.pdf
How do I calculate the following for relative error by hand- I'm aware.pdf
 
How is global human resource management different from domestic HRM- Q.pdf
How is global human resource management different from domestic HRM- Q.pdfHow is global human resource management different from domestic HRM- Q.pdf
How is global human resource management different from domestic HRM- Q.pdf
 
How has Europe benefited from its location and its major physical feat.pdf
How has Europe benefited from its location and its major physical feat.pdfHow has Europe benefited from its location and its major physical feat.pdf
How has Europe benefited from its location and its major physical feat.pdf
 
How each of this happens and their clinical correlates-a- Inversion du.pdf
How each of this happens and their clinical correlates-a- Inversion du.pdfHow each of this happens and their clinical correlates-a- Inversion du.pdf
How each of this happens and their clinical correlates-a- Inversion du.pdf
 
How is the beginning of intramembranous ossification different from en.pdf
How is the beginning of intramembranous ossification different from en.pdfHow is the beginning of intramembranous ossification different from en.pdf
How is the beginning of intramembranous ossification different from en.pdf
 
How do the architecture and design of these systems reflect the functi.pdf
How do the architecture and design of these systems reflect the functi.pdfHow do the architecture and design of these systems reflect the functi.pdf
How do the architecture and design of these systems reflect the functi.pdf
 
How does the fluid mosaic model represents the structure of the plasma.pdf
How does the fluid mosaic model represents the structure of the plasma.pdfHow does the fluid mosaic model represents the structure of the plasma.pdf
How does the fluid mosaic model represents the structure of the plasma.pdf
 
How do you differentiate a crypto exchange from a traditional stock ex.pdf
How do you differentiate a crypto exchange from a traditional stock ex.pdfHow do you differentiate a crypto exchange from a traditional stock ex.pdf
How do you differentiate a crypto exchange from a traditional stock ex.pdf
 
How does the heterozygous condition for sickle cell disease confer an.pdf
How does the heterozygous condition for sickle cell disease confer an.pdfHow does the heterozygous condition for sickle cell disease confer an.pdf
How does the heterozygous condition for sickle cell disease confer an.pdf
 
How does Celebrity Cruises collect data about the customer experience-.pdf
How does Celebrity Cruises collect data about the customer experience-.pdfHow does Celebrity Cruises collect data about the customer experience-.pdf
How does Celebrity Cruises collect data about the customer experience-.pdf
 
How do retail stores display their merchandise taking into account sub.pdf
How do retail stores display their merchandise taking into account sub.pdfHow do retail stores display their merchandise taking into account sub.pdf
How do retail stores display their merchandise taking into account sub.pdf
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

How do I modify this code in order to create a rotating pyramid instea.pdf

  • 1. How do I modify this code in order to create a rotating pyramid instead of a rotating cube? HTML : <!DOCTYPE html> <html> <script id="vertex-shader" type="x-shader/x-vertex"> #version 300 es in vec4 aPosition; in vec4 aColor; out vec4 vColor; uniform vec3 uTheta; void main() { // Compute the sines and cosines of theta for each of // the three axes in one computation. vec3 angles = radians(uTheta); vec3 c = cos(angles); vec3 s = sin(angles); // Remeber: thse matrices are column-major mat4 rx = mat4(1.0, 0.0, 0.0, 0.0, 0.0, c.x, s.x, 0.0, 0.0, -s.x, c.x, 0.0, 0.0, 0.0, 0.0, 1.0); mat4 ry = mat4(c.y, 0.0, -s.y, 0.0,
  • 2. 0.0, 1.0, 0.0, 0.0, s.y, 0.0, c.y, 0.0, 0.0, 0.0, 0.0, 1.0); mat4 rz = mat4(c.z, s.z, 0.0, 0.0, -s.z, c.z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); vColor = aColor; gl_Position = rz * ry * rx * aPosition; gl_Position.z = -gl_Position.z; } </script> <script id="fragment-shader" type="x-shader/x-fragment"> #version 300 es precision mediump float; in vec4 vColor; out vec4 fColor; void main() { fColor = vColor; }
  • 3. </script> <script type="text/javascript" src="initShaders.js"></script> <script type="text/javascript" src="MV.js"></script> <script type="text/javascript" src="RLSlProj4.js"></script> <script type="text/javascript" src="webgl-utils.js"></script> <body> <canvas id="gl-canvas" width="512"" height="512"> Oops ... your browser doesn't support the HTML5 canvas element </canvas> <br/> <button id= "xButton">Rotate X</button> <button id= "yButton">Rotate Y</button> <button id= "zButton">Rotate Z</button> </body> </html> Javascript : "use strict"; var canvas; var gl; var numPositions = 36; var positions = []; var colors = []; var xAxis = 0;
  • 4. var yAxis = 1; var zAxis = 2; var axis = 0; var theta = [0, 0, 0]; var thetaLoc; window.onload = function init() { canvas = document.getElementById("gl-canvas"); gl = canvas.getContext('webgl2'); if (!gl) alert("WebGL 2.0 isn't available"); colorCube(); gl.viewport(0, 0, canvas.width, canvas.height); gl.clearColor(1.0, 1.0, 1.0, 1.0); gl.enable(gl.DEPTH_TEST); // // Load shaders and initialize attribute buffers // var program = initShaders(gl, "vertex-shader", "fragment-shader"); gl.useProgram(program); var cBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, cBuffer); gl.bufferData(gl.ARRAY_BUFFER, flatten(colors), gl.STATIC_DRAW); var colorLoc = gl.getAttribLocation( program, "aColor" );
  • 5. gl.vertexAttribPointer( colorLoc, 4, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( colorLoc ); var vBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); gl.bufferData(gl.ARRAY_BUFFER, flatten(positions), gl.STATIC_DRAW); var positionLoc = gl.getAttribLocation(program, "aPosition"); gl.vertexAttribPointer(positionLoc, 4, gl.FLOAT, false, 0, 0); gl.enableVertexAttribArray(positionLoc); thetaLoc = gl.getUniformLocation(program, "uTheta"); //event listeners for buttons document.getElementById( "xButton" ).onclick = function () { axis = xAxis; }; document.getElementById( "yButton" ).onclick = function () { axis = yAxis; }; document.getElementById( "zButton" ).onclick = function () { axis = zAxis; }; render(); } function colorCube()
  • 6. { quad(1, 0, 3, 2); quad(2, 3, 7, 6); quad(3, 0, 4, 7); quad(6, 5, 1, 2); quad(4, 5, 6, 7); quad(5, 4, 0, 1); } function quad(a, b, c, d) { var vertices = [ vec4(-0.5, -0.5, 0.5, 1.0), vec4(-0.5, 0.5, 0.5, 1.0), vec4(0.5, 0.5, 0.5, 1.0), vec4(0.5, -0.5, 0.5, 1.0), vec4(-0.5, -0.5, -0.5, 1.0), vec4(-0.5, 0.5, -0.5, 1.0), vec4(0.5, 0.5, -0.5, 1.0), vec4(0.5, -0.5, -0.5, 1.0) ]; var vertexColors = [ vec4(0.0, 0.0, 0.0, 1.0), // black vec4(1.0, 0.0, 0.0, 1.0), // red
  • 7. vec4(1.0, 1.0, 0.0, 1.0), // yellow vec4(0.0, 1.0, 0.0, 1.0), // green vec4(0.0, 0.0, 1.0, 1.0), // blue vec4(1.0, 0.0, 1.0, 1.0), // magenta vec4(0.0, 1.0, 1.0, 1.0), // cyan vec4(1.0, 1.0, 1.0, 1.0) // white ]; // We need to parition the quad into two triangles in order for // WebGL to be able to render it. In this case, we create two // triangles from the quad indices //vertex color assigned by the index of the vertex var indices = [a, b, c, a, c, d]; for ( var i = 0; i < indices.length; ++i ) { positions.push( vertices[indices[i]] ); //colors.push( vertexColors[indices[i]] ); // for solid colored faces use colors.push(vertexColors[a]); } } function render() { gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); theta[axis] += 2.0;
  • 8. gl.uniform3fv(thetaLoc, theta); gl.drawArrays(gl.TRIANGLES, 0, numPositions); requestAnimationFrame(render); }