Jump to content
  • Advertisement
Sign in to follow this  

Back face of a pyramid is missing

This topic is 2231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to texture map a pyramid. However, what should be the back side of the pyramid is somehow missing from view.

Here is a view from the front. This is the default orientation when my demo first executes.
As we rotate about the y axis to get a view of the back face of the pyramid, we find that the back face is missing! Instead, we see that the diagonal cross section is texture mapped. Obviously, the viewer should never be able to see inside the pyramid much less have it texture mapped.
Here is a map of the vertices for clarity.
Here is some code.

void PyramidDemo::buildPyrGeometry()
// Create the vertex buffer.
HR(gd3dDevice->CreateVertexBuffer(24 * sizeof(VertexPNT), D3DUSAGE_WRITEONLY,
0, D3DPOOL_MANAGED, &mPyrVB, 0));
// Write Pyr vertices to the vertex buffer.
VertexPNT* v = 0;
HR(mPyrVB->Lock(0, 0, (void**)&v, 0));
D3DXVECTOR3 pyrV0( 0.0f, 0.0f, 0.0f);
D3DXVECTOR3 pyrV1(-1.0f, -1.0f, -1.0f);
D3DXVECTOR3 pyrV2( 1.0f, -1.0f, -1.0f);
D3DXVECTOR3 pyrV3(-1.0f, -1.0f, 1.0f);
D3DXVECTOR3 pyrV4( 1.0f, -1.0f, 1.0f);
faceNormal(&pyrV0, &pyrV2, &pyrV1, &fn_f);
faceNormal(&pyrV0, &pyrV3, &pyrV4, &fn_b);
faceNormal(&pyrV0, &pyrV1, &pyrV3, &fn_l);
faceNormal(&pyrV0, &pyrV4, &pyrV2, &fn_r);

v[0] = VertexPNT(pyrV1.x, pyrV1.y, pyrV1.z, fn_f.x, fn_f.y, fn_f.z, 0.0f, 1.0f);
v[1] = VertexPNT(pyrV0.x, pyrV0.y, pyrV0.z, fn_f.x, fn_f.y, fn_f.z, 0.0f, 0.0f);
v[2] = VertexPNT(pyrV2.x, pyrV2.y, pyrV2.z, fn_f.x, fn_f.y, fn_f.z, 1.0f, 0.0f);

v[3] = VertexPNT(pyrV4.x, pyrV4.y, pyrV4.z, fn_b.x, fn_b.y, fn_b.z, 0.0f, 1.0f);
v[4] = VertexPNT(pyrV0.x, pyrV0.y, pyrV0.z, fn_b.x, fn_b.y, fn_b.z, 0.0f, 0.0f);
v[5] = VertexPNT(pyrV3.x, pyrV3.y, pyrV3.z, fn_b.x, fn_b.y, fn_b.z, 1.0f, 0.0f);

v[6] = VertexPNT(pyrV1.x, pyrV1.y, pyrV1.z, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f);
v[7] = VertexPNT(pyrV2.x, pyrV2.y, pyrV2.z, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f);
v[8] = VertexPNT(pyrV4.x, pyrV4.y, pyrV4.z, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
v[9] = VertexPNT(pyrV3.x, pyrV3.y, pyrV3.z, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

v[10]= VertexPNT(pyrV4.x, pyrV4.y, pyrV4.z, fn_l.x, fn_l.y, fn_l.z, 0.0f, 1.0f);
v[11]= VertexPNT(pyrV0.x, pyrV0.y, pyrV0.z, fn_l.x, fn_l.y, fn_l.z, 0.0f, 0.0f);
v[12]= VertexPNT(pyrV1.x, pyrV1.y, pyrV1.z, fn_l.x, fn_l.y, fn_l.z, 1.0f, 0.0f);
v[13]= VertexPNT(pyrV2.x, pyrV2.y, pyrV2.z, fn_r.x, fn_r.y, fn_r.z, 0.0f, 1.0f);
v[14]= VertexPNT(pyrV0.x, pyrV0.y, pyrV0.z, fn_r.x, fn_r.y, fn_r.z, 0.0f, 0.0f);
v[15]= VertexPNT(pyrV4.x, pyrV4.y, pyrV4.z, fn_r.x, fn_r.y, fn_r.z, 1.0f, 0.0f);


// Create the vertex buffer.
HR(gd3dDevice->CreateIndexBuffer(36 * sizeof(WORD), D3DUSAGE_WRITEONLY,
// Write Pyr indices to the index buffer.
WORD* i = 0;
HR(mPyrIB->Lock(0, 0, (void**)&i, 0));

i[0] = 0; i[1] = 1; i[2] = 2;
i[3] = 3; i[4] = 4; i[5] = 5;
i[6] = 6; i[7] = 7; i[8] = 8;
i[9] = 8; i[10] = 9; i[11] = 6;
i[12] = 10; i[13] = 11; i[14] = 12;
i[15] = 13; i[16] = 14; i[17] = 15;


void PyramidDemo::faceNormal(D3DXVECTOR3* v0, D3DXVECTOR3* v1, D3DXVECTOR3* v2, D3DXVECTOR3* n)
D3DXVECTOR3 u = *v1 - *v0;
D3DXVECTOR3 v = *v2 - *v0;
D3DXVec3Cross(n, &u, &v);
D3DXVec3Normalize(n, n);

I tried to list the vertices of the back face in a counterclockwise winding order. I tried disabling culling, and it still is missing. What could be wrong?

Share this post

Link to post
Share on other sites
From your picture it doesn't look like your back triangle isn't missing, but rather one of its indices are wrong. See how the triangle connects to the bottom right corner and the top of the pyramid, but then connects to the front left corner instead of the back left corner? Edited by MJP

Share this post

Link to post
Share on other sites
Agreed, or similarly the normal is facing the wrong way and it is being back-face culled. That could also be related to indices; the order that you specify them.

Share this post

Link to post
Share on other sites
Like I said, I disabled culling and it still won't show. Also, I tried specifying the vertices that make up the back face of my pyramid both clockwise and counterclockwise, and it still didn't do what I wanted. Do both the vertices and the indices that correspond to those vertices have to be in a special order?

Share this post

Link to post
Share on other sites
That really doesn't look like windingorder-related problem (face culling).
Maybe you should give us another picture, from a slightly different camera orientation, but my best guess at this moment is this:

Let's name the vertices one the second picute (the wrong one) this way - the top one is T, the bottom square consist of A (closer to us, left), B (closer to us, right), C (further from us, left), D (further from us, right).
I would bet that the triangle which should form the front face and should be made of T, B, A is instead made of T, B, C.
But as I said, another camera angle would confirm/disprove it.

And if I'm right, then it really means that you have some error in your code. Most probably in the indices, even though you double-checked it already. Edited by Tom KQT

Share this post

Link to post
Share on other sites

i[12] = 10; i[13] = 11; i[14] = 12;

These indices are looking like a diagonal (v1, v0, v4).

However, I could be wrong since I'm quite new to this 3d stuff.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!