2020-07-08 09:05:02 +02:00
|
|
|
//
|
|
|
|
// Created by Wouter Groeneveld on 02/08/18.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <libgba-sprite-engine/gba/tonc_memdef.h>
|
|
|
|
#include <libgba-sprite-engine/gba_engine.h>
|
2020-07-10 17:36:13 +02:00
|
|
|
#include <libgba-sprite-engine/background/text_stream.h>
|
2020-07-08 09:05:02 +02:00
|
|
|
#include "wirescene.h"
|
|
|
|
|
|
|
|
|
2020-07-08 18:12:38 +02:00
|
|
|
const unsigned short pal[4] __attribute__((aligned(4))) = {
|
2020-07-08 09:05:02 +02:00
|
|
|
0x0000, 0xFFFF, 0x3AE2
|
|
|
|
};
|
|
|
|
|
2020-07-08 18:12:38 +02:00
|
|
|
std::vector<Mesh*> WireScene::meshes() {
|
|
|
|
return { cube.get() };
|
|
|
|
}
|
|
|
|
|
2020-07-09 13:29:02 +02:00
|
|
|
Camera WireScene::camera() {
|
|
|
|
return Camera(VectorFx::fromInt(0, 0, 10), VectorFx::fromInt(0, 0, 0));
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:36:13 +02:00
|
|
|
int msecs = 1;
|
2020-07-08 09:05:02 +02:00
|
|
|
void WireScene::load() {
|
|
|
|
foregroundPalette = std::unique_ptr<ForegroundPaletteManager>(new ForegroundPaletteManager());
|
|
|
|
backgroundPalette = std::unique_ptr<BackgroundPaletteManager>(new BackgroundPaletteManager(pal, sizeof(pal)));
|
2020-07-08 18:12:38 +02:00
|
|
|
|
|
|
|
cube = std::unique_ptr<Mesh>(new Mesh());
|
2020-07-09 15:48:03 +02:00
|
|
|
cube->add(VectorFx::fromInt(-1, 1, 1));
|
|
|
|
cube->add(VectorFx::fromInt(1, 1, 1));
|
|
|
|
cube->add(VectorFx::fromInt(-1, -1, 1));
|
|
|
|
cube->add(VectorFx::fromInt(-1, -1, -1));
|
|
|
|
cube->add(VectorFx::fromInt(-1, 1, -1));
|
|
|
|
cube->add(VectorFx::fromInt(1, 1, -1));
|
|
|
|
cube->add(VectorFx::fromInt(1, -1, 1));
|
|
|
|
cube->add(VectorFx::fromInt(1, -1, -1));
|
2020-07-10 14:41:32 +02:00
|
|
|
|
|
|
|
cube->addFace({ 0, 1, 2});
|
|
|
|
cube->addFace({ 1, 2, 3});
|
|
|
|
cube->addFace({ 1, 3, 6});
|
|
|
|
cube->addFace({ 1, 5, 6});
|
|
|
|
cube->addFace({ 0, 1, 4});
|
|
|
|
cube->addFace({ 1, 4, 5});
|
|
|
|
|
|
|
|
cube->addFace({ 2, 3, 7});
|
|
|
|
cube->addFace({ 3, 6, 7});
|
|
|
|
cube->addFace({ 0, 2, 7});
|
|
|
|
cube->addFace({ 0, 4, 7});
|
|
|
|
cube->addFace({ 4, 5, 6});
|
|
|
|
cube->addFace({ 4, 6, 7});
|
2020-07-10 17:36:13 +02:00
|
|
|
|
|
|
|
engine->getTimer()->start();
|
2020-07-08 09:05:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void WireScene::tick(u16 keys) {
|
2020-07-10 17:36:13 +02:00
|
|
|
int curmsecs = engine->getTimer()->getMsecs();
|
|
|
|
int elapsed = curmsecs - msecs;
|
|
|
|
msecs = curmsecs;
|
|
|
|
|
|
|
|
TextStream::instance().setText(std::to_string(1000 / elapsed) + std::string(" FPS"), 1, 1);
|
|
|
|
|
2020-07-10 11:11:49 +02:00
|
|
|
cube->rotate(2, 2);
|
2020-07-10 14:41:32 +02:00
|
|
|
|
|
|
|
if(keys & KEY_A) {
|
2020-07-09 15:48:03 +02:00
|
|
|
cube->resetRotation();
|
2020-07-10 14:41:32 +02:00
|
|
|
} else if(keys & KEY_B) {
|
|
|
|
if(cube->isWired()) {
|
|
|
|
cube->unwire();
|
|
|
|
} else {
|
|
|
|
cube->wire();
|
|
|
|
}
|
2020-07-09 15:48:03 +02:00
|
|
|
}
|
2020-07-08 09:05:02 +02:00
|
|
|
}
|