PDA

View Full Version : take THAT you filthy quaternion


t2k
7th March 2005, 09:31 AM
I first heard about quaternions in 1997 and finally the other night at 3am developed a solid understanding of how they work and what their useful applications are in computer graphics. As a result my looping camera keyframe interpolation code finally works and I can move forward with my plans for a timeline based camera sequencer. Here's a (big) .mov to show off the first loop

(this is a 14 megabyte .mov file and it should loop seamlessly)

http://www.treyharrison.com/RadialKeyframeCam.mov

http://www.treyharrison.com/radialpreview.jpg

trey

akira_k
7th March 2005, 01:05 PM
Call me ignorant, but I don't have a clue of what you're going on about (will google later), the clip looks strange and very interesting anyway, I liked it!!

t2k
7th March 2005, 06:17 PM
A quaternion is a mathematical structure kind of like a "vector". If "vector" is a new term to you, just know that a vector is simply a set of x,y,z coordinates (and sometimes 4th coordinate w) that are used to define the location of a point in space.

Like vectors, quaternions are a set of 4 "coordinates" (x, y, z, and w) but the 4 numbers do not define a point in space, they actually define an orientation. If the term "orientation" is not clear, think of your own head as a camera and consider the way you are facing right now. There is a "front" direction that you are looking in to see the monitor, there is an "up" direction that shoots straight out the top of your head, and a "side" direction that, well, shoots straight out the side of your head, perhaps out your ear. If you combine the information about your front, up, and side directions, you have a complete "orientation". Note that if you turn left or right, your front and side directions change but your up direction stays the same. If you look up and down, your front and up directions change but your side direction stays the same. If you kind of rotate your head a few degrees clockwise or counterclockwise (dont go too far!! heheh) your up and side directions change, but your front direction stays the same.

Representing a 3d camera with computer graphics software always involves defining the camera's location in space using an x,y,z, along with the camera's orientation. The user of a 3d application usually just aims the camera interactively by panning, tilting, and rotating it with the mouse. Internally, though, the software has to represent the aim somehow, and its typically done using front,up,and side directions. The software combines the camera's location and front,up,side directions in a matrix, and then uses that matrix to transform the positions of other objects in your 3d scene into the camera's viewable space (which is certainly a necessary step if you want to draw the scene from the perspective of the camera).

Quaternions are not a requirement for the camera viewspace transform because as I've said you can do that step using matrices.

However, in most 3d rendering applications the user wants to render a sequence of frames over a period of time. To do that, the user typically defines a small number of camera positions and orientations on a track or loop, and then tells the software to move the camera along that track and through those orientations over a period of time.

The mathematical work involved in computing all of the in-between camera locations and camera orientations would take at least as much text as I've already written, and I really feel like wrapping this up, so I'll just say that for that computation to produce the smoothest most physically realistic sequence of camera movements and turns, use of quaternions is basically a requirement.

You may find some websites out there debunking the quaternion "myth" and attempting to explain how other methods of interpolating orientations can be used to achieve the same results - I know I found at least one. The problem w/the other methods though is that they are equally complicated and there seeemed to be less information about them on the web, so I went with quaternions =).

As far as that video clip is concerned, quaternions were only used to achieve the smooth panning/tilting of the camera. There are obviously several other processes going on there which are responsible for generating the weird/crazy/interesting oscillating blue torus chip thing in the middle, but those processes dont involve quaternions, mainly just basic trigonometry and matrix math.

See, doesnt it all makes sense now? :D
trey

tigital
7th March 2005, 06:22 PM
...quaternions sure are a preferred solution to 3d transforms and such: I definitely had to get into them when adding a camera object to GEM awhile back...

...but I'm more curious about the loop that you're producing: I've seen something like this done with 4d-polytopes, and a I've also seen a demo at frustum.org/3d (symmetry) which worked by reflect planes of the object as it is rotated...what are you doing in this case?

murk
7th March 2005, 06:46 PM
Did you do this with Salvation? If so, I would love to check out the patch. I have checked out Salvation on and off, but haven't done any work in it. If these type of realtime algorithms are possible, it would be a new motivating factor to check it out again.

t2k
7th March 2005, 06:59 PM
Well to start I'll just post a picture of the structure that generated the .mov:

http://www.treyharrison.com/RadialStructure.jpg

To fully explain how it works I would start at the top of this structure and point to the 3DSImport module which imports a 3d chip model, and work my way down through an explanation of each module and what it does until I get to the GLDisplay module at the end.

That'd take too long so I'll summarize and just say that the chip model is radially spread so that a circle of chips is created, then that circle is radially spread so that a torus is created. The chip models are scaled and rotated around in a few different coordinate spaces.. before forming the circle, after forming the circle, and while forming the torus.

The chips start at a scale of 0 and then get really really big to the point where they are really intersecting and overlapping. The z-buffer takes care of making sure everything is drawn depth-correct, but beyond that.. there's a rotating texturemap drawn onto the front of the chips... and a camera spinning around it all =).

trey

t2k
7th March 2005, 07:07 PM
Yes murk this was done with Salvation - pretty much all of the 3d graphics work I do from here on out is going to be incorporated into the Salvation package. I haven't released this code yet so you won't be able to do this kind of stuff with the current demo/beta, but your interest will be a motivating factor for me to spit out another build sometime this week =).

I actually was taking a little break from Salvation for the last 3 weeks while working on a videogame for Naked Sky Entertainment which is being shown this week at the Computer Game Developers conference. Theres a little bit of press about that here http://hardware.gamespot.com/Story-ST-x-1570-x-x-x
(it was shown last week at at the Intel Developer Forums)

And before that I was in Puerto Escondido on vacation (pictures here - http://www.treyharrison.com/pictures/PuertoEscondido) so I havent really had much time to work on Salvation in over a month, I'm pretty excited to sink my teeth back into it! =)

trey

akira_k
8th March 2005, 01:15 PM
Originally posted by t2k
See, doesnt it all makes sense now? :D It is more clear now, yes, thanks for that quick introduction. I do have a knowledge in mathematics, did two or 3 semi advanced courses on algebra and calculus... but it's all fuzzy now, i deleted it purposefully off my mind ;D

jaw
8th March 2005, 04:58 PM
nice to see some interresting discussions here :)

Trey, not sure if you saw this (it currently looks horrible) but i'm using quaternions in this sphere input controller in vsxu:

http://files.intra.vovoid.com/quaternion_sphere.jpg

so it simply gives me a vector i can use for rotating a camera, an object etc.
or just providing an angle for rotation. really nice whn you just wanna explore something you just built from all angles and still maintaining full speed in the production environment.

also it's super-smoothly interpolated like the rest of the controllers so it's really neat.
i have to make a module like yours as well. it's not much code really..

currently I'm working on a sequencer as parameter though. for 3d lofting stuff..

t2k
8th March 2005, 07:32 PM
Very cool jaw!

Here's another little radial spread / camera keyframe loop, this time using some vector text instead of a .3ds file

(23 megabyte looping .mov)

http://www.treyharrison.com/SalvationTorus.mov

http://www.treyharrison.com/SalvationDesktop.jpg


trey

many2
8th March 2005, 08:10 PM
Can you make dynamic 3d L-systems with Salvation ?

I love L-systems :heart:

t2k
8th March 2005, 09:00 PM
many2 - Can you share some links to some information on L-systems? With pictures, etc? If they are as loveable as you say I might have to write them in ASAP :)

trey

many2
8th March 2005, 09:26 PM
info from answers.com
http://www.answers.com/main/ntquery;jsessionid=9hquo6pbow2m?method=4&dsid=2222&dekey=L-system&gwp=8&curtab=2222_1&sbid=lc04a

Here is a link to a 2d java applet based on L-systems
http://www.javaview.de/vgp/tutor/lsystem/PaLSystem.html

A quick description from a math perspective with links to references
http://mathworld.wolfram.com/LindenmayerSystem.html

another link
http://www.stud.tu-ilmenau.de/~juhu/GX/RTEvol/DOC/LATEX2HTML/node6.html

L-systems are very useful to create 3d plants and to simulate their growth. A lot of my recent personal work is based on vegetal life and that's why I've used L-systems.

I've had a lot of fun using a beta plugin Blur Studio has made many years ago for 3ds Max - the problem is that it won't work on recent versions of 3dsMax.

A real-time 3d L-system generator would be a good addition to my VJ toolbox and would definitely inspire me to push my vegetal-based videoart a little bit further.

t2k
9th March 2005, 03:48 AM
many2,

I didn't have much luck googling for it myself but your links were pretty helpful. I think I understand the technique of generating each iteration of the shapes, it will be interesting to figure out how to smoothly arrive at each new iteration of the shapes.

Also I wonder whether there may be some more general way to apply the technique to more than just the simple "turtle" generated shapes... I'll be thinking about this for awhile =)

thanks!

trey

many2
9th March 2005, 12:18 PM
I think L-systems are a good bag of tricks for procedural 3d modelling and animation.

There are two programs I've used many years ago which I believe were based on L-systems : Organic Arts and DancerDNA.

mondo
10th March 2005, 08:26 AM
respect to you guys for working in this field and bringing programming to life to us <comparative> vegetables.

keep up the good work

;)

Nema
16th June 2006, 05:22 AM
here is an animated quaternion, rendered with the standard "julia" plugin from visualJockey, together with the "wax" plugin from the pdoom package.

http://josua.hoengermedia.ch/clips/quaternion-morph.wmv

you might also be interested in this article:

http://www.devmaster.net/forums/showthread.php?t=4448

dongbamage
16th June 2006, 11:00 AM
u wanna give us a math blast t2k?? u're magic quaternion formula, or is it trade secrets?? :D

kostya
18th June 2006, 08:16 AM
many2
How about these for L-Systems::roll: ?
http://i83.photobucket.com/albums/j307/kostyap/l7.jpg
-
http://i83.photobucket.com/albums/j307/kostyap/l4.jpg

johnnylocust
18th June 2006, 05:18 PM
That's an L-System!?!? What was that made with? The only L-Systems I've seen are those dorky dragon things.

RayV
18th June 2006, 06:53 PM
used organic arts too - it was the first app i ever toyed with
& after one whole winter i really got into it
still gutted they never made exporting feature
i wonder what those guys are doing these days
shame they have stopped develope it
[us vegies cant do much about it i guess]

kostya
18th June 2006, 07:18 PM
That's an L-System!?!? What was that made with? The only L-Systems I've seen are those dorky dragon things.

It is realtime music visualizer I wrote. Of course it is not L-System in its pure sense but I thnk it can do something that gives similar results