Example: Bitmaps.cpp
1// This file is generated by WOWCube SDK project wizard23#include <stdint.h>4#include <string>5#include <vector>6#include <string>7#include <memory>89#include "AppManager.h"10#include "Bitmaps.h"1112using namespace Cubios::Gfx;1314//Applicaton initialization callback. Called once when CUB application starts15void OnInit(Cubios::AppManager& appMgr)16{17 Bitmaps* theApp = new Bitmaps();1819 appMgr.SetApplication(theApp,"AAbbCCddEE");2021 theApp->InitializeResources();2223}242526Bitmaps::Bitmaps():incl(0.0)27{28}2930Bitmaps::~Bitmaps()31{32}3334void Bitmaps::InitializeResources()35{36 LOG_i("\n");37 LOG_i("WOWCube SDK Example \"Simple Shapes - Bitmaps\" ***\n");3839 LOG_i("Cubeapp is initializing...");40 LOG_i("Cubeapp is started on module %d",this->Module);4142 //Load images43 bkg_image = Cubios::GFX_getAssetId("bkg.png");44 fg_image = Cubios::GFX_getAssetId("fg.png");45 sun_image = Cubios::GFX_getAssetId("star.png");4647 //Initialize sprites48 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;5556 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;6364 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;7172 LOG_i("Done.");73}747576//This callback is called every "tick" of cubeapp application loop77void Bitmaps::on_Tick(uint32_t currentTime, uint32_t deltaTime)78{79}8081//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());8788 //Render background89 Cubios::GFX_drawImage(this->bkg_image, 128,128, 0xFF, Cubios::Gfx::Colors::black, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);909192 //Render planets in proper z-order93 for(int i=0;i<NUM_PLANETS;i++)94 {95 if(planets[i].z<0)96 {97 //Render planets behind the sun98 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 }101102 //Render sun103 Cubios::GFX_drawImage( this->sun_image,128,128, 0xFF, Cubios::Gfx::Colors::black, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);104105106 for(int i=0;i<NUM_PLANETS;i++)107 {108 if(planets[i].z>0)109 {110 //Render planets in from of the sun111 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 }114115 //Render foreground glow116 Cubios::GFX_drawImage(this->fg_image,128,128, 0xFF, Cubios::Gfx::Colors::black, 100,100, 0, Cubios::GFX_mirror_t::MIRROR_BLANK);117118 Cubios::GFX_render();119 }120}121122//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 plantes126 for(int i=0;i<NUM_PLANETS;i++)127 {128 float fSin = sin(planets[i].angle);129 float fCos = cos(planets[i].angle);130131 planets[i].angle += planets[i].speed;132 if(planets[i].angle>PI_2) planets[i].angle = planets[i].angle-PI_2;133134 planets[i].x = 120.0 + planets[i].radius*fSin;135 planets[i].y = 120.0 + planets[i].radius*fCos*planets[i].orbIncl*incl;136137 //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 else143 {144 planets[i].z = -1;145 }146 }147148 //Animate global inclanation149 if(incl<1.0)150 incl+=0.001;151 else152 if(incl>-1.0)153 {154 incl-=0.001;155 }156}157158//This callback is called on programmable timer (if any)159void Bitmaps::on_Timer(uint8_t timerID)160{161}162163//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed164void Bitmaps::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)165{166}167168//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module169void Bitmaps::on_Message(uint32_t type, uint8_t* pkt, u32_t size)170{171}172173//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source174void Bitmaps::on_ExternalMessage(uint8_t* pkt, u32_t size)175{176}177178//Screen tap callback179void Bitmaps::on_Tap(uint32_t count)180{181}