Unofficial community resource. Not affiliated with, maintained by, or endorsed by WOWCube / Cubios Inc. Cubios Inc. does not guarantee the accuracy or completeness of this content. Official WOWCube Development Kit

WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelogDeveloper Toolkit
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.

Unofficial community resource. Not affiliated with, maintained by, or endorsed by WOWCube / Cubios Inc. Cubios Inc. does not guarantee the accuracy or completeness of this content. For official documentation and the SDK, see the WOWCube Development Kit.

Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. Handling Twists
Mission NodeSDK 6.3C++topologyCode Snippet · Assets Not Included

Handling Twists

Topology Handling Twists First of all, what is a twist ? As per Oxford Dictionary, a twist is an act of rotating something around a stationary point. So ever...

Examples / SDK 6.3 / C++ / topology
VersionSDK 6.3SDK 6.2SDK 6.1
Report issue

Topology - Handling Twists

First of all, what is a twist ?

As per Oxford Dictionary, a twist is 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,

Handling Twists
CPP
1on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
2
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

callback is used.

This callback is called every time you twist your WOWCube thus changing its topology. The twist parameter of Cubios::TOPOLOGY_twistInfo_t type is a structure that contains the following fields:

Handling Twists
CPP
1struct TOPOLOGY_twistInfo_t
2{
3 int32_t screen;
4 int32_t count;
5 int32_t direction;
6};
7
8Fields:
9
10screen - an index of the screen around which a twist was performed
11count - a count of twists that have happened since the application started
12direction - a direction of a twist
13
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

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 InitializeResources() of course:

Handling Twists
CPP
1void HandleTwists::InitializeResources()
2{
3 ...
4
5 this->left = Cubios::GFX_getAssetId("left.png");
6 this->right = Cubios::GFX_getAssetId("right.png");
7 this->dbl = Cubios::GFX_getAssetId("dbl.png");
8
9 ...
10}
11
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

Then let's define the on_Twist callback as follows:

Handling Twists
CPP
1void HandleTwists::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
2{
3 this->screen = twist.screen;
4 this->direction = (Cubios::TOPOLOGY_twist_t)twist.direction;
5
6 this->animationOffset = 200;
7}
8
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.

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.

Handling Twists
CPP
1void HandleTwists::on_Render(std::array<Cubios::Screen, 3>& screens)
2{
3 for(auto it = screens.begin(); it != screens.end(); ++it)
4 {
5 Cubios::GFX_setRenderTarget(it->ID());
6 Cubios::GFX_clear(Colors::black);
7
8 if(it->ID()==this->screen)
9 {
10 iconPos.X = 120+this->animationOffset;
11
12 switch(this->direction)
13 {
14 case Cubios::TOPOLOGY_twist_t::TWIST_LEFT:
15 {
16 this->iconPos.X = 120+this->animationOffset;
17 Cubios::GFX_drawImage(this->left, this->iconPos.X, this->iconPos.Y, 0xFF, Cubios::Gfx::Colors::black,100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
18 }
19 break;
20 case Cubios::TOPOLOGY_twist_t::TWIST_RIGHT:
21 {
22 this->iconPos.X = 120-this->animationOffset;
23 Cubios::GFX_drawImage(this->right, this->iconPos.X, this->iconPos.Y, 0xFF, Cubios::Gfx::Colors::black,100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
24 }
25 break;
26 case Cubios::TOPOLOGY_twist_t:: TWIST_DOUBLE:
27 Cubios::GFX_drawImage(this->dbl,120,120, 0xFF, Cubios::Gfx::Colors::black,100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
28 break;
29 default:
30 break;
31 }
32 }
33
34 Cubios::GFX_render();
35 }
36}
37
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Trust & provenance

Document status

Source
SDK example metadata and source snippets
Classification
Code snippet · assets not included
Verification
Community-maintained · verify against installed SDK

Catalog updated Oct 20, 2018

Context Rail

Snippet files (assets not included)

HandleTwists.cpp
project/src/HandleTwists.cpp
HandleTwists.h
project/src/HandleTwists.h
wowcubeapp-build.json
project/wowcubeapp-build.json
Jump Grid

On This Page

Topology Handling TwistsThe example
Back to top ↑
Context Rail

Related nodes

info.json
Examples / SDK 6.3 / C++ / topology / Handling Twists
HandleTwists.cpp
Examples / SDK 6.3 / C++ / topology / Handling Twists / project / src
HandleTwists.h
Examples / SDK 6.3 / C++ / topology / Handling Twists / project / src
wowcubeapp-build.json
Examples / SDK 6.3 / C++ / topology / Handling Twists / project
Previous Node
wowcubeapp-build.json
Examples / SDK 6.3 / C++ / rendering / Gfx Engine - Animated Sprites and Sprite Atlases / project
Next Node
info.json
Examples / SDK 6.3 / C++ / topology / Handling Twists