Animating object location


Recommended Posts

I'd like to animate the position of a screen object based on the value of a number (channel or variable). What's the most efficient way to do this without the motion appearing choppy or unduly bogging down the UI thread? Have a fairly high update rate on the channel and recalc the locations in OnPaint? Or you could trend the value and interpolate to predict position between channel reads.

Link to comment
Share on other sites

If you want it smooth, its probably best to recalc the location in a sequence based on time, then have the component use the results during paint. The refresh rate of the screen is not perfectly time synced, and in fact, when you drag items, it refreshes the screen really fast. Interpolation would help with smoothness. Truthfully, determining the best solution would require a bit more detail about what you are doing. I'd just experiment.

Link to comment
Share on other sites

So every time you recalculate one of the position parameters, it forces a screen refresh? If so, that should work. Get the position from the PLC and either interpolate the position by calculating the velocity in DAQFactory, or have the PLC calc it and send it over as another channel. Yeah, smoothness is the goal.

It's like a mimic panel app. Something physical is getting moved by the PLC, the PLC knows where it is and knows, or can calculate, the velocity. So I'd like the picture of the object to move on the machine layout on the screen as realistically and accurately can reasonably be achieved.

Link to comment
Share on other sites

No, recalcing a parameter doesn't cause a screen refresh. Only the page refresh interval and dragging controls, knobs, etc.

For smoothness, you'll need to interpolate at refresh based on the last two PLC read values. The faster you read those values, the more accurate it will be. Put the calc in OnPaint. Just have it update global variables and let the control use them to determine its position, or if you want use Component.myComp.MoveTo() in OnPaint

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.