I have this mesh class, which has 3 ArrayLists: vertices, edges, faces, but I can't find a way to draw them in a correct way. I want the vertices and the edges on the back not to be visible through the faces in front of my camera. Like if I have a cube I want the vertices, edges and faces that are facing the camera to be visible, the rest should be not.
I don't know if this is clear enough and I'm just doing this as an exercise to learn more about OpenGL ES.
If there's another way to deal with a meshes using vertex, edge and a face as classes please help. Thanks.
Here is my mesh class code:
public class Mesh {
protected ArrayList<Vertex> vertices;
protected ArrayList<Edge> edges;
protected ArrayList<Triangle> triangles;
public Vector Pos;
public float rx,ry,rz;
public float r,g,b,alfa;
private boolean colorSet;
private static boolean vertexOn,edgeOn,FaceOn;
Mesh()
{
Pos=new Vector();
vertices=new ArrayList<Vertex>();
edges=new ArrayList<Edge>();
triangles=new ArrayList<Triangle>();
r=g=b=0; alfa=1;
colorSet=false;
vertexOn=true;
edgeOn=true;
FaceOn=true;
}
Mesh(Vector pos)
{
Pos=pos;
vertices=new ArrayList<Vertex>();
edges=new ArrayList<Edge>();
triangles=new ArrayList<Triangle>();
r=g=b=0; alfa=1;
colorSet=false;
vertexOn=true;
edgeOn=true;
FaceOn=true;
}
public void add(Vertex v)
{
vertices.add(v);
}
public void add(Edge e)
{
edges.add(e);
}
public void add(Triangle t)
{
triangles.add(t);
}
public static void setOn(boolean v,boolean e,boolean f)
{
vertexOn=v; edgeOn=e; FaceOn=f;
}
public void setColor(float r,float g,float b,float alfa)
{
colorSet=true;
this.r=r; this.g=g; this.b=b; this.alfa=alfa;
}
public ArrayList<Vertex> getVertices()
{
return vertices;
}
public ArrayList<Edge> getEdges()
{
return edges;
}
public ArrayList<Triangle> getTriangls()
{
return triangles;
}
public void draw(GL10 gl)
{
gl.glPushMatrix();
gl.glTranslatef(Pos.x,Pos.y,Pos.z);
gl.glRotatef(rx,1,0,0);
gl.glRotatef(ry,0,1,0);
gl.glRotatef(rz,0,0,1);
if(colorSet)
{
if(vertexOn)
for(Vertex v: vertices)
{
v.setcolor(r,g,b,alfa);
v.draw(gl);
}
if(FaceOn)
for(Triangle t: triangles)
{
t.setcolor(r,g,b,alfa);
t.draw(gl);
}
if(edgeOn)
for(Edge e: edges)
{
e.setcolor(r,b,g,alfa);
e.draw(gl);
}
}//if a single color is set for the whole mesh with edges and vertices
else
{
if(vertexOn)
for(Vertex v: vertices)
{
v.draw(gl);
}
if(FaceOn)
for(Triangle t: triangles)
{
t.draw(gl);
}
if(edgeOn)
for(Edge e: edges)
{
e.draw(gl);
}
}//if no color for the whole mesh has been set
gl.glPopMatrix();
}//Draw
}//class