View Full Version : rolling cube
hvanzon 03 March 2006, 02:06 PM im in need of a script where you can let a cube (or rectangular) form, roll over an other surface. That surface could be another cube.
like this sample:
http://www.harmmaaktmooi.nl/sample/sample.jpg
so when the cubicform come at the top it rolls over it.
I can animate this manually by using a lot of link contrains, but i want masses of cubes to do this. And even cylindric and other forms to do this over other forms.
Is there any way? Or any person who can make some sort of script for me?
maybe c it as an challenge? Like the ones CGSOCIETY is giving you guys. :)
tnx,
harm


stuh505
03 March 2006, 02:03 AM
The problem you have specified is really unclear. Do you want to be able to specify a path (perhaps by a spline) and then have an object follow the path while rotating?
Or do you want this to be more like a physics simulation? And if that is the case, why not use reactor?
hvanzon
03 March 2006, 12:05 PM
sry if i have been unclear.
i want the forms to crawl. to roll themselves and over another object. And so that i can assign the objects that crawl and the objects that are crawled over.
basicly the object should roll over its own edges. I need 3 different obect types. Cubes, Cylinders and paramid forms.
and when for instance assigned to an object it uses that object surface to crawl over. When it comes to a edge, its crawls over it and follows the surface. I hope this is more clear.
so i think this are 2 problem.
1. the rolling of the objects (in any direction)
2. the rolling over objects.
I would be happy with 1 of them solved.
Sry i come to you with this problem. But im a noob when it comes to scripting. Im learning it, but i cant even begin to think, how to start here.
If i am still unclear plz let me know.
tnx
stuh505
03 March 2006, 01:06 PM
Well, a cube does not really roll because of it's geometry...do you just want to imagine a sphere that circumscribes the object and have it rotate within that boundary? Because that does not sound too hard
hvanzon
03 March 2006, 01:50 PM
no i can make a cylinder roll based on pi and its diameter.
A cube can 'roll'. just imagen square wheels. i used it in a animation before but i hand animated that. I you want i can make a preview maxfile of it. so you know what i mean?
marktsang
03 March 2006, 02:32 PM
i understand what you want, and i dont think it will be easy to get results.
mark
eek
03 March 2006, 02:22 AM
if you want a box to roll, like a square wheel, just by moving it is gunna be some complex math, maybe step algorithm, with pi and some sin stuff, in all directions is harder. Hmmm... maybe not
maybe a sin/zig zag algoritm for the z position, but no that wont work going up the sides of things.
Why cant you just hand animate the the z/x/y position, its just a wave, based off the the rotation. I.e animate it moving, and rotating, add the keys to stop it cutting through the floor. I wouldnt even use constraints id just key it.
Aearon
03 March 2006, 09:01 AM
i'd also do this by hand, but i'd just animate the pivot instead of bothering with waves or anything.
parent your boxes / pyramids whatever under a point helper. initially position the helper at the first corner your object will roll over.
animate the helper so the object rolls over this first corner and lies on it's next edge (let's say this happens on frame 20. then animate the helpers position from frame 20 to 21 so it's at the next corner the object is to roll over (the object itself will move as well obviously), you need to animate the object as well from frame 20 to 21 to counter this movement so it stays in place. once you have done this you can use the helper to animate the next roll.
the part about this that could be scripted is a simple tool to help animate the pivot with the object itself staying in place
here's a quick example (http://www.aearon.de/files/public/rollingCube.avi)(tscc / techsmith codec)
Aearon
03 March 2006, 09:20 AM
here's another one (http://www.aearon.de/files/public/rollingCube2.avi)
it's showing the cube rolling over the top edge of the obstacle
hvanzon
03 March 2006, 06:03 PM
thank you very much, but i already use that methode in a previous animation.
call me stubborn but i really to try to script it, or do it in wire parameters.
i focused on the cube. How to let it roll. I tried it in wire parameters but dunno how to do it.
heres my thought. the rotation should be linked to the position of the cube. So when the cube moves in a x_position he should rotate in the y_direction. the linking should be in this way, that when the cube travels its own length it should rotate 90°. this is dun by dividing the units by the lenght of the cube and then multiplying it by 90.
x_postion=(y_rotation/length)*90
then you measure half the diagonal of the square. you take half the height of the cube.
and subtract that from the diagonal. to get the sinus for the z_position.
z_position=sin ((diagonal/2)(height/2))
so when the cube is 60,60,60
y_rotation=(x_position/60)*90
z_position=sin 12,42640687119285
This can be applied to all of the axes.
is this the way to do it? Or am i just plain stupid. (which could be). And can someone tell me how to do this in a script or in wire parameters.
thanx a lot...
stuh505
03 March 2006, 06:35 PM
You could just give it a constant horizontal velocity and make the angular rotation constant as well. Then you just need a function to determine the elevation with respect to the rotation. So, if you're rotating from 0 to 9999 by 15 deg for example, first say
r = rotation mod 90
you know that when r = 0 or 90 the height should be unchanged (length/2). When r=45 the height should be length/sqrt(2).
So if we modify a sin curve to fit within these bounds you get
y = sin(r*490)/2+0.5
but this gives y as 0 to 1, we want it to vary from 0 to (length/sqrt(2)length/2) so just multiply it by that
hvanzon
03 March 2006, 09:27 PM
http://www.harmmaaktmooi.nl/sample/roll.max
i made the cube. and when you move it in the xaxis. Its roll's. this part is ok.
did it in wireparameters.
can someone plz show me how to make the sinus thingie.
is this doable in wireparameters or do i need expressions?
hvanzon
03 March 2006, 02:36 PM
Aeron your absolutely right. It isnt a sin, cos or whatever.
http://harmmaaktmooi.nl/sample/movement.jpg
i made the movement and it comes to this. Is this doable or is it real hard?
jman
03 March 2006, 05:41 PM
this is surely done with animation not script!!?!? I'd use a splineIK (see attached MaxFile)
If it absolutely came down to scripting it then I would transform the vertices around the relative axis (defined by two corner vertices!) using matrixes. When that was rotated, I'd then move to the next axis and then rotate the next set. does this make sense?
Anyway, plenty of hidden pitfalls, the IK is much better,
J¬
hvanzon
03 March 2006, 06:33 PM
no its animation. Just to show that the movement isnt a sinus as i thought.
eek
03 March 2006, 06:51 PM
Its not a sin wave ,its more zizzag or bounce, i.e fast inout. Reminds me a lot of bezier segments. Hmm... i think i have an idea.
hvanzon
03 March 2006, 07:08 PM
cant this movement be done in an expression. so that when i move the cubes its rolls.
i would be happy with only the bounce Zmovement. then i can desect and make my own expressions.
tnx
eek
03 March 2006, 07:30 PM
Yes but the bounce is the hard part, one side not is that the x positon is product of both the bounce and rotation, but i more the bounce i think.
Or the rotation.
Aearon
03 March 2006, 08:13 PM
i think i have it. it is a sine wave, but only a part of it
the calculations in this thread so far use a sine wave from 0 to 180, the cube only goes from from 45° to 135°, so we just need that segment of the sine
eek
03 March 2006, 08:24 PM
i think i have it. it is a sine wave, but only a part of it
the calculations in this thread so far use a sine wave from 0 to 180, the cube only goes from from 45° to 135°, so we just need that segment of the sine
yes we could use a full wave rectified sine to achieve this. It wont take into accout slding though. Its one thing to keep the box on the ground plane another to sync to rotation to the wave. bernstien would acheive the same result.
The equation for full wave is: f(t) = (2*a/pi  4*a/pi) sum cos(n*inf1*t)
'a' being the height and 't' iteration.
This is part of the 'fourier' series.
Edit: sorry that equation is wrong, i need to factor in sigma.
Aearon
03 March 2006, 10:11 PM
this one is more accurate, i used some circle formulas instead of sin:
(http://upload.wikimedia.org/wikipedia/de/3/34/EinheitskreisWF.gif)
len = 20
r = sqrt (2*len^2)
rot = abs (radToDeg Y_Rotation)
rot = mod rot 90 + 45  with this rot will always be between 45 and 135, which is the segment of a full circle the box's center traverses
 straight from wikipedia formula
a = cos (abs rot) * r
g = a/(tan rot)^1
g = g/20*8.2843
what we remains is some slipping, we can get rid of that as well though. 'a', which we calculated based on the current rotation, gives us the position the corner of the cube 'should be at' at any given time, we can use this to apply an offset to the position using a list controller for example
eek
03 March 2006, 10:22 PM
or this:
full wave rectified sine
a = 10.  amplitude
o = 50.  omega
t = slidertime  time
r = 0  result
for n = 1 to 1000 do
(
r = r + (cos(n*o*t))/(4*n^21)
)
(2*a/pi)((4*a/pi)*r)
Aearon
03 March 2006, 10:23 PM
here's the visual version: www.aearon.de/files/public/rollCube3.avi
eek
03 March 2006, 12:33 AM
Interesting Aearon you got fazers going on in there?
magicm
03 March 2006, 12:51 AM
Here's my take on this. It just works in one axis so the box can't go up, but it's a start.
Cheers,
Martijn
hvanzon
03 March 2006, 01:03 AM
wow u guys r f@cking genious. tnx tnx tnx for helping me... :)
eek
03 March 2006, 01:34 AM
i was thinking about the up issue, why not put that on a float list controller. Then drive it with a slider to wieght the equation for each axis i.e get to the edge, blend to different equation move up? Or even do some math checking, call the same fn moving up against x, but wed need to give the x a float list. So to say when moving above say 10 we ramp in the new equation?
Thats a simple blend math. Also maybe an animatable height value when the ramp starts?
fabman
03 March 2006, 12:26 PM
Just as an info... the shape you're talking about in maths it's call a "catenary", quite used in geometry, you got some info in here (http://mathforum.org/library/drmath/view/53706.html) I hope it helps...
Cheers.
lechoo
03 March 2006, 02:33 PM
I had similar problem few weeks ago, but my object wasn't cube. I decided to write a script which will animate rotation and Z part of position, to give convincing effect of rolling. Here's small test rollTest. (http://67.19.72.217/adam/trash/rollTest.avi)
First part shows original animation. Second is result of executing script.
hvanzon
03 March 2006, 02:50 PM
lookz awesome, this would take a lot of time to animate. great work
does that script work with any forms (surface trace of some kind), and in the z direction?
lechoo
03 March 2006, 09:13 PM
does that script work with any forms (surface trace of some kind), and in the z direction?
Yes, it works with object of any shape but only on a plane.
hvanzon
03 March 2006, 01:55 AM
also in a plane in the zdirection, cos then its exatly what i am looking for.
can you post it, or is it commercial?
lechoo
03 March 2006, 10:04 AM
also in a plane in the zdirection, cos then its exatly what i am looking for.
can you post it, or is it commercial?
Unfortunately it is commercial.
hvanzon
03 March 2006, 10:22 AM
where to but it? an what r the costs?
edit: to 'buy' it off course. ('huh huh he said butt')
eek
03 March 2006, 08:03 PM
is this script doing a key bake down?, i.e firstly a velocity check to determine speed, then a check for ground intersecting  find the difference and append?
ground checks and hieght adjustment isnt too hard, its getting rotation correct/distance. So maybe two passes, firstly to get the rotation then to get hieght.
lechoo
03 March 2006, 11:21 AM
where to but it? an what r the costs?
edit: to 'buy' it off course. ('huh huh he said butt')
I wrote it for one of projects in company that I work in and am not allowed to post it or sell it. So its commercial in that way :)
is this script doing a key bake down?, i.e firstly a velocity check to determine speed, then a check for ground intersecting  find the difference and append?
ground checks and hieght adjustment isnt too hard, its getting rotation correct/distance. So maybe two passes, firstly to get the rotation then to get hieght.
That's the idea.
CGTalk Moderation
03 March 2006, 11:21 AM
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.