Setting bounds with floats?

I’m trying to move a component along a path, but the results are a big “shakey”! I’m using getPointAlongPath() which returns a float, but I can only set bounds using ints. Therefore the loss of precision is causing the component to move along in a not so smooth way. Anyone got any better ideas of how I could do this?

Here’s my code…

Point<float> pt = ballPath.getPointAlongPath(i, affine); comp->setCentrePosition (pt.getX(), pt.getY()); i += incr;

Not sure if this is directly relevant, but remember that the parametric form for cubic splines (a.k.a. Bézier curves) exhibits nonlinear velocity with respect to the parameter. Or to put it in different terms, the magnitude of the velocity vector is variable given a constant parameter velocity.

Smoothly varying the parameter t used to calculate the x and y coordinates of a point moved along a cubic spline will not always result in constant velocity.

On a related note, the topic of equal-length subdivisions of cubic splines is a hot one since it bears direct relevance to rendering. Polygons containing fewer subdivisions in the piecewise approximation of a cubic spline will render faster. That the rate of change of the x and y coordinates is variable with a constant rate of change of the interpolating parameter complicates the subdivision of the curve into a suitable polygon.

You could perhaps have a fixed origin position, and use a transform to position the component?

I hadn’t thought of using a transform. Would this be the logical approach?
I’m building an xy pad so the ball is the component which I want to move around. It’s fine for dragging (I just use the dragger), but for automation I would have thought that I need to reset the bounds? It works fine for angles of 0, 45, 90, 135 degress etc but anything else will result in a “shakey” ball!

Well, for something like that I probably wouldn’t bother with a component for the handle at all- I’d just draw the handle directly to the pad component (in its paint callback) and override the component’s mouse event callbacks to manually define the dragging behaviour.

I had tried that before but it ends up having a lot of calculations, and doesn’t give me the option for having multiple balls. It kind of goes against OOP no?

Anyone else ever have this problem when resetting the bounds of a component?

What problem? I think people answered your original question pretty well.

And did you consider using a DrawablePath for your ball?

[quote=“jules”]What problem? I think people answered your original question pretty well.

And did you consider using a DrawablePath for your ball?[/quote]

I was just curious to see if anyone else had encountered a similar situation where they had to continually move an object around using precise coordinates. I’ll take a look at DrawablePath, thanks.