WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. GfxOrientation.cpp
Mission NodeSDK 6.1C++renderingProject Included

GfxOrientation.cpp

Example: GfxOrientation.cpp

Examples / SDK 6.1 / C++ / rendering / Gfx Engine - Orientation / project / src
GfxOrientation.cpp
CPP
1// This file is generated by WOWCube SDK project wizard
2
3#include <stdint.h>
4#include <string>
5#include <vector>
6#include <string>
7#include <memory>
8
9#include "AppManager.h"
10#include "GfxOrientation.h"
11
12using namespace Cubios;
13using namespace Cubios::Math;
14using namespace Cubios::Gfx;
15
16//Applicaton initialization callback. Called once when CUB application starts
17void OnInit(Cubios::AppManager& appMgr)
18{
19 GfxOrientation* theApp = new GfxOrientation();
20
21 appMgr.SetApplication(theApp,"AAbbCCddEE");
22
23 theApp->InitializeResources();
24
25}
26
27
28GfxOrientation::GfxOrientation():currentMode(0)
29{
30}
31
32GfxOrientation::~GfxOrientation()
33{
34 this->Scene.DisposeAllObjects();
35}
36
37void GfxOrientation::InitializeResources()
38{
39 this->modes.push_back({TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_MENU,false,"MENU"});
40 this->modes.push_back({TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_MENU,true,"MENU"});
41 this->modes.push_back({TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,false,"GRAVITY"});
42 this->modes.push_back({TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true,"GRAVITY"});
43 this->modes.push_back({TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_SPLASH,false,"SPLASH"});
44 this->modes.push_back({TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_SPLASH,true,"SPLASH"});
45
46 //Create a Cubios::Gfx::Background object
47 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(0,0,0));
48
49 //Create animated sprite
50 this->Scene.CreateObjectWithID(GfxObjects::mySprite,new AnimatedSprite("torch","png",1,8,Transform(120,120,0)));
51 this->torch = dynamic_cast<AnimatedSprite*>(this->Scene[GfxObjects::mySprite]);
52 this->torch->SetPlaybackSpeed(100);
53 this->torch->SetPlaybackMode(AnimatedSprite::playbackMode_t::Loop);
54
55 //Create a Cubios::Gfx::Text objects
56 this->Scene.CreateObjectWithID(GfxObjects::myText1,new Text("TAP",120,20,9,Colors::gold));
57 this->Scene.CreateObjectWithID(GfxObjects::myText2,new Text("TO CHANGE",120,50,9,Colors::gold));
58 this->Scene.CreateObjectWithID(GfxObjects::myText3,new Text("ORIENTATION",120,80,9,Colors::gold));
59 this->Scene.CreateObjectWithID(GfxObjects::myText4,new Text("MODE",120,110,9,Colors::gold));
60
61 this->Scene.CreateObjectWithID(GfxObjects::myText5,new Text("-MODE-",120,160,6,Colors::tomato));
62 this->Scene.CreateObjectWithID(GfxObjects::myText6,new Text("GRAVITY",120,200,6,Colors::silver));
63
64 this->SetTimer(1,250);
65
66}
67
68//This callback is called every "tick" of cubeapp application loop
69void GfxOrientation::on_Tick(uint32_t currentTime, uint32_t deltaTime)
70{
71 this->torch->Tick(deltaTime);
72}
73
74//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
75void GfxOrientation::on_Render(std::array<Cubios::Screen, 3>& screens)
76{
77 for(auto it = screens.begin(); it != screens.end(); ++it)
78 {
79 //typically, you don't set orientation directly. But for this sample we have to do it.
80 it->SetOrientation(this->modes.at(this->currentMode).mode);
81
82 //Start adding objects to a screen
83 it->Begin(this->modes.at(this->currentMode).mode,this->modes.at(this->currentMode).autorotation);
84
85 //Add animated sprite on the sides of a cube
86 if(it->Direction()!=TOPOLOGY_orientation_t::ORIENTATION_UP && it->Direction()!=TOPOLOGY_orientation_t::ORIENTATION_DOWN)
87 {
88 if(this->Module==0)
89 {
90 it->Add(this->Scene[GfxObjects::myBackground]);
91
92 it->Add(this->Scene[GfxObjects::myText1]);
93 it->Add(this->Scene[GfxObjects::myText2]);
94 it->Add(this->Scene[GfxObjects::myText3]);
95 it->Add(this->Scene[GfxObjects::myText4]);
96
97 if(this->modes.at(this->currentMode).autorotation)
98 dynamic_cast<Text*>(it->Add(this->Scene[GfxObjects::myText5]))->SetContent("AUTOROTATION:ON")
99 ->SetColor(Colors::lime);
100 else
101 dynamic_cast<Text*>(it->Add(this->Scene[GfxObjects::myText5]))->SetContent("AUTOROTATION:OFF")
102 ->SetColor(Colors::tomato);
103
104 dynamic_cast<Text*>(it->Add(this->Scene[GfxObjects::myText6]))->FormatContent("MODE:%s", this->modes.at(this->currentMode).name.c_str());
105 }
106 else
107 {
108 it->Add(this->torch);
109 }
110 }
111 else
112 {
113 //Add background
114 it->Add(this->Scene[GfxObjects::myBackground]);
115 }
116
117 //Finish adding objects
118 it->End();
119 }
120}
121
122//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
123void GfxOrientation::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
124{
125}
126
127//This callback is called on programmable timer (if any)
128void GfxOrientation::on_Timer(uint8_t timerID)
129{
130}
131
132//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
133void GfxOrientation::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
134{
135}
136
137//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
138void GfxOrientation::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
139{
140 NetworkMessage nm(pkt,size);
141
142 if(this->Module!=0)
143 {
144 //Read incoming mode
145 this->currentMode = nm.ReadInt(4);
146 }
147
148}
149
150//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
151void GfxOrientation::on_ExternalMessage(uint8_t* pkt, u32_t size)
152{
153}
154
155//Screen tap callback
156void GfxOrientation::on_Tap(uint32_t count)
157{
158 if(this->Module==0)
159 {
160 if(this->currentMode<5)
161 {
162 this->currentMode++;
163 }
164 else
165 {
166 this->currentMode = 0;
167 }
168
169 NetworkMessage msg;
170 msg.WriteInt(this->currentMode,4); //4 bits is enough
171
172 //send new mode to all modules
173 this->SendNetworkMessage(1,&msg);
174 }
175}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

GfxOrientation.cpp
project/src/GfxOrientation.cpp
GfxOrientation.h
project/src/GfxOrientation.h
wowcubeapp-build.json
project/wowcubeapp-build.json
Context Rail

Related nodes

GfxOrientation.h
Examples / SDK 6.1 / C++ / rendering / Gfx Engine - Orientation / project / src
Gfx Engine - Orientation
Examples / SDK 6.1 / C++ / rendering
info.json
Examples / SDK 6.1 / C++ / rendering / Gfx Engine - Orientation
wowcubeapp-build.json
Examples / SDK 6.1 / C++ / rendering / Gfx Engine - Orientation / project
Previous Node
info.json
Examples / SDK 6.1 / C++ / rendering / Gfx Engine - Orientation
Next Node
GfxOrientation.h
Examples / SDK 6.1 / C++ / rendering / Gfx Engine - Orientation / project / src