Jump to content
  • Advertisement
SR D

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.

Or if you know of any good links that talk about this, please post.

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

 

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!