Jump to content
  • Advertisement
Sign in to follow this  
broady

vertices and faces [opengl but even no]

This topic is 3610 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

Hello guys, i have to write some code to manage a generic net on a 2D plain. This net is composed of vertices and faces; the faces link the vertices. When N faces "point" one the same vertex, this vertex has to be stored just 1 time. This stuff to say that vertices and faces have to be stored independently and in some way i have to create some kind of link that relate vertices to faces. I was obviusly thinking to a Vertex class which stores the x and y coords for the vertex. What's the face class for me? It should say just if 2 vertices are linked or no, i think. What's the best way to reach the goal? What do you think? Thanks Bro

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure whether we actually mean the same, so I want to introduce some terms first. In computer graphics, a surface representation consisting of discrete supporting points with connections is normally called a mesh. The supporting points have a location in space, but can also have other geometric attributes and also non-geometric attributes (e.g. colors); they are called vertices. 2 vertices are connected by edges, what most often are straight lines (whether they are given explicit or implicit, and whether they are rendered or not is another question). A face is (normally a flat) area piece of the surface.

So, a vertex is 0-dimensional, an edge 1-dimensional, and a face 2-dimensional. A face can be described by a sequence of its corners, obviously relating directly to vertices, or else as a sequence of (orientated) edges. As such, a face described by only 2 vertices (as suggested in the OP) would be senseless. Instead, faces have to show at least 3 vertices (or edges). The elements form a closed loop which interior is filled by the face. Nevertheless, those vertices may be aligned on a line (or the edges may be co-linear), so that the face is degenerated, i.e. its 2nd dimension is disappeared and so it has an area of 0. But that obviously isn't the general case (although such faces are useful sometimes).

In computer graphics, faces are often also restricted to 3 corners building a triangle. That has the advantage of being simple and uniquely defined. More corners (e.g. quadrangles) are of course possible may need to be explicitely enforced to be flat and sometimes also convex, or else tesselation problems may occur. Flatness isn't your problem actually since you're working in 2D, but you still would have to deal with convexity / concavity.

Whether you're happy with a pure top-down structure (i.e. faces refer to the used vertices), and whether you would be more convenient with explicit edges depends on you specific needs. Standard meshes for rendering only
* are build purely of triangles,
* have no face adjacency information stored explicitely,
* have faces refering to their corner vertices, and
* does not store edges explicitely.
Vertex and face normals are no issue here since you're working in 2D (assuming the normals simply ever point outward w.r.t the plane) and hence need not be stored at all.

Share this post


Link to post
Share on other sites
hey haegarr,

thank you so much for your reply. I had some confusion with terms yes, now it's clear. Moreover i didn't khnow there is a lot of material on the mesh topic. Googling i found good topics about data structures for this mesh. As i have been suggested ill try to use the node/face structure.

I am going now cu this night
Bro :D

Share this post


Link to post
Share on other sites
Quote:
Original post by broady
...Moreover i didn't khnow there is a lot of material on the mesh topic. Googling i found good topics about data structures for this mesh...

Oh yes, there is plenty of stuff available about meshes. On the other hand, it may produce even more confusion. You have to bear in mind for which purposes you design your mesh structure(s). A high performance rendering mesh should be close to OpenGL's VBOs or D3D's equivalent of them. A mesh suitable for interactive editing has different requirements, and a VBO friendly representation is normally not well suited for them. Animated meshes may introduce their own requirements, too.

I suggest you to inform yourself about several structures, but to revise them thoroughly w.r.t. your individual needs.

Share this post


Link to post
Share on other sites
Quote:
Original post by broady
When N faces "point" one the same vertex, this vertex has to be stored just 1 time. This stuff to say that vertices and faces have to be stored independently and in some way i have to create some kind of link that relate vertices to faces.
In OpenGL or D3D, you would accomplish this using "indexed triangles". As you described, you maintain 2 buffers, one for the vertices (x, y pairs), and one for the indices. Indices are just integers, which hold the offset into the vertex array of an individual vertex. For each triangle, you place the indices of that triangle's 3 vertices into the vertex array. When you render, the graphics API uses the indices to form triangles from the vertex buffer.

This typically saves a lot of space over storing duplicate vertices, and it also allows the graphics API to perform several optimisations (mainly caching).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!