[Numpy-discussion] Interleaved Arrays and
Ian Mallett
geometrian at gmail.com
Mon Jun 15 04:41:03 EDT 2009
Hi,
So I'm trying to get a certain sort of 3D terrain working in PyOpenGL. The
idea is to get vertex buffer objects to draw a simple 2D plane comprised of
many flat polygons, and use a vertex shader to deform that with a heightmap
and map that on a sphere.
I've managed to do this with a grid (simple points), making the vertex
buffer object:
threedimensionalgrid = dstack(mgrid[0:size,0:size,0:1])/float(size-1)
twodimensionalgrid = threedimensionalgrid.reshape(self.size_squared,3)
floattwodimensionalgrid = array(twodimensionalgrid,"f")
self.vertex_vbo = vbo.VBO(floattwodimensionalgrid)
However, landscapes tend to be, um, solid :D So, the landscape needs to be
drawn as quads or triangles.
Strips of triangles will be most effective, and the data must be specified
to vbo.VBO() in a certain way:
n = #blah
testlist = []
for x in xrange(n):
for y in xrange(n):
testlist.append([x,y])
testlist.append([x+1,y])
If "testlist" is an array (i.e., I could go: "array(testlist)"), it works
nicely. However, my Python method is certainly improveable with numpy. I
suspect the best way is interleaving the arrays [x,y->yn] and
[x+1,y->yn] ntimes, but I couldn't figure out how to do that...
Help?
Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090615/ca1e1e24/attachment.html>
More information about the NumPy-Discussion
mailing list