开发者

Storing OpenGL ES Polygon and Vertex info

I'm working on a simple modelling program concept for Android, and I've come into a bit of a problem.

Basically, I keep Vertex and Polygon info in Java Vectors (I need this info for manipulating them, not drawing them).

For drawing I'm using VBO's.

Each polygon currently has a list of vertices that it is made of. That means that when the indice array is populated, I need to find out what index each vertex has, 开发者_开发技巧and those indexes can change if vertices are created or deleted.

I quickly coded this using the indexOf(Vertex v) method of the Java Vector, but obviously this is very slow and I'm wondering what is the best way of managing this so that it doesn't take too much processing?

Thank you in advance.


First off, a quick fix that will improve performance a tiny bit: Use ArrayList instead of Vector - you probably don't require the synchronisation overhead.

The main issue is that you are recalculating the whole index array on every vertex array change. Currently you need to do this because if you delete a vertex, the index of every vertex after the deleted one in the list changes. Thus the key is to minimise changes to vertex indices, allowing you to easily maintain the index array rather than completely recalculating it. So: instead of using list.remove() to remove a vertex, replace it with the vertex at the end of the list. This way there is only one index that has changed, and so it'll be super-quick to iterate through your index array and substitute the new value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜