blender www.blender.nl
this document is online at http://www.blender.nl/showitem.php?id=118
ALT
  Python Roller   Get your spheres rolling!
2001 01 03 
   
Bart Veldhuizen 
id118 
       
Introduction
Zycho was working on an animation with billiard balls last week. He came to me asking for a Python script that would add realistic rotation to the balls depending on their movement. At first I figured it would be easy - just translate the x and y coordinate of each ball into rotations.

Things were not as simple as that however and I had to use quaternion math instead of Euler rotations. Ton came to my rescue with a bunch of ready to use formulas and a few hours later the script was ready. Take a look at this animation to get a taste for the result:

Download:
 balletje.mpg

How to use the script
If you want to use this script download it below and please note the following:

- The script does not work correctly in Blender 2.10 beta yet.

- For each object, you have to create an accompanying empty. The empty's name must have the extention '.old'. For example, if your sphere is called 'Sphere', the empty must be called 'Sphere.old'. The script uses this empty to store the location of the sphere in the previous frame. In this way, Blender can calculate the displacement of the sphere since the last frame. Don't worry about the location of the empty - it will be automatically corrected by the script. The sphere's name is automagically fetched by the script.

Next, select your sphere and go to the Script Buttons menu. Click on the 'Display Object script links' button in the header - this is the icon with the three arrows. Click on 'New' and change the script event to 'Redraw'. Enter the script's name in the text box.

As a last step, check the definition of the radius in line 11 of the script and make sure that it matches the radius of your sphere. If they don't match your sphere will slip while rolling.

Now you're ready to go! Switch to top view and drag the sphere around - the rotation will now be automatically calculated.

Enjoy

B@rt

Download:
 roller.zip
A bit of theory - Gimbal Lock
Gimbal Lock (quoted from gamedev.net - see below)

As rotations in the Euler representation are done with respect to the global axis, a rotation in one axis could 'override' a rotation in another, making you lose a degree of freedom. This is gimbal lock.

Say, if the rotation in the Y axis rotates a vector (parallel to the x axis) so that the vector is parallel to the z axis. Then, any rotations in the z axis would have no effect on the vector.

Quaternions
More information about quaternions can be found here: Gamedev.net

For the mathematically oriented: UC Berkeley college notes


Feedback
Nexusvins 2001 09 29
Sorry, atrociously redundant postings below! (please delete if poss) - Thanks
Nexusvins 2001 09 29
Art and Maths? Wow! Wondrous, impressively scholastic and aptly complimentary to your collegues amazing billiard ball posting. Thanks guys!
Nexusvins 2001 09 29
Art and Maths? Wow! Wondrous, impressively scholastic and aptly complimentary to your collegues amazing billiard ball posting. Thanks guys!
Nexusvins 2001 09 29
Art and Maths? Wow! Wondrous and impressively scholastic and aptly complimentary to your collegues billiard ball article. Thanks guys!
Nexusvins 2001 09 29
Art and Maths? Wow! Wondrous and impressively scholastic and aptly complimentary to your collegues billiard ball article. Thanks guys!
rijingm 2001 01 08
New to blender, what is Python Script
Osprey 2001 01 06
New to Blender but amazed on first day!!! Can u fly too?
Osprey 2001 01 06
New to Blender but amazed on first day!!! Can u fly too?
B@rt 2001 01 04
driedee - it will be once the new physics engine and tied into the animation system!
driedee 2001 01 04
Nice ! is it possible to do just the opposite: define rotations, put the balls on the floor and let them roll according to laws of physics ...
stephen2002 2001 01 03
Will this thing work on stuff like wheels on a car?
WCFireball 2001 01 03
Now, where on earth did I put that billiard stick...?
Pol 2001 01 03
Hey !
Marvellous !!!!!!
GammaRayQ21 2001 01 03
real gaming!!