Topology - Handling Twists
First of all, what is a twist ?
As per Oxford Dictionary, a
twistis an act of rotating something around a stationary point.
So every time you play with your WOWCube and rotate its modules relatively to each other, you are actually twisting them around the common rotation center, i.e. a centre of the device.
What also happening when you twist your device is this: device topology gets changed.
The word topology means “The study of mappings”.
But what exactly do we call a topology ?
There are several different definitions of what topology really is. In mathematcis, topology is concerned with a shape of a geometric object and how various transformations affect it. In networking it is common to define topology as a way of arranging of multiple devices that are the elements of a communication network. And in ecology it is the study of patterns of interconnections in an eco-system, and specifically called ecological topology.
In WOWCube Development Kit topology is defined as
а mutual arrangement of device modules relative to each other
while in order to detect a change of topology,
callback is used.
This callback is called every time you twist your WOWCube thus changing its topology. The twist parameter of TOPOLOGY_TWIST_INFO type is a structure that contains the following fields:
As a matter of fact, handling WOWCube twists is easy. Let's get to coding...
The example
To demonstrate how twists are handled, let's create a simple cubeapp that just detects a twist and shows its direction.
First of all, let's load some images in order to make our cubeapp a little prettier. This is done in the ON_Init() callback of course:
Then let's define the ON_Twist callback as follows:
This callback gets called every time the topology of WOWCube gets changed. So every time it happens we will register a screen index and a direction in which the screen has been twisted, i.e rotated.
And finally, we will use these values to play some neat animation.