Matrix Maths Tools

I think I may tackle this myself, as a first QC Plugin project once my Cocoa programming book has arrived and I've worked my way through it.

I'm thinking of a set of tools to do Matrix manipulation (mainly multiplication) outside a GLSL Shader. I'd envisage it taking in 2 or more structures and outputting a result, probably as another structure.

I'm imagining it might be nice to be able to do this kind of thing per-frame, or in fact, only when needed, rather than having to do a similar job per-vertex in a shader. I'm also thinking maybe I can take advantage of OpenGLs Matrix maths tools.

Doable? Useful?

alx

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
matrix reloaded

this is totally doable (you could even do it with math patches or javascript, though it'd be more expensive that way). It's possible to make patches that only work when inputs change -- this is how kineme3d works, as well as the texture patches and a few others (the JS patch too).

To really flesh it out (second system effect!), having generalized math functions available would be really slick (ala gmp, lapack, arpack, etc) -- gmp's for arbitrarily large numbers along with handy functions, lapack handles linear algebra, arpack for systems of equations, etc.

in a more realistic scope, generalized matrix multiplication (compiled code, not interpreted/parsed stuff) would actually be useful for a few people who are operating QC in 3D environments. The other stuff is likely to be overkill for now ;)

toneburst's picture
I'm just putting together a

I'm just putting together a JS patch to create a single matrix incorporating rotation/translation/scaling on all 3 axes. It's actually working pretty well, but I much prefer the idea of having a nice simple plugin that handles all this stuff 'behind the scenes'.

I don't really wanna have to deal with 150-odd lines of code when I could do the same thing with none! Actually, I'd imagine the code for the plugin to do matrix multiplication would probably not be much longer than the JavaScript to do the same thing in QC! .. and massively more efficient, I imagine.

alx

Quartz Composer Blog: http://machinesdontcare.wordpress.com

Music Site: http://www.toneburst.net

toneburst's picture
:)

Agreed. Just wondering if it would be possible to use OpenGL matrix tools in a plugin that outputs just numerical values, rather than rendering something... I guess if so, that means matrix manipulation patches could be GPU-accelerated....

I'm also wondering if it would be worth creating a 'toolkit' of different basic matrix manipulation tools, which could be connected together with structure in/out ports. For the little project I'm currently tinkering with, for example, I need to create matrices for rotation, and also I need to invert a couple of matrices, and subtract one matrix from another. I can see a nice selection of individual matrix tools, + a 'float to matrix' and a 'matrix to float' patch would be pretty useful. Might make a good addition to the Kineme GL Tools set, too.

Do you think it's worth me jumping in and trying to knock something like this together using the official QC plugin API?

Any thoughts?

alx

Quartz Composer Blog: http://machinesdontcare.wordpress.com

Music Site: http://www.toneburst.net

tobyspark's picture
do it.

...come round one night and we could have a go getting you started?

toby

toneburst's picture
Cool

that sounds like a good idea, toby. Sounds like good little QC plugin starter project, I think.

alx

Quartz Composer Blog: http://machinesdontcare.wordpress.com

Music Site: http://www.toneburst.net

cwright's picture
++

unless you're able to chain together several matrix ops at once (multiply, add, invert, etc), doing them on with opengl probably won't be much faster because of the setup time (having to save the current matrix, load your data, perform the operation(s), download the results, upload the original data...). Doing 4x4 math in software won't be tremendously expensive (you could probably do millions of transforms or more on the CPU without a significant performance hit; Intel GPUs don't have hardware T&L, so it's done in software anyway and doing 6 million polys per frame (18million vertex transformations) is a walk in the park.

This is totally worth getting your feet wet with; nothing too insane (structure manipulation is a bit tricky, but you're not dealing with textures, or maintaining internals states, or anything too difficult), and a fair amount of challenge to push your limits if you're just starting out. It would also work well in Kineme GLTools, so if you'd like, I can graft that in once your done (or, we can race ;).

This would be well-suited for either the official or unofficial API I believe. Jump in, and keep us posted :)

toneburst's picture
Ah, OK. I still think it

Ah, OK.

I still think it would be faster to do it matrix manipulation with some kind of Cocoa-based plugin than in JavaScript though. Most of the code in my JS matrix plugin was just so it can deal with matrices at all. If Objective C has builtin tools for doing matrix maths, I've got no problem using these in a plugin, rather than OpenGL.

alx

Quartz Composer Blog: http://machinesdontcare.wordpress.com

Music Site: http://www.toneburst.net

cwright's picture
no tools :(

C and objC don't have matrix operators, unfortunately. that's ok though, the operations are typically pretty straight forward, and can be found in C or pseudo-C all over the internet.

toneburst's picture
Definitions Vary

Ah, but we already know that our definitions of 'straightforward' in the context of programming vary considerably ;)

alx

Quartz Composer Blog: http://machinesdontcare.wordpress.com

Music Site: http://www.toneburst.net

cwright's picture
++

... good point. I stand corrected :)