quaternion trackball (Composition by dust)

Author: dust
License: (unknown)
Date: 2009.10.10
Compatibility: 10.6
Categories:
Required plugins:
(none)

so i put together some vector math functions, people might find useful. i have made them into macros. i also made an example. in this example im taking x,y point data from the mouse patch and using some euler and quaternion functions to make a trackball with the xyz rotations exposed. i like the trackball but there are no parameters exposed so i thought if i built a trackball with the rotations exposed it might prove useful for people.

PreviewAttachmentSize
vectors.qtz89.45 KB
units2pixX.qtz1.78 KB
units2pixY.qtz1.78 KB
Quartz Composer Patches copy.zip56.36 KB

dust's picture
Re: quaternion trackball (Composition by dust)

im working on converting all these functions to open cl as well which should be faster although im not really sure the trackball needs to be any faster. its a learning experience for me so i will post the cl functions as well.

usefuldesign.au's picture
Re: quaternion trackball (Composition by dust)

Good idea. I've often considered how would I accomplish this task (Trackball that can also be computationally driven). Given I only know trig (not euler and quaternion) it's a good thing you tackled it not me. I guess this is 10.6 only unless I rebuild from the individual files. Can't see the master composition in the screenshot though, it's to low-res to copy from. One more reason to buy a MacBookPro and get with SL; I've been watching ebay all week!

Thanks for sharing , Dust.

dust's picture
Re: quaternion trackball (Composition by dust)

here is zoomed in screen shot of how to hook up a trackball. i think everything should be leopard safe. you might have to use the macro source and make clips from them in qc3, then hook them together like the screen shot.

oh the angle input for the quaternionFromAxisAndAngle function macro needs this expression. just put it into a math expression and hook up the dx,dy in qc units with math exp "atan2(abs(dx), abs(dy))."

i basically took apples trackball.m example and a made bunch of macros from their vector functions. then i just hooked up a few of them to do a trackball. i tried copying apples cg implementations to qc implementations, but they where very confusing. so i just strung together my own.

i feel yah the quaternion looked pretty complex on wikipedia. i find it easier to read in C than in regular math notations because well i haven't taken any math classes besides logic and predicate calculus. i guess computer science counts as math, so for those assignments i learn just what i need to do my homework. there are a few classes i want to take but they require calculus and discrete math so i might have to take those, which will be nice to be able to actually visualize that kind of math in my head.

actually all these quaternion functions don't require anything but basic arithmetic like multiplication addition subtraction etc... and a few expressions. actually the hypot(x,y) function i think is trig. couldn't find an expression for hypotenuse but my php book says it can be calculated with square roots, so thats how i made that function in qc.

i actually really only used the quaternionFromAxisAndAngle function for the trackball. apple uses all of them so i figured someone that actually knows more about vector math could use these macros for something. it seems apple is using them for a reason. plus i think the distance calculations and stuff like that i can use for my multi-touch class.

anyways here is the screen shot so you can hook up a trackball in qc3.

[edit] i guess i forgot to include the mouse in the screen shot... the math expression takes xy in qc units but the quaternionFromAxisAndAngle function take the mouse xy in pixels. im not sure if qc3 has the converter so here is apples macro for units 2 pixels. actually now that im looking at it it only seems to be units to pixels for x. i guess you'll want to make one for y as well. good thing i looked at that. got to make an edit of this qc file cause that will be messing up my y a tiny bit. good thing i just looked.

PreviewAttachmentSize
Screen shot 2009-10-10 at 8.50.45 PM.png
Screen shot 2009-10-10 at 8.50.45 PM.png157.47 KB
units2pix.qtz2.17 KB

dust's picture
Re: quaternion trackball (Composition by dust)

so i have just updated the trackball. apparently apples units to pixel macro is only for x coordinates so i have included a new macro for x and y. just visit the composition front page for revised files. now the trackball works even better.

toneburst's picture
Re: quaternion trackball (Composition by dust)

Great work, man!!!

Funnily enough, I was about to attempt something like this myself. Glad you beat me to it though- I'm sure you made a much better job of it than I would have.

a|x

toneburst's picture
Re: quaternion trackball (Composition by dust)

Just downloaded your zip and noticed there's one of mine in there (tb_soundFlower.qtz). Don't want to sound like a b*stard here, but it's nice to ask permission before redistributing stuff other people have made. I'm sure it was an oversight though.

a|x

dust's picture
Re: quaternion trackball (Composition by dust)

most defiantly an oversight as that macro has nothing to do with the track ball. i think one day i was using it to visualize touches with martins tuio plugin and forgot about them in my macro folder. i actually use your macros and clips frequently, which i am very grateful for. i will re upload the macro folder right now.

actually i am using your tb_dirty monochrome red channel as of late, for a haar sample creating utility i'm making for cv_tools. this is so people can make there own classifiers to use with object detection. i would like to share it someday when its finished. im not entirely certain how your open source stuff works so i'm asking permission. i don't think it would be posted anywhere but on kineme, maybe on my blog, which i have been meaning to update.

cybero's picture
Re: quaternion trackball (Composition by dust)

Humungous collection of macros , dust - all very useful.

cybero's picture
Re: quaternion trackball (Composition by dust)

Thanks for the explanation of how you arrived at this published collection. Informative

cybero's picture
Re: quaternion trackball (Composition by dust)

I really like the way that clips and patches get sorted in the Library window, makes life much easier for figuring out what's what and wherefrom it came , although the tb_ always was a decent enough clue to begin with in QC3 in regards of your clips, toneburst :-) .

toneburst's picture
Re: quaternion trackball (Composition by dust)

cybero wrote:
...although the tb_ always was a decent enough clue to begin with in QC3 in regards of your clips, toneburst :-) .

Heehee. True. Well, I have to assert ownership somehow ;)

a|x

dust's picture
Re: quaternion trackball (Composition by dust)

i was hoping they would be useful. they where made to be used in the trackball context but i'm sure they can be used in other contexts as well. im still trying to get these all working in open cl. it seems there is a wide variety of built in vector functions like "cross products" etc... in open cl. at least with this implementation people can use them in qc3 etc..

bernardo's picture
Re: quaternion trackball (Composition by dust)

could you please port this to 10.5 leopard... please thanks dust bern

bernardo's picture
Re: quaternion trackball (Composition by dust)

Please port this to Leopard as i get this error:

(null) : Patch with name "/vec3" is missing

Macro Patch Cannot create node of class "/vec3" and identifier "(null)"

(null) : Patch with name "/normalize" is missing

Macro Patch Cannot create node of class "/normalize" and identifier "(null)"

Macro Patch Cannot create connection from ["y_1" @ "Patch_1"] to ["yCoordinate" @ "Expression_4"]

Macro Patch Cannot create connection from ["x_1" @ "Patch_1"] to ["inputValue" @ "Math_1"]

Macro Patch Cannot create connection from ["outputResult" @ "Expression_4"] to ["Z" @ "Patch_2"]

Macro Patch Cannot create connection from ["outputValue" @ "Math_1"] to ["X" @ "Patch_2"]

Macro Patch Cannot create connection from ["y_1" @ "Patch_1"] to ["inputValue" @ "Math_2"]

Macro Patch Cannot create connection from ["outputValue" @ "Math_2"] to ["Y" @ "Patch_2"]

Macro Patch Cannot create connection from ["x_1" @ "Patch_1"] to ["xCoordinate" @ "Expression_4"]

Macro Patch Cannot publish input port ["x" @ "Patch_1"]

Macro Patch Cannot publish input port ["y" @ "Patch_1"]

Macro Patch Cannot publish output port ["z" @ "Patch_2"]

(null) State restoration failed on

and i cant open anything else.... or expose the patch "2d bounds to 3d point" and the "quaternionFromAxisAndAngle" ยด thanks alot bern

bernardo's picture
Re: quaternion trackball (Composition by dust)

can anyone help please?!?!?!?!

cybero's picture
Re: quaternion trackball (Composition by dust)

Virtual Macros won't work in Leopard - that's why the Quartz Composer patches zip file contents provoke such messages when you try to open those .qtz that are really just waiting to ask to be installed into a QC4 environment.

Other custom patches within any open and editable QC file you can just select and add them to your Library.

If you can't open the file, you can't edit it and you therefore can't select the custom patches.

Hope that's clearer.

As for porting the sort of functionality that is wrapped up in this newer kind of macro patch, probably could be done.

bernardo's picture
Re: quaternion trackball (Composition by dust)

thanks cybero it was kinda what i was looking for... i was wondering if can anyone can post the insides of the patchs i said before because i am porting it to leopard anyway and i get a weird behavior in the process of converting to quaternions. thank alot. bern

dust's picture
Re: quaternion trackball (Composition by dust)

so i will see if i can port this to 10.5 actually my backup drive went down and unfortunately my dvd burner has never worked on my new computer, so me being lazy about fixing not wanting to let my new computer go for a week has lost all my files. so im looking at this trying to get some of my files back from my web server and this repository. sucks cause i amassed a great collection of kineme forum samples from various users so im just re downloading these files. not entirely sure how to re factor this to 10.5 seeing the clips vs library thing in one shot.

you can however open the individual patches and make them clips then add them together like the screen shot. should work. sorry my time machine went down, after i did a re install of my system so i literally have to re build my development machine. the seagate firewire external i was using was sold to me with life time warranty but i don't think the warranty covers the data on my drive. my drive has dropped many times but for what ever reason i unplugged the power strip it was on while i was watching a movie file from the drive and now it is like stuck or something. its been two days im almost done morning the loss of my data.

im going to see about getting some of the data back or saying f it and getting a new drive replacement.

try making clips of the patches and if that doesn't work i will see what i can do.

bernardo's picture
Re: quaternion trackball (Composition by dust)

thanks dust for the effort i cant see where i am failing but i can't make this clips work there is allways something missing inside them.

i would definitly need your help... i guess.

if it is not to much for an inconvinience...

hugs bern and lets hope for the best for your hard drive...

itsthejayj's picture
Re: quaternion trackball (Composition by dust)

So if i have a Roll, Pitch and Yaw how do I translate this into rotX, rotY, rotZ for a 3d transform ? Getting a tad confused here. :(

cybero's picture
Re: quaternion trackball (Composition by dust)

This might help you - if you haven't already seen it ..

http://kineme.net/forum/Discussion/DevelopingCompositions/euleranglesmatrix

Unfortunately the Matrix to Params patch no longer is at the URL referenced in the thread.

QC Coordinates X,Y,Z

X axis - horizontal Y axis - vertical Z axis - out from screen [bigger] and into screen [smaller]

Roll - Clockwise or Anti Clockwise Pitch - Up and Down Yaw - Left and Right

Don't you find that the example in vectors_0.qtz does a lot of that footwork for you?

Certainly does the pitch and yaw.

Perhaps one could input the roll that needs to be applied directly upon the object so that it seems to roll either clockwise or anticlockwise. Perhaps I'm misunderstanding something here ... Getting that roll programatically and smoothly enabled is a different matter. Find attached an approximate , quick and dirty hack, built upon the vectors_o.qtz exemplar from dust.

PreviewAttachmentSize
quickanddirtypry.zip327.27 KB