【发布时间】:2016-07-06 11:40:02
【问题描述】:
我有这个网格类,它有 3 个 ArrayList:顶点、边、面,但我找不到以正确方式绘制它们的方法。我希望背面的顶点和边缘通过我的相机前面的面不可见。就像我有一个立方体一样,我希望面向相机的顶点、边和面可见,其余的不应该。
我不知道这是否足够清楚,我只是作为练习来了解更多关于 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
【问题讨论】: