View Full Version : get traveled Distance

 ArminAnim07-20-2011, 09:55 AMHi everyone I have a float_param which I need to change by the traveled distance of an object. like rotating a wheel of car depending of the car traveled distance (but a float parameter instead of rotation). I've got a rolling-ball script before but is works for rotation and I can't Match it for a float parameter... here is what I've done in my float_Script : MyObj = \$MyTravelingObj finalDistance = 0 fn TravelDistance CurrTime = ( tv = distance (at time CurrTime MyObj.pos) (at time (CurrTime-1) MyObj.pos) finalDistance+= at time Currtime tv ) TravelDistance currentTime the returned value of above script, is just the Derivative of \$MyTravelingObj movement , not its traveled distance Now Am I totally Wrong on it? anyone have got an idea? thanks
lo
07-20-2011, 11:22 AM
I'm not sure I understand... which of these are you trying to get:

*the distance the object has traveled since the previous frame
*the distance from it's position in the first frame
*or the total accumulated distance it has traveled in all frames?

ArminAnim
07-20-2011, 11:39 AM

I think I should say : *the total accumulated distance it has traveled in all frames...
My object do not move a straight path, it moves curvy ...
you could imagine the normal "path constraint" of 3Ds Max, which moves an object along a path by a "percent" value... my job is inverse that one. I want to get a "Single value" from the "total amount" of my object movement...

I hope I could explain it right

JHN
07-20-2011, 12:49 PM
I think your original idea is good (or I'm missing the point) this is what I would do

fn getTravelDistance obj:unsupplied timeRange:animationRange =
(
local totalDistance = 0

for t in timeRange.start to timeRange.end do
(
totalDistance += distance (at time t in coordsys world obj.pos) (at time (t - 1f) in coordsys world obj.pos)
)

totalDistance
)

getTravelDistance obj:\$ timeRange:(interval 0f 50f)

Something like that?

-Johan

ArminAnim
07-21-2011, 12:44 AM
thank you very much Mr.Johan. yea its working, but it gives me a constant Value which is the "final" traveled ditance. I need the traveled distance of my object only until "Current time", because something gonna depend on it at animation and should update on each frame...
for this, in your code I used :
"for t in timeRange.start to currentTime do..."
"for t in timeRange.start to timeRange.end do..."
in my Script_float, And it worked, but it became too heavy to process and by going forward of timeline, it became harder and harder to update the Max. just like a huge Partice!
Do you have any solution for this?
thank you for helping

denisT
07-21-2011, 02:00 AM
Armin,
bro,
you don't really show your setup. is it a script transform? is it a path constraint? post a simplified and localized max file. and at least you will get a chance to have me came in the case.

stefan
07-21-2011, 03:36 AM
AA=0.0
For i = 0 to currenttime do
(
A=at time (i-1) Car_CTRL.pos
B=at time i Car_CTR.pos
AA=AA + length (B-A)
)
AA

put this as script controller of your float value and create variable "Car_CTRL" with your object node in it.

ArminAnim
07-21-2011, 04:48 AM
put this as script controller of your float value and create variable "Car_CTRL" with your object node in it.

Thank you very much Sir, it is exactly what I wanted and it worked fine. but why after using the code, when timeslider moves tward, my scene become slow?

But thank you for helpingIm going to use it.. :)

ArminAnim
07-21-2011, 05:13 AM
Armin,
bro,
you don't really show your setup. is it a script transform? is it a path constraint? post a simplified and localized max file. and at least you will get a chance to have me came in the case.
Im sorry Sir, put it on my english weakness.. the file is heavy but I think this link can show the issue
preview is preparing on this link:
I want the wheel rotate currectly by traveled distance, but its not a rotation, its a float parameter which control rotation.
http://vimeo.com/26707590

stefan
07-21-2011, 11:28 AM
Thank you very much Sir, it is exactly what I wanted and it worked fine. but why after using the code, when timeslider moves tward, my scene become slow?

because the controller is "Alive"
may be U could use it just to create a tool for animation of your value. And reuse it always as U change object's animation.

lo
07-21-2011, 11:31 AM
Ideas for optimization:

* don't calculate from start of animationrange, instead calculate from the first key of the objects animation

* don't calculcate every frame, but every keyframe.

JHN
07-22-2011, 08:53 AM
History dependency (like pflow) will always slow down systems, it's inherit to the way you set it up.
Bu there's another way to set this up, BUT, you will need to bake the solution before submitting it to a renderfarm.

Below is the code in the X rotation script controller (nested in a rotation list controller, layer 1 = script, layer 2 is baked), on the script controller I have a custom attribute called "wheel" it just has 2 parameters, dist and lastTime. I'm not saying this is the best solution, but it worked for us.

--Reset the stored values on the wheel at frame 0 just to make sure
--we have a set starting rotation. If the user skips frames the rotation
--at frame 0 would not be the same each time.
if F==0 then
(
this.wheel.dist=0
this.wheel.lastTime=0
)

--Get the old position and the current position.
p0=at time (this.wheel.lastTime) parent.pos
p1=parent.pos

--Get the distance traveled.
newDist=distance p0 p1

--Calculate the direction to wheel was traveling in so that it can
--rotate backwards. +Y is moving forward in local space so use
--the y vector of the transform compared to the normalized
--direction vector
multi=dot parent.transform.row2 (normalize (p1-p0))
--multi=-1

--Calculate the amout to rotate the wheel and add it to the
--distance variable stored in the ca def.

--Set the last frame to the current frame.
this.wheel.lastTime=F

--Convert the value to radians and apply the rotation to the wheel.

parent is a control below the wheel on the ground (to measure distance per interval)
radius is a track value that is assigned to the radius of a circle shape describing the radius of a wheel

-Johan

CGTalk Moderation
07-22-2011, 08:53 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.

1