Notifications
Clear all

[Closed] Inequality test: Unexpected Result

Greetings

I have a dummy object, with a custom attribute (.axisPos)  evaluating a float script.

However, I'm getting some rather odd results when trying to detect changes to the value over the course of the animation... 

I double checked what was going on at the frame my while loop detected a change in axisPos unexpectedly, these are the values involved typed into the listener…

(at time 307 $Axis_3.axisPos)
    15112.5 -- listener response 
    (at time 306 $Axis_3.axisPos)
    15112.5 -- listener response 
    (at time 307 $Axis_3.axisPos) != (at time 306 $Axis_3.axisPos)
    true -- listener response 
    (at time 307 $Axis_3.axisPos) as string != (at time 306 $Axis_3.axisPos) as string
    false -- listener response 

I thought one only needed to cast values to strings for equality comparissons when they were things like transform matrices, or similar? What am i missing here?

Cheers

Mikie

9 Replies

howdy

could you show the axisPos script?

In a nutshell…
source is a scene helper with a few CAs that assist in calculation
refPos, payout, and trim are all either floats, or floatScripts.

  axisList is a struct containing some related info and functions
  (UpdatePos F seeds a c# .dll with some scene info)
  (countDirection returns a bool based on what UpdatePos fills in)
pos = source.refPos - source.payout + source.trim
      axisList[source.cI].UpdatePos F
      dir = axisList[source.cI].countdirection()
      if dir then -pos else pos
      

Could this all come down to float precision? I suppose i could multiply out and convert to INT, or use close_enough? (altho i don’t really get the third parameter of close_enough)

what:


 ((at time 307 $Axis_3.axisPos) as string) != ((at time 306 $Axis_3.axisPos) as string)
 

does say?

converting to strings does evaluate as expected… It does add quite a bit to the overhead, and I was hoping to avoid it…

To add to the confusion…

in this case, $Axis_3.axisPosition is basically derrived from an object following a path constraint. it has animation keys set till frame 80 where there is a linear tangent key set at 100%, at frame 400 there is another linear tangent key set at 100% In that range the reported value of .axisPos does not APPEAR to change.

Part of what I’m doing involves getting the first derrivative of axisPos. This gets displayed in another custom Attribute as Speed… the values in speed from frame 80 to 400 are ‘mostly’ 0… however, occasionally there are blips in the range of +/- 0.019… This seems indicative of something going on under the hood affecting the internal value of .axisPosition…

 lo1

I think you must show the code of .axisPosition in order to find out the true problem, but you can always work around it by using something like :

abs ((at time 307 $Axis_3.axisPos)-(at time 306 $Axis_3.axisPos)) < 0.0001

or something along those lines. I think it will be less wasteful than strings.

Yah… I’m just a bit perplexed as to where it’s coming from… I’m making up some test functions now to see what’s going on…

I’m trying to isolate the exact source for debugging purposes to see, but i havn’t quite figured out how to get floats to print their internal value, rather then their displayed value…

 lo1

If you got to the ‘number values’ page in the maxscript help there’s an explanation on how float values are stored/displayed.

Okie Dokie, so far seems to be a path constraint thing…

this is what i’ve tested with (just whacked it in globally) and tried to make it as generic as possible with no performace shortcuts.

I then animated an object for half my timeline (150 frames).
First with just a point A>B keyframe animation…

I then ran the following in the listener with my box selected

for n = 0 to 250 do LinearSpeed $ n

The data looked as I’d expect, with values for speed being 0 in the frames 150-250

I then replicated the move with a path constraint, and bezier float percentage on a regular spline. I used 3 keys (value, time) as follows (0,0) (100.0,150) (100.0,250) (linear tangents between keys 2, and 3)

between frames 150 and 250 speed values juddered all over the place, so i thought it might be the wierd thing path constraints can do when they wrap from the end of the spline to the start… So i changed my keys to (0.01,0) (99.99,150) (99.99,250) and still have random value fluctuations, though not as large as when sitting on 100.0


 global LinearPos
 global LinearSpeed
 global LinearAccel
 global Linearjerk
 
 fn LinearPos obj Frame=
 (
 	sX = 0.0d0
 	sY = 0.0d0
 	sZ = 0.0d0
 	lX = 0.0d0
 	lY = 0.0d0
 	lZ = 0.0d0
 	pay = 0.0d0
 	p = 0.0d0
 	
 	sX += at time Frame obj.pos.x
 	sY += at time Frame obj.pos.y
 	sZ += at time Frame obj.pos.z
 	lX += 0
 	lY += 0
 	lZ += 0
 	pay += (sqrt ((lx-sx)*(lx-sx)+(ly-sy)*(ly-sy)+(lz-sz)*(lz-sz)))
 		
 	format "====FRAME==== [%]
" Frame
 	format "sx:%
" sX
 	format "sy:%
" sy
 	format "sz:%
" sz
 	format "pay:%
" pay
 
 	pay
 )
 
 fn LinearSpeed obj Frame =
 (
 	pos1 = LinearPos obj Frame
 	pos2 = LinearPos obj (Frame + 1)
 	spd = (pos2 - pos1) * framerate
 	
 	format "spd:%
" spd
 	
 	spd
 )