Hi All,
I m a new member here.I am now writing a program that render Vertex Normals.I m now trying to implement a data structure that will best suit computing vertex normals.For that computation , my data structure should have accessed to the faces adjacent to each vertices.
first i read all vertices ,and faces from .m file into a structure.And stored in vectors.
vector<Vertex> vertices;
vector<Face> faces;
Then i render that model.No error and problem till now.
After that i created "poly" vector to store the faces adjacent to each vertices.
vector<Polygon> poly;
For all vertices,I find the faces that share a vertex and stored in poly.Following is the code i wrote for this.
[code=cpp]
//to search faces that share a vertex
for (int i =0; i <(int)vertices. size(); i++)//loop1
{
int s=0;
Polygon polygon;
Face face;
Vertex vertex;
vertex=vertices .at(i);
polygon.inciden t=0;
vertex.Incident =0;
for (int j = 0; j < (int)faces.size (); j ++)//loop2
{
if(faces[j].v1==vertices[i].vertexid )
{
face=faces.at(j );
//vertex=vertices .at(i);
polygon.faceid= face.faceid;
polygon.v2=face .v1;
polygon.v1=face .v2;
polygon.v3=face .v3;
polygon.v2x=ver tex.x;
polygon.v2y=ver tex.y;
polygon.v2z=ver tex.z;
for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
{ vertex=vertices .at(k);
if(faces[j].v2==vertices[k].vertexid )
{
polygon.v1x=ver tex.x;
polygon.v1y=ver tex.y;
polygon.v1z=ver tex.z;
}
if(faces[j].v3==vertices[k].vertexid )
{
polygon.v3x=ver tex.x;
polygon.v3y=ver tex.y;
polygon.v3z=ver tex.z;
}
}//loop 3
s++;
}
else if(faces[j].v2==vertices[i].vertexid )
{
face=faces.at(j );
//vertex=vertices .at(i);
polygon.faceid= faces[j].faceid;
polygon.v2=face s[j].v2;
polygon.v1=face s[j].v1;
polygon.v3=face s[j].v3;
polygon.v2x=ver tices[i].x;
polygon.v2y=ver tices[i].y;
polygon.v2z=ver tices[i].z;
for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
{
vertex=vertices .at(k);
if(faces[j].v1==vertices[k].vertexid )
{
polygon.v1x=ver tex.x;
polygon.v1y=ver tex.y;
polygon.v1z=ver tex.z;
}
if(faces[j].v3==vertices[k].vertexid )
{
polygon.v3x=ver tex.x;
polygon.v3y=ver tex.y;
polygon.v3z=ver tex.z;
}
}//loop 3
s++;
}
else if(faces[j].v3==vertices[i].vertexid )
{
face=faces.at(j );
//vertex=vertices .at(i);
polygon.faceid= faces[j].faceid;
polygon.v2=face s[j].v3;
polygon.v1=face s[j].v1;
polygon.v3=face s[j].v2;
polygon.v2x=ver tices[i].x;
polygon.v2y=ver tices[i].y;
polygon.v2z=ver tices[i].z;
for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
{
vertex=vertices .at(k);
if(faces[j].v1==vertices[k].vertexid )
{
polygon.v1x=ver tex.x;
polygon.v1y=ver tex.y;
polygon.v1z=ver tex.z;
}
if(faces[j].v2==vertices[k].vertexid )
{
polygon.v3x=ver tex.x;
polygon.v3y=ver tex.y;
polygon.v3z=ver tex.z;
}
}//loop 3
s++;
}//else if
}//loop2
polygon.inciden t=s;//no of adjacent faces per vertex
//cout<<"before vertex pointer"<<verte x.vp<<"\n";
vertex.vp=&poly ;
vertices[i]=vertex;
}//loop1
//
} [/code]
After that the model disappered.I m not familiar with the usage of vectors.Definit ely something wrong in using vector or something else.So please help me.
Thanks in advance.
I m a new member here.I am now writing a program that render Vertex Normals.I m now trying to implement a data structure that will best suit computing vertex normals.For that computation , my data structure should have accessed to the faces adjacent to each vertices.
first i read all vertices ,and faces from .m file into a structure.And stored in vectors.
vector<Vertex> vertices;
vector<Face> faces;
Then i render that model.No error and problem till now.
After that i created "poly" vector to store the faces adjacent to each vertices.
vector<Polygon> poly;
For all vertices,I find the faces that share a vertex and stored in poly.Following is the code i wrote for this.
[code=cpp]
//to search faces that share a vertex
for (int i =0; i <(int)vertices. size(); i++)//loop1
{
int s=0;
Polygon polygon;
Face face;
Vertex vertex;
vertex=vertices .at(i);
polygon.inciden t=0;
vertex.Incident =0;
for (int j = 0; j < (int)faces.size (); j ++)//loop2
{
if(faces[j].v1==vertices[i].vertexid )
{
face=faces.at(j );
//vertex=vertices .at(i);
polygon.faceid= face.faceid;
polygon.v2=face .v1;
polygon.v1=face .v2;
polygon.v3=face .v3;
polygon.v2x=ver tex.x;
polygon.v2y=ver tex.y;
polygon.v2z=ver tex.z;
for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
{ vertex=vertices .at(k);
if(faces[j].v2==vertices[k].vertexid )
{
polygon.v1x=ver tex.x;
polygon.v1y=ver tex.y;
polygon.v1z=ver tex.z;
}
if(faces[j].v3==vertices[k].vertexid )
{
polygon.v3x=ver tex.x;
polygon.v3y=ver tex.y;
polygon.v3z=ver tex.z;
}
}//loop 3
s++;
}
else if(faces[j].v2==vertices[i].vertexid )
{
face=faces.at(j );
//vertex=vertices .at(i);
polygon.faceid= faces[j].faceid;
polygon.v2=face s[j].v2;
polygon.v1=face s[j].v1;
polygon.v3=face s[j].v3;
polygon.v2x=ver tices[i].x;
polygon.v2y=ver tices[i].y;
polygon.v2z=ver tices[i].z;
for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
{
vertex=vertices .at(k);
if(faces[j].v1==vertices[k].vertexid )
{
polygon.v1x=ver tex.x;
polygon.v1y=ver tex.y;
polygon.v1z=ver tex.z;
}
if(faces[j].v3==vertices[k].vertexid )
{
polygon.v3x=ver tex.x;
polygon.v3y=ver tex.y;
polygon.v3z=ver tex.z;
}
}//loop 3
s++;
}
else if(faces[j].v3==vertices[i].vertexid )
{
face=faces.at(j );
//vertex=vertices .at(i);
polygon.faceid= faces[j].faceid;
polygon.v2=face s[j].v3;
polygon.v1=face s[j].v1;
polygon.v3=face s[j].v2;
polygon.v2x=ver tices[i].x;
polygon.v2y=ver tices[i].y;
polygon.v2z=ver tices[i].z;
for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
{
vertex=vertices .at(k);
if(faces[j].v1==vertices[k].vertexid )
{
polygon.v1x=ver tex.x;
polygon.v1y=ver tex.y;
polygon.v1z=ver tex.z;
}
if(faces[j].v2==vertices[k].vertexid )
{
polygon.v3x=ver tex.x;
polygon.v3y=ver tex.y;
polygon.v3z=ver tex.z;
}
}//loop 3
s++;
}//else if
}//loop2
polygon.inciden t=s;//no of adjacent faces per vertex
//cout<<"before vertex pointer"<<verte x.vp<<"\n";
vertex.vp=&poly ;
vertices[i]=vertex;
}//loop1
//
} [/code]
After that the model disappered.I m not familiar with the usage of vectors.Definit ely something wrong in using vector or something else.So please help me.
Thanks in advance.
Comment