Universidad Lasalle Noroeste
Animacion por computadora IV
"Good Rotation of an sphere in all axes"
Jennifer Rios Holanda spontaneous and short version =)
Matricula: 059171
Teacher: Enrique rosales
So… let’s begin saying what is the problem im trying to solve and explain about making a ball roll.
First: if I roll it in the “x” axis everything is fine, I managed to do this.
And if I want to roll it in the “y” axis, all is good I can do it too, all of this with just a code in the rotation o each axis, but what happens when I want to roll it in both axis at the same time?, whoops! That rotation is not alright at all =(
well then just do the same as everyone has been saying and good luck =D.....kidding!
ok, ok well, lets see
to begin, there is a solution called, quaternions, so what is this quaternion?, is an imaginary axis between the already known axes "x" & "y", you see we already managed to separately move the ball, but when you choose the triangle that inmeaddiatly moves both at the same time, because it is not designed like the other axes, its a mess when you move the ball, it has no coherence in movement at all, so what we need is to make it understand in that option to move equally.
for that we need the next script
but first how to put it
Assigning the Script
-Open track view curve editor, find the sphere you created and select the rotation controller under transform (sphere/Transform/Rotation)
-Click the assign controller button and pick rotation script and then click OK
-then you can put the next.
obj = $Sphere01 -- change sphere by the name you have
timeres = 1f
fn getrot t =
(
if t<=0f then return quat 0 0 0 1 -- t=0 => no rotation
t0 = t-timeres -- previous frame time
t1 = t -- current time
rot0 = getrot(t0) -- previous rotation:
p0 = at time t0 obj.position-- previous position
p1 = at time t1 obj.position-- current position
if(p0==p1) then return rot0 -- no distance is traveled
dif = p1-p0 -- difference in positions
len = Length(dif) -- distance that's traveled
vec = dif / len -- normalized movement vector.
r0 = at time t0 obj.radius -- previous radius
r1 = at time t1 obj.radius -- current radius
rotax = cross vec [0, 0, 1] -- rotation axis
angle = 360*len/((r0+r1)*pi)-- rotation amount (in degs)
rotdif = quat angle rotax -- rotation from t0 to t1
rot1 = rot0 + rotdif -- total rotation
)
getrot(currentTime)
Click Evaluate and if no error is shot, click Close in the script rotation dialog box.
lets not forget the credits: http://www.cuneytozdas.com/tutorials/maxscript/
No hay comentarios:
Publicar un comentario