Repository navigation
Expand file tree
/
Copy pathArduino3D.ino
More file actions
129 lines (104 loc) · 2.3 KB
/
Copy pathArduino3D.ino
File metadata and controls
129 lines (104 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* 3DGraphicsEngine
*
* Test the 3D graphics engine.
*/
#include "G3D.h"
#if USELIBRARY == 1
#include <SPI.h> // this is needed for display
#include <Wire.h> // this is needed for FT6206
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>
#elif USELIBRARY == 2
#endif
/*
* Drawing globals
*/
#if USELIBRARY == 1
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Graphics setup
G3D draw(tft,0,0,tft.width(),tft.height());
#elif USELIBRARY == 2
Arduboy arduboy;
// Graphics setup
G3D draw(arduboy,0,0,100,64);
#endif
// Rotation
static float GXAngle;
static float GYAngle;
void setup()
{
#if USELIBRARY == 1
tft.begin();
#elif USELIBRARY == 2
arduboy.beginNoLogo();
arduboy.setFrameRate(50);
arduboy.clear();
arduboy.display();
#endif
GXAngle = 0;
GYAngle = 0;
}
void transform()
{
draw.transformation.setIdentity();
draw.perspective(1.0f,0.5f);
draw.translate(0,0,-3.5);
draw.rotate(AXIS_X,GXAngle);
draw.rotate(AXIS_Y,GYAngle);
}
void drawBox(int x, int y, int z)
{
draw.move(x-1,y-1,z-1);
draw.draw(x+1,y-1,z-1);
draw.draw(x+1,y+1,z-1);
draw.draw(x-1,y+1,z-1);
draw.draw(x-1,y-1,z-1);
draw.draw(x-1,y-1,z+1);
draw.draw(x+1,y-1,z+1);
draw.draw(x+1,y+1,z+1);
draw.draw(x-1,y+1,z+1);
draw.draw(x-1,y-1,z+1);
draw.move(x+1,y-1,z-1);
draw.draw(x+1,y-1,z+1);
draw.move(x+1,y+1,z-1);
draw.draw(x+1,y+1,z+1);
draw.move(x-1,y+1,z-1);
draw.draw(x-1,y+1,z+1);
}
#if USELIBRARY == 1
void loop()
{
tft.fillScreen(ILI9341_BLACK);
draw.begin();
draw.setColor(ILI9341_RED);
transform();
drawBox(0,0,0);
draw.end();
delay(100);
draw.begin();
draw.setColor(ILI9341_BLACK);
drawBox(0,0,0);
draw.end();
GXAngle += 0.01;
GYAngle += 0.02;
}
#elif USELIBRARY == 2
void loop()
{
if (!arduboy.nextFrame()) return;
arduboy.clear();
draw.begin();
draw.setColor(WHITE);
transform();
drawBox(0,0,0);
draw.end();
arduboy.display();
GXAngle += 0.01;
GYAngle += 0.02;
}
#endif