# C++ How does one get the top or a bottom of a triangle?

## Recommended Posts

I have a small mesh of triangles and I'd like to know how to tell which side is the top and which side is the bottom. E.g., I have a cube and I'm looking for the interior of the cube as well as the external side of it. Eventually, I'd like to show volumes of my models.

##### Share on other sites
Posted (edited)
25 minutes ago, SR D said:

Eventually, I'd like to show volumes of my models.

I think that's called rendering? The cube/mesh should be designed to have the faces pointing in the right direction without having to do calculations.

Edited by fleabay

##### Share on other sites

1 hour ago, SR D said:

... a cube and I'm looking for the interior of the cube as well as the external side of it ...

If i understand it right, two concepts play a role here: the winding order of vertices/indices, and surface normals.

##### Share on other sites

The winding I know, but I've not yet drawn or calculated the normals as I'm a bit confused on that. Isn't there a normal for each side? Or is the normal only on the side where I choose the winding order?

##### Share on other sites
Posted (edited)

The surface normal of a triangle is the cross product of two of its edges.

But i don't know what you're up to. OpenGL for example is content with the winding order alone to determine which sides are front and back. But for more complex things like lighting, one would calculate normals per primitive, vertex or fragment manually, preferably in some shader.

Edited by Green_Baron

##### Share on other sites
13 hours ago, SR D said:

The winding I know, but I've not yet drawn or calculated the normals as I'm a bit confused on that. Isn't there a normal for each side? Or is the normal only on the side where I choose the winding order?

Normal is a per vertex information, that is, it is on each vertex. Sometimes all three verticies of a triangle has the same pointing normal called triangle normal, what is a normal perpendicular to the triangle the verticies form. Sometimes there are duplicated verticies becouse of unique normal but shared position, take for example a cube- a corner vertex has one position but three distinct normals, each perpendicular to one of the shared triangles, thus you have multiple verticies to conform multiple distinct triangles, they just have a common position.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 10
• 15
• 22
• 19
• 46