View Full Version : Expression for sphere rotation
08-27-2002, 08:56 AM
I'd like to animate a sphere that rolls along a curved path. I'd like to use an expression to calculate the spheres rotation from its position. This is easy if the sphere rides on a straight path but tricky on a curved path since when I rotate one axis the other axis will be rotated as well. maybe there is a solution with some nulls??? I even don't know if this is the right forum since I am new here and this is my first post.
:rolleyes: :rolleyes: :rolleyes: :rolleyes: :rolleyes:
08-27-2002, 07:56 PM
sorry, I know nothing about expressions, but sure someone here does, so I think you should tell us what software you're using, dont you think?
08-28-2002, 02:48 AM
what software are you using? [so i can direct your thread to the appropriate forum...]
08-28-2002, 08:13 AM
I am using Universe with Xpressionist :buttrock: . I have not seen any Universe forum here. My question is not so much software related but math related - it would pretty much be the same problem in Maya, Max, LW or any other software. I am looking for something like a formula:
rotation_in_degrees = travelled_distance / sphere_diameter * pi * 360;
which would describe the rotation on one axis. But I have not found something how to calculate the spheres rotation for a curved path - i.e. when the sphere moves in X and Z - how can I calculate the rotation then?
:beer: :beer: :beer: :beer:
08-28-2002, 08:54 PM
wouldnt it just be the same expression for each axis? So if the sphere travels foward 5 metres, it might rotate around Z 5 times. But if it travels foward 5 metres & left 1 metre, it would rotate around Z 5 times & around X once. The same expression should do all of that. Another way would be to constrain the sphere to a path, & just use the expression on the Z axis, that would give you motion like a wheel, as opposed to a marble - but for a fast moving sphere thats probably what you want...
08-28-2002, 09:43 PM
thanks for your suggestions, but if it would be that easy I would not ask. I can't use the same expression for the X axis, because whenever I rotate one axis (z) the other two axis (x and y) also rotate. The direction of the other axis change. If I rotate the Z axis 90 degrees the X axis becomes the Y axis and vice versa. If I want to rotate the sphere on the X axis and the z axis is already 90° rotated I actually would need to rotate the spheres Y axis - to get a rotation around the world x-axis. The same happens to the Z axis when I rotate the X axis. This problem relates to the local coordinate system of the sphere.
So I guess that I need a (some?) seperate coordinate systems or a more complex formula which also incorporates the Y axis to solve the problem.
I could rotate the sphere like a wheel as you suggested, but that is not what I want. I want it to rotate like a natural sphere - a billard ball, or a marble in a labyrinth game.
:shrug: :shrug: :shrug: :shrug: :shrug:
08-28-2002, 10:16 PM
You could also try rotating the sphere around the y axis to make it point in the direction it's going.. make it so the y_axis is evaluated last so it's not affected by the rotation in the Z axis.
If you can keep track of where the ball was the last time the expression was evaluated, get the vector between the last position and the current position, you can figure out how it needs to be oriented in the y axis to meet that direction.. then rotate it in y.. then rotate it in Z.
08-28-2002, 10:31 PM
yep, Jasons right, if your getting 'gimbal lock' you either need to key around the problem frames, of change the axis evaluation order. In Max theres a dropdown list you can just change the order the axis of rotation get evaluated in, perhaps Universe has something similar? The other possiblilty would be to maybe link the ball to a Null & use the Null object for one of the axis's (axees?) - again, I dont know anything about your app, so that may or may not be possible... :shrug:
08-29-2002, 08:54 AM
Thanks Jason and Chris, :beer:
if I do like Jason suggested the behavior of the sphere would be like the behavior of a wheel: it first gets oriented in Y (direction) and then the z (or x) rotation is evaluated. This is possiible, since I can evaluate what the expression did on the last frame, but this is not the effect I want :shame: . I want the sphere not to change its direction. I want it to roll like a ball would do. A ball would not change its orientation during a direction change. it would simply roll into the new direction.
Yes, I can change the order in which the axis are evaluated in Universe - but however I set the order, one axis is always processed first leading to a rotation of the other axis.
This problem is not as trivial as it might seem.
:hmm: :hmm: :hmm:
08-29-2002, 09:13 AM
use dynamics. :)
08-29-2002, 09:16 AM
Universe does not have dynamics :)
:cool: :cool: :cool: :cool:
08-29-2002, 09:20 AM
you could use maya.. :)
08-29-2002, 09:25 AM
I couldn't. I don't have Maya. I am lookung for an expression - not a new software.
08-29-2002, 08:37 PM
I know.. It was a joke! :)
I was thinking you might be able to fake it with a texture map.. use transform rotation for one direction, then map rotation for another, but you run into the same problem really..
sounds like you'll have to do some sort of vector math. you can easily get two independent rotations for rx and rz (two different spheres moving in the directions you want). Using those, you should be able to somehow figure out the necessary rotations.. but the math is way beyond me. :)
I can ask around tho!
08-30-2002, 02:20 AM
Okay, here's a way of doing this in maya w/out all the vector/matrix math..
basically, it involves using the "rotate" command so you can rotate in world space.
I set up an expression which tracks the distance the ball moves in any given frame or evaluation.. then rotates the ball in world space based on that evaluation. It's running a mel command, so it's not great.. but it gets the job done. Maybe there's a command similar to this in Universe you can use?
anyway, the sphere is following a locator for the motion.. here's the expression:
nurbsSphere1.translateX = locator1.translateX;
nurbsSphere1.translateY = locator1.translateY;
nurbsSphere1.translateZ = locator1.translateZ;
global float $prevTx;
global float $prevTz;
$rx = nurbsSphere1.rotateX;
$ry = nurbsSphere1.rotateY;
$rz = nurbsSphere1.rotateZ;
$tx = locator1.translateX;
$tz = locator1.translateZ;
$txDif = $tx - $prevTx;
$tzDif = $tz - $prevTz;
$newRz = -1 * $txDif / 15 * 360 * 3.141592;
$newRx = 1 * $tzDif/ 15 * 360 * 3.141592;
rotate -r -ws $newRx 0 $newRz nurbsSphere1;
$prevTx = $tx;
$prevTz = $tz;
hope this helps some!
01-13-2006, 03:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.