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. Bitmaps.cpp
Mission NodeSDK 6.3C++renderingProject Included

Bitmaps.cpp

Example: Bitmaps.cpp

Examples / SDK 6.3 / C++ / rendering / Simple Shapes - Bitmaps / project / src
Bitmaps.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 "Bitmaps.h"
11
12using namespace Cubios::Gfx;
13
14//Applicaton initialization callback. Called once when CUB application starts
15void OnInit(Cubios::AppManager& appMgr)
16{
17 Bitmaps* theApp = new Bitmaps();
18
19 appMgr.SetApplication(theApp,"AAbbCCddEE");
20
21 theApp->InitializeResources();
22
23}
24
25
26Bitmaps::Bitmaps():incl(0.0)
27{
28}
29
30Bitmaps::~Bitmaps()
31{
32}
33
34void Bitmaps::InitializeResources()
35{
36 LOG_i("\n");
37 LOG_i("WOWCube SDK Example \"Simple Shapes - Bitmaps\" ***\n");
38
39 LOG_i("Cubeapp is initializing...");
40 LOG_i("Cubeapp is started on module %d",this->Module);
41
42 //Load images
43 bkg_image = Cubios::GFX_getAssetId("bkg.png");
44 fg_image = Cubios::GFX_getAssetId("fg.png");
45 sun_image = Cubios::GFX_getAssetId("star.png");
46
47 //Initialize sprites
48 planets[0].sprite = Cubios::GFX_getAssetId("planet1.png");
49 planets[0].x = 120.0;
50 planets[0].y = 120.0;
51 planets[0].angle = 0;
52 planets[0].radius = 100;
53 planets[0].speed = 0.05;
54 planets[0].orbIncl = 0.2;
55
56 planets[1].sprite = Cubios::GFX_getAssetId("planet2.png");
57 planets[1].x = 120.0;
58 planets[1].y = 120.0;
59 planets[1].angle = 30;
60 planets[1].radius = 60;
61 planets[1].speed = 0.07;
62 planets[1].orbIncl = 0.22;
63
64 planets[2].sprite = Cubios::GFX_getAssetId("planet3.png");
65 planets[2].x = 120.0;
66 planets[2].y = 120.0;
67 planets[2].angle = 200;
68 planets[2].radius = 160;
69 planets[2].speed = 0.01;
70 planets[2].orbIncl = 0.6;
71
72 LOG_i("Done.");
73}
74
75
76//This callback is called every "tick" of cubeapp application loop
77void Bitmaps::on_Tick(uint32_t currentTime, uint32_t deltaTime)
78{
79}
80
81//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
82void Bitmaps::on_Render(std::array<Cubios::Screen, 3>& screens)
83{
84 for(auto it = screens.begin(); it != screens.end(); ++it)
85 {
86 Cubios::GFX_setRenderTarget(it->ID());
87
88 //Render background
89 Cubios::GFX_drawImage(this->bkg_image, 128,128, 0xFF, Cubios::Gfx::Colors::black, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
90
91
92 //Render planets in proper z-order
93 for(int i=0;i<NUM_PLANETS;i++)
94 {
95 if(planets[i].z<0)
96 {
97 //Render planets behind the sun
98 Cubios::GFX_drawImage(planets[i].sprite,(int)planets[i].x,(int)planets[i].y, 0xFF, Cubios::Gfx::Colors::magenta, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
99 }
100 }
101
102 //Render sun
103 Cubios::GFX_drawImage( this->sun_image,128,128, 0xFF, Cubios::Gfx::Colors::black, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
104
105
106 for(int i=0;i<NUM_PLANETS;i++)
107 {
108 if(planets[i].z>0)
109 {
110 //Render planets in from of the sun
111 Cubios::GFX_drawImage(planets[i].sprite,(int)planets[i].x,(int)planets[i].y, 0xFF, Cubios::Gfx::Colors::magenta, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
112 }
113 }
114
115 //Render foreground glow
116 Cubios::GFX_drawImage(this->fg_image,128,128, 0xFF, Cubios::Gfx::Colors::black, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);
117
118 Cubios::GFX_render();
119 }
120}
121
122//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
123void Bitmaps::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
124{
125 //Calculate positions of plantes
126 for(int i=0;i<NUM_PLANETS;i++)
127 {
128 float fSin = sin(planets[i].angle);
129 float fCos = cos(planets[i].angle);
130
131 planets[i].angle += planets[i].speed;
132 if(planets[i].angle>PI_2) planets[i].angle = planets[i].angle-PI_2;
133
134 planets[i].x = 120.0 + planets[i].radius*fSin;
135 planets[i].y = 120.0 + planets[i].radius*fCos*planets[i].orbIncl*incl;
136
137 //Is the planet ahead of behind the sun?
138 if(planets[i].angle>PI/2 && planets[i].angle<PI_2-PI/2)
139 {
140 planets[i].z = 1;
141 }
142 else
143 {
144 planets[i].z = -1;
145 }
146 }
147
148 //Animate global inclanation
149 if(incl<1.0)
150 incl+=0.001;
151 else
152 if(incl>-1.0)
153 {
154 incl-=0.001;
155 }
156}
157
158//This callback is called on programmable timer (if any)
159void Bitmaps::on_Timer(uint8_t timerID)
160{
161}
162
163//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
164void Bitmaps::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
165{
166}
167
168//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
169void Bitmaps::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
170{
171}
172
173//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
174void Bitmaps::on_ExternalMessage(uint8_t* pkt, u32_t size)
175{
176}
177
178//Screen pat callback
179void Bitmaps::on_Pat(uint32_t count)
180{
181}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

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

Related nodes

Bitmaps.h
Examples / SDK 6.3 / C++ / rendering / Simple Shapes - Bitmaps / project / src
Simple Shapes - Bitmaps
Examples / SDK 6.3 / C++ / rendering
info.json
Examples / SDK 6.3 / C++ / rendering / Simple Shapes - Bitmaps
wowcubeapp-build.json
Examples / SDK 6.3 / C++ / rendering / Simple Shapes - Bitmaps / project
Previous Node
info.json
Examples / SDK 6.3 / C++ / rendering / Simple Shapes - Bitmaps
Next Node
Bitmaps.h
Examples / SDK 6.3 / C++ / rendering / Simple Shapes - Bitmaps / project / src