1
\$\begingroup\$

I know little about 3D game development, but I'm trying to understand how to set what side of a mesh has the visible face. I am using Wild Magic 5 and my object looks like this:

VertexFormat* ssVFormat = VertexFormat::Create(2,
    VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0,
    VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT4, 0);
int ssVStride = ssVFormat->GetStride();

VertexBuffer* ssVBuffer = new0 VertexBuffer(8, ssVStride);
VertexBufferAccessor ssVba(ssVFormat, ssVBuffer);
Float4 ssColor(0.0f, 0.0f, 1.0f, 0.25f);
ssVba.Position<Float3>(0) = Float3(0.0f, 0.0f, 1.0f);
ssVba.Position<Float3>(1) = Float3(1.0f, 0.0f, 1.0f);
ssVba.Position<Float3>(2) = Float3(1.0f, 1.0f, 1.0f);
ssVba.Position<Float3>(3) = Float3(0.0f, 1.0f, 1.0f);
ssVba.Position<Float3>(4) = Float3(0.0f, 0.0f, 0.0f);
ssVba.Position<Float3>(5) = Float3(1.0f, 0.0f, 0.0f);
ssVba.Position<Float3>(6) = Float3(1.0f, 1.0f, 0.0f);
ssVba.Position<Float3>(7) = Float3(0.0f, 1.0f, 0.0f);
ssVba.Color<Float4>(0, 0) = ssColor;
ssVba.Color<Float4>(0, 1) = ssColor;
ssVba.Color<Float4>(0, 2) = ssColor;
ssVba.Color<Float4>(0, 3) = ssColor;          

IndexBuffer* ssIBuffer = new0 IndexBuffer(12, sizeof(int));
int* indices = (int*)ssIBuffer->GetData();
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
indices[6] = 7; indices[7] = 4; indices[8] = 3;
indices[9] = 0; indices[10] = 4; indices[11] = 3;

TriMeshPtr mRectangle = new0 TriMesh(ssVFormat, ssVBuffer, ssIBuffer);
mRectangle->Update();

// Create a vertex color effect for the screen rectangle.
VertexColor4Effect* ssEffect = new0 VertexColor4Effect();
mRectangle->SetEffectInstance(ssEffect->CreateInstance());

return mRectangle;

How do I set what side is the visible face? Am I using the right terminology? I'm sure this engine can set it—I just don't know how.

\$\endgroup\$
2
\$\begingroup\$

Side determination is done using the direction the vertices are wound in "window-space."

Basically, that means after you project your geometry onto the image plane (window), you either shade the front or the back of a triangle. Which side is being shaded is determined by following the path the vertices that make up each triangle takes. Technically, it is much simpler than that... you can determine winding direction using something called the signed area test.

Consider the equation for the area of a right triangle:

  1/2 Base x Height

Ordinarily, Base and Height are assumed to be positive because in every day life negative lengths are meaningless. But if you include direction in either, suddenly and quite meaningfully, the area of a triangle can be either positive or negative.

Visualization of Signed Area Test:

          Signed Area

As you can see, triangles are always either arranged in a clockwise or counter-clockwise winding, and graphics APIs let you establish which one is supposed to represent the front. You must arrange your vertices according to this convention.

Likewise, APIs allow you to cull either the front or back (or both, as silly as that sounds) of polygons. So you need to define both the front-face orientation and the side(s) to cull before you can say which side of a polygon is going to be visible.

\$\endgroup\$
1
  • \$\begingroup\$ It is also worth pointing out that if two of the points in a triangle are the same, it will have zero area (degenerate) and technically is neither clockwise nor counter-clockwise. You don't have to worry about which side of those are front or back though, because they have no sides ;) \$\endgroup\$ May 4 '14 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.