我有這個網格類,它有3個ArrayLists:頂點,邊,面,但我找不到一種方法來以正確的方式繪製它們。我希望背部的頂點和邊緣不能通過相機前面的臉部看到。就像我擁有一個立方體一樣,我希望頂點,面對相機的邊和麪都是可見的,其他的不應該是。繪製多個對象的Opengl es
我不知道這是否足夠清晰,我只是在做這個練習來了解更多關於OpenGL ES的知識。
如果還有另一種方法來處理網格使用頂點,邊和臉作爲類請幫助。謝謝。
這裏是我的目類代碼:
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