How to know if user has stopped orbiting camera?
-
Hi all,
is there a way to know if User has stopped using OrbitTool to navigate camera?
Or some way to know that Mouse Up event occurred, that might help but I'm not sure how to track it.I need to know if this event occurred to get transformations of instances whose definitions have always_face_camera flag after the camera has changed. I can do this by listening to ViewObserver but onViewChanged event fires too often.
-
You can use the ToolsObserver to detect when the Orbit tool isn't active any more - that would assume the user is using the middle mouse button. To catch when the Orbit tool has explicitly activated the tool you can check if the state changes.
-
Maybe something is wrong, but I don't get any onToolStateChanged messages when using Orbit Tool. I do get them for a move tool though.
-
Ah! Now that's annoying.
You could use a timer to defer the event, so that you don't perform actions too quick and merge quick successive view update into one event.
-
Inside your own tool, you use the .resume and .suspend methods. suspend will tell you if the user has started using orbit or pan, and resume will tell you when you are back into your tool.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/tool.php#resume
-
@chris fullmer said:
Inside your own tool, you use the .resume and .suspend methods. suspend will tell you if the user has started using orbit or pan, and resume will tell you when you are back into your tool.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/tool.php#resume
Thanks! Tried that approach. Unfortunately one would need to .resume custom tool manually or by some specific event which I didn't manage to find so I sticked with the time solution.
-
Thanks, Thom!
Solved it using timer to merge quick calls and camera.xaxis to determine if OrbitTool was used
class MyViewObserver < Sketchup;;ViewObserver def initialize #used to determine if camera has been rotated around z axis or not @old_xaxis = nil @update_timer_id = -1 @update_delay = 0.07 # seconds end def onTimerDone @update_timer_id = -1 # DO UPDATE STUFF HERE end def onViewChanged(view) return if !view if camera.xaxis != @old_xaxis UI.stop_timer(@update_timer_id) if @update_timer_id != -1 @update_timer_id = ;;UI.start_timer(@update_delay, false) {onTimerDone} @old_xaxis = camera.xaxis end end end
-
@chris fullmer said:
...
suspend
will tell you if the user has started using orbit or pan, ...Really? That is news to me. (The API docs do not say this.)
AFAIK, a tool's suspend callback is called JUST BEFORE the tool becomes inactive, (so you can save stuff like your tool's state etc.,) and BEFORE the interruptor tool becomes active.
Also.. because the
Sketchup::Tools
collection does not haveEnumerable
mixed in (and aneach
method defined,) there is no way to non-destructively read the last tool on the stack, nor even iterate the stack.
Advertisement