PDA

View Full Version : Splitting Pyramid Problem



Qoheleth
12-30-2012, 11:54 PM
Good for now: 934
Bad. One of the faces reappears down the middle: 933

I've have a pyramid on screen. I'm able to rotate it by 5 degrees on the y-axis, but at certain points one of the faces will appear straight down the middle, and will continue to increase in size until it reaches the original face size, which at that point if you continue to go in the same direction (using the left/right arrow keys) the pyramid will then rotate in the opposite direction. I am incrementing and decrementing the angle with:



if ( key == GLUT_KEY_LEFT )
{
rStepAngle += 0.10f;
}

else if ( key == GLUT_KEY_RIGHT )
{
rStepAngle -= 0.10f;
}
...


Another question I have is, how do I make each face a solid color. I attempted to do this by:



VertexData data[ 12 ] = {
{ { 255, 0, 0, 255 }, { -0.5f, 0.0f, 0.5f } }, // front
{ { 255, 0, 0, 255 }, { 0.5f, 0.0f, 0.5f } },
{ { 255, 0, 0, 255 }, { 0.0f, 0.5f, 0.0f } },
{ { 0, 255, 0, 255 }, { 0.5f, 0.0f, 0.5f } }, // right
{ { 0, 255, 0, 255 }, { 0.5f, 0.0f, -0.5f } },
{ { 0, 255, 0, 255 }, { 0.0f, 0.5f, 0.0f } },
{ { 0, 0, 255, 255 }, { 0.5f, 0.0f, -0.5f } }, // back
{ { 0, 0, 255, 255 }, { -0.5f, 0.0f, -0.5f } },
{ { 0, 0, 255, 255 }, { 0.0f, 0.5f, 0.0f } },
{ { 255, 255, 0, 255 }, { -0.5f, 0.0f, -0.5f } }, // left
{ { 255, 255, 0, 255 }, { -0.5f, 0.0f, 0.5f } },
{ { 255, 255, 0, 255 }, { 0.0f, 0.5f, 0.0f } }
};

glVertexAttribPointer( vColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof( VertexData ), BUFFER_OFFSET( 0 ) );


Sticking that in the buffer, but the shader does gouraud and it's like the color for the vertices is random.

Qoheleth
01-01-2013, 12:11 PM
I was able to figure out the problem. A beginner mistake: I had not culled the back face.