1. Coin3D
  2. Coin


Clone wiki

Coin / Sc21 Tutorial_Part2_Eventhandling

You are here: HomeDocumentationMac information pageSc21 → Sc21 Tutorial - Part 2: Eventhandling

Sc21 Tutorial - Part 2: Eventhandling

This tutorial explains how the Sc21 eventhandling system works.

This tutorial assumes that you are familiar with the basic Sc21 tutorial, and builds on the sc21-tutorial-test application developed therein. If you have not worked through the basic tutorial, please do so now before continuing.


The Sc21 eventhandling system is described in detail in this article. Basically, events are received by the SCController instance and passed on to its SCEventHandler. There can be a whole chain of event handlers; if the first one does not handle the event, it passes it on to the next event handler. Sc21 provides two basic event handlers, but you can (and probably will) write your own.

Examining the Scene

In this tutorial, we will use one of the event handlers that come with Sc21 to inspect the scene. SCExaminerHandler provides basic camera control functionality: it allows you to rotate the scene, pan, and zoom in and out.


Open the sc21-tutorial-test project you created in the basic Sc21 tutorial. Double-click on MainMenu.nib to bring up Interface Builder.

Add an SCExaminerHandler to your project by dragging the SCExaminerHandler icon onto the Instances panel. Connect the SCController's eventHandler outlet to your newly created SCExaminerHandler instance.


This is it. You can now interactively inspect the scene. Let's try it!

Switch back to Xcode and build and run the application. You can use the left mouse button to rotate the scene, and the middle mouse button to pan. Holding down the shift key and pressing the left mouse button lets you zoom in and out. (If you have a mouse wheel, you can also use this for zooming.)

Your default settings suck!

This was easy, right? I'll do you one better. If you don't like the default bindings, you can change them. And of course you can define if and how you want to emulate the middle and right mouse buttons.

You can do this in the Attributes panel in Interface Builder. Simply select your SCExaminerHandler and press <Apple> + <Shift> + i (or choose "Show Inspector" from the "Tools" menu). and choose "Attributes" (<Command> + 1). Here you can define the bindings for the rotate, pan, and zoom functionality; define mouse button emulation; and change some other options.



The CustomEventHandling example that comes with the Sc21 distribution showcases a slightly more advanced usage of Sc21 event handling. Here you see an actual eventhandler chain in action. The example uses the same examiner functionality we used in this tutorial, but adds a custom event handler: When the <Command> key is pressed, events are not used to control the camera, but are converted to Inventor events and sent to the scenegraph instead.

The CustomEventHandling example shows you how to create your own custom event handler, how to use the SCCoinHandler that is part of the Sc21 framework, and how to hook the whole thing up. Incidentally, it also demonstrates how to use selection and how to modify the scenegraph when a new file is loaded. Check it out!