THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/06/2012 at 03:27, xxxxxxxx wrote:
Trying to understand vectors, matrix, etc. I am trying to (re)place an object on a spline using the spline offset.
So, on frame x, the Sphere is placed on the spline using spline offset.
On frame x+1, I want to position the sphere a bit further (randomly) on the spline, thus increase the spline offset a bit and replace the sphere.
Now the question is, how to get the spline offset using the sphere position?
Below the code I use at this moment to calculate the spline offset given the sphere position and the 'origin' position of the spline (offset = 0).
For a straight spline it is ok, but when I change (round) the spline a bit, something goes wrong.
After the next point, the position goes 'wild'.
It seems that need to take the rotation into account, but how?
Another strange thing is, that when I do not use random, but just a standard offset (frame / 100.0) everything is ok?
---- Piece of code, see link for the complete file ---
scene file: www.nfvc.nl/test - place object on spline.zip
#get offset on spline based on object position
pos0 = sh.GetPosition(0) # get 'origin' position spline offset=0
objmtx = current_object.GetMg() # Get the object's global matrix
diff = objmtx.off # get object position
dist = (diff-pos0).GetLength() # get difference between spline origin and object
currentoffset = sh.GetOffsetFromUnit(dist) # get offset on spline
Note: I can solve the issue by storing the spline offset at frame x and use it in frame x+1, but I really want to understand.