[Numpy-discussion] Interleaved Arrays and
Mon Jun 15 03:41:03 CDT 2009
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
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):
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...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion