PDA

View Full Version : Rotation to form a pyramid

Phinehas
10-24-2010, 10:39 PM
Hi,

I have an idea and want to implement it in WebGL. Normally, we have to create many vertex to form a pyramid (at least four triangle and three vertex for each triangle).

However, I want to use only one triangle to form a pyramid. The method is that I rotate the screen 90 degree after drawing one triangle. Then, I can rotate it again and drawing the second triangle and so on. Therefore, if I change the size of the triangle, I only change one time without extra effort.

But, I fail to implement it with the following coding:

for (var j = 0; j < n; j++) {
mvPushMatrix();
mvRotate(1, [0, 1, 0]);
setMatrixUniforms();
gl.drawElements(gl.TRIANGLES, pyramidVertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
mvPopMatrix();
}

It only show me one triangle. Is there any mistakes I made?

wglb
10-30-2010, 09:13 AM
Yes, you use the same rotation for every triangle.
Rotation angle should depend on j value.
Try something like:

var deltaAngle = Math.PI * 2 / n;
for (var j = 0; j < n; j++) {
mvPushMatrix();
mvRotate(j * deltaAngle, [0, 1, 0]);
setMatrixUniforms();
gl.drawElements(gl.TRIANGLES, pyramidVertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
mvPopMatrix();
}

(not tested!)

henbietha
06-02-2011, 12:42 AM
How do you figure out the volume of a segmented pyramid? Let's say there's a pyramid, and you're given the base length (16) and height (10). If we were to cut off the top 4 inches of the pyramid, how can you calculate the volume of just that segment of the pyramid?