6.1 Standard Operators

6.1.1 Using operators
6.1.2 Combining operators

In addition to rendering a scene, your application will likely require some way for the user to interact with it. While you may choose to handle user input independently, HOOPS Visualize provides operators for this purpose. An operator is a hook into the user input event loop present on all supported GUI platforms. Visualize has a set of pre-built, standard operators to handle zooming, panning, and rotation, and also offers the ability to subclass these for custom functionality. When using operators in C++, include the header sprk_ops.h. All operators must derive from HPS::Operator.

The purpose of operators is to process input events. The three types of events that can be processed are HPS::KeyboardEvent, HPS::MouseEvent, and HPS::TouchEvent. Touch events are triggered in response to the action of the user's fingers on a touch-screen. Additionally, your operator can overload a function to intercept a timer tick event.

6.1.1 Using operators

When active, operators are always associated with a HPS::View object. For example, to enable the HPS::OrbitOperator, you would attach it to the view as shown:

[snippet 6.1.1.a]
// ... do other initialization
myView.GetOperatorControl().Push(orbitOperator); // makes 'orbitOperator' active
HPS.View myView = HPS.Factory.CreateView();
// ... do other initialization
HPS.OrbitOperator orbitOperator = new HPS.OrbitOperator(HPS.MouseButtons.ButtonMiddle());
myView.GetOperatorControl().Push(orbitOperator); // makes 'orbitOperator' active

Unlike most other HOOPS Visualize classes, C++ developers must use a pointer to instantiate and use the operator. However, after the call to Push, Visualize will take ownership of the pointer and you no longer have to keep a reference to it or worry about its deletion. Visualize will free the memory automatically.

In the code sample above, the parameter to the HPS::OrbitOperator constructor is called the operator trigger. You can combine the mouse button with a keyboard button to create a complex trigger. For example, if you want to orbit the scene when the user holds down CTRL and the right mouse button, you can add a HPS::ModifierKeys parameter, like so:

[snippet 6.1.1.b]
HPS.OrbitOperator orbitOperator
= new HPS.OrbitOperator(HPS.MouseButtons.ButtonRight(), HPS.ModifierKeys.KeyControl());
// ... do other initialization

If you require more complex logic than trapping a single modifier key, you should create your own operator, as the standard operators do not include logic to handle all possible keyboard combinations.

After the code above executes, you should be able to orbit the camera around your scene by dragging the middle mouse button. To disable the operator, detach it from the view.

[snippet 6.1.1.c]
orbitOperator->DetachView(); // detaching operator from the view
orbitOperator.DetachView(); // detaching operator from the view

This push-and-detach mechanic is identical for all the standard operators. Each instance of an operator can only be associated with a single HPS::View, however, one HPS::View can have multiple operators associated simultaneously in an operator stack. The operator that was attached last has receives the input event first. Generally speaking, an operator will consume an event if they have something they can do with it. For example, the HPS::PanOperator, which pans the scene when the user drags the mouse, will consume a HPS::MouseEvent but pass on a HPS::KeyboardEvent.

6.1.2 Combining operators

You can use the operator stack to combine operators, giving your scene the ability to respond to multiple types of input events. For example, you could use the mouse wheel input to zoom the scene, right button to pan, and left button to orbit. The code below demonstrates how you could set that up:

[snippet 6.1.2.a]
myView.GetOperatorControl().Push(new HPS.ZoomOperator(HPS.MouseButtons.ButtonMiddle()))
.Push(new HPS.PanOperator(HPS.MouseButtons.ButtonRight()))
.Push(new HPS.OrbitOperator(HPS.MouseButtons.ButtonLeft()));

HOOPS Visualize provides a number of standard operators that provide common functionality for interacting with a 3D scene, many of which can be combined.

Camera manipulation operators:

Selection operators:

Highlight operators:

Miscellaneous operators: