Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

4D Snake

Name: Anonymous 2012-01-04 5:45

Hi /prog/

I'm trying to define a polygon, inside the polygon I have a vertexes array, a edges array and a faces array.

edges contains the indexes of the vertexes array of the two points connected.

something like this:


std::vector<vertex> vertexes;

std::vector<edge> edges;

typedef std::vector<edge>::const_iterator cEdgeIt;
void render_edges(Polygon p){
   for(cEdgeIt = p.edges.begin(); cEdgeIt != p.edges.end(); ++cEdgeIt){
       edge e = *cEdgeIt;
       vertex1 = vertexes[e[0]];
       vertex2 = vertexes[e[1]];
       drawLine(vertex1, vertex2);
   }
}


now this works fine, but if I order the vertex array, I mess up with the edges, and will be really complicated to restore all the indexes...
is it Possible to make an edge like a reference for a vertex? Like a pointer to the vertex in the vertex array?

Name: Anonymous 2012-01-04 5:57

no it is not possible.

Name: Anonymous 2012-01-04 6:02

The plural of vertex is vertices, and for index it's indices.

Name: Anonymous 2012-01-04 6:12

>>3
>The plural of vertex is vertices, and for index it's indices.
Thx! I will change the code accordingly in future!


class Edge{
private:
    std::vector<V3 const*> vertexes;
public:
    Edge(V3 const& v1, V3 const& v2);
    Edge(int v1i, int v2i, std::vector<V3> const& vertexes_array);
   
    V3 const& operator[](int index) const;
};



Edge::Edge(V3 const& v1, V3 const& v2){
    vertexes.push_back(&v1);
    vertexes.push_back(&v2);
}

Edge::Edge(int v1i, int v2i, std::vector<V3> const& vertexes_array){
    vertexes.push_back(& vertexes_array[v1i]);
    vertexes.push_back(& vertexes_array[v2i]);
}


V3 const& Edge::operator[](int index) const{
    return *vertexes[index];
}


btw this works... but if the vector<vertices> reallocate I loose the references right?

Name: Anonymous 2012-01-04 6:13

>>2
no it is not possible.
Correction:  It is only possible with Haskell.

Name: Anonymous 2012-01-04 6:33

Here is one method:

struct vertex {
  int x;
  int y;
  int z;
};

struct vertex vertex_array[N];

struct edge {
  unsigned int vertex_index_1;
  unsigned int vertex_index_2;
};

struct edge edge_array[N];

struct face {
  int number_of_vertices;
  int* vertex_indecies;
};

You can have your vertices in one array, and then your shapes can specify what vertices compose themselves by specifying indecies into the array.

Name: Anonymous 2012-01-04 6:51

>>6
this has the problem of my previous thing... if I order the vertices array... all the indexes will be messed up...

Name: Anonymous 2012-01-04 7:58



struct vertex {
 
  int RelocatedTo; //Dense mapping
 
  int x;
  int y;
  int z;
};

Don't change these.
Name: Email:
Entire Thread Thread List