- How to animate a ball using math
- the scientific side of computer graphics"
- what we are going to do is to animat a ball using math expressions ,the
ball will bounce against the floor with attenuation during its movement. - to do this follow these are step by step instructions
- 1-craet nurbs plane and scale it 24 times.
2-create nurbs sphere .
3-still select the sphere ,right-mouse-click on "translate Y"
and choose Experssion, a window will appear to you.
4-in this window under experssion write this :
=========================================
nurbsSphere1.translateY=cos(time);
=========================================
this line tells MAYA to move the sphere in y direction according to cos function. - just a little review:
cos : x-----cos(x)
cos : ]-infinity,+infinity[ ------> [-1,+1] - in our situation the free variable is (TIME), and it begins at 0,as we know
cos(0)=1 which tells that the pivot of our sphere will be at (0,1,0)
at the beginning of the time,if we play the animation ,the "translateY" will decrease untill reaching (0,-1,0)
where it stops and then back again to (0,1,0) and start over again.
5-we need some adjustment to acheive the we goul,
let us multiply the cos function with 4,so the previous line will be:
============================================
nurbsSphere1.translateY=4*cos(time);
============================================ - here the movement will oscillate between (0,4,0) and (0,-4,0).
- 5-untill now it not seems like our ball is bounsing at all,
to fix this lets us remmeber absolotw value (abs) function - abs : x ---->|x|
abs : ]-infinity,+infinity[------>[0,+infinity[ - that GRAPHICALLY means (when you draw the graph of this function )
every point under x axes (minuse values) will be refected above the
x axes. - now play back the animation and watch the new motion.
- 6-the ball penetrate the plane , to fix this problem
just add 1 to the script line above ,so it will look like this: - ===========================================
nurbsSphere1.translateY=abs(4*cos(time))+1;
=========================================== - 7-if you like to make the motion faster multiply the time inside cos function
====================================
nurbsSphere1.translateY=abs(4*cos(time*5))+1;
============================================
this will make it 5 times faster. - 8-now we need some attenuation. and this will be done by (exp) function.
- exp :x-------->exp(x)
exp :]-infinity,+infinity[------]0,+infinity[ - the propersty of this function that we are goning to use is its
'acceleration' ,while the free variable(x) increase (decrease) ,exp(x)
will increase (decrease) much much faster . - adjust the script line like this
====================================
nurbsSphere1.translateY=exp(-time)*abs(4*cos(time*5))+1;
====================================
I multiply exp(-time) with the previous expression
"abs(4*cos(time*5))+1" and this will attenuate the bouncing by time. - if you want more attenuation try exp(-time/2), if you want less attenuation
try exp(-time*2) . - now we have done with bouning and attenuation, let us go to rotation
and translation to some direction and let it be x direction. - 9-right-mouse-click on "translate x"and choose Experssion :
right (like you have done above) this script: - ========================================
nurbsSphere1.translateX=4*log(time+1);
======================================== - log :x---->log(x)
log :]0,+infinity[---->]-infinity,+infinity[ - I add 1 in log function because there is no log(0), and multiply
by 3 to make the movement to "x" lasts a little longer. - play back and watch.
- 10- we need to rotate the ball so it will look more realistic motion.to do this
right-mouse-click on "rotate Z" and choose Experssion - right down this script:
=======================================
nurbsSphere1.rotateZ=-200*log(time+1);
====================================== - by the logic of translation x
- and here it is.
- if you further explainations,i will try to answer you Q at this e-mail
or in this page.
justforthis101@yahoo.com
إعـــــــلان
تقليص
لا يوجد إعلان حتى الآن.
How to animate a ball using math
تقليص
X
-
How to animate a ball using math
الكلمات الدلالية (Tags): لا يوجد
تعليق