The heartbeat is a timer that ticks regularly. This tick runs Ruby script block, which increments position or angle of SketchUp's instance toward target. Refer below code snippet for a timer usage and block execution by the timer tick.
In the code, I said the heart beats at precise interval of 'period' and you can say that I should somehow replace the timer with atom clock to get that behaviour. Well, we may meet in the middle by measuring duration; We can't make consistent period but we can get elapsed time between consequent timer calls. Refer below code.
Below is code for object translation. 'entity.transform!' updates the position. This change will be shown by model.active_view.update - search up above code.
Updating position in the middle is easy as it is moving in constant speed. Difficulty lies at the boundaries - reminding me of studying differential equations, asking for great care on boundary condition at all times. In here I have to figure out where and when to stop. I am just checking the remaining distance to the target position in here.
This simple approach - constant speed - makes unrealistic movements at the boundaries. It starts and stops in infinite acceleration. Better simulation should involve smooth change at ends.
Reference : Animate Yo' Cheese
essay on programming languages, computer science, information techonlogies and all.
Tuesday, April 15, 2014
Tuesday, April 8, 2014
One step further with Sketchup and RubyAPI
Trying to impress audience, I have gone further on this simulation and created this glass handling robot interacting with AOI and cassette.
Apparent complex movement are all come down to either rotation or translation in a certain axis. And then these simple motions are chained to each other or set to run concurrently. In the end, it is all about designing class to easily create, link and launch motions.
Apparent complex movement are all come down to either rotation or translation in a certain axis. And then these simple motions are chained to each other or set to run concurrently. In the end, it is all about designing class to easily create, link and launch motions.
Subscribe to:
Posts (Atom)