[PyOpenGL-Users] best way to set up matrices and vertex arrays?
Brought to you by:
mcfletch
|
From: Kolja K. <kol...@av...> - 2010-03-09 11:10:35
|
Hi all,
I've recently discovered PyOpenGL and am quite happy with this package
(kudos to the authors!). It's just great for prototyping on different
platforms. I keep struggling with how I should best represent vertex
data and matrices, though. Here are some of my favorite problems:
- Row-major vs. column-major matrices. With the default
row-major layout used by numpy, I always have to pass in matrices as the
transpose of what I expect. I found out I can create numpy arrays with
'F' order, but I still have to transpose matrices I get back from
PyOpenGL, it seems.
- What's a good way to build a dynamically growing vertex
array? Sort of the equivalent of a std::vector<Vec3f> in C++, with
struct Vec3f { float p[3]; }. Currently, I am setting up an array with
shape(n,3) and concatenate another array of length 3 to it. It looks
horrible in code (sorry, I can't remember the syntax right now), and I
believe it's always making a copy.
- My hope was to avoid having to do my own 3D-vector- and
matrix-classes for doing linear algebra, and just use numpy's abilities.
It turns out that this is not always so effortless - e.g. to multiply a
matrix with a vector from the right, I have to make sure it's a column
vector. To transform a 3D vector with a 4x4 matrix, I have to append an
extra 1.0 element, do the multiplication, and then slice off the 4th
element again. Looks like it would be cleaner to write out the whole
matrix/vector multiplication by hand.
Does anyone here have some advice for me on these matters? Maybe I am
just missing "the obvious way" to organize these things.
Thanks,
-Kolja
|