-
Notifications
You must be signed in to change notification settings - Fork 18
/
sprite.ino
135 lines (112 loc) · 3.11 KB
/
sprite.ino
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
130
131
132
133
134
135
/**
* Polargraph Server for ATMEGA1280+
* Written by Sandy Noble
* Released under GNU License version 3.
* http://www.polargraph.co.uk
* https://github.com/euphy/polargraph_server_polarshield
Specific features for Polarshield / arduino mega.
Sprite.
Methods that handle drawing and processing vector sprites.
*/
void sprite_drawSprite()
{
int spriteScale = atoi(inParam1);
String spriteFilename = inParam2;
// flip just B axis to orientate for SE drawing
int spriteScaleX = spriteScale;
int spriteScaleY = -spriteScale;
int rotation = 0;
// and work out rotation value
if (globalDrawDirection == DIR_SE) // 2
{
rotation = 0;
}
else if (globalDrawDirection == DIR_NW) // 4
{
rotation = 180;
}
else if (globalDrawDirection == DIR_SW) //3
{
rotation = 90;
}
else //(drawDirection == DIR_NE) // default //1
{
rotation = 270;
}
boolean okToDraw = false;
if (useRoveArea)
{
Serial.println("Must use rove area.");
// if you're using the rove area, then make sure it's in it before drawing
if (rove_inRoveArea(motorA.currentPosition(), motorB.currentPosition()))
{
Serial.println("You're already in the rove area!");
okToDraw = true;
}
else
{
Serial.println("You're outside of the rove area!");
// if drawing text then move to the next line
if (textRowSize > 1)
{
Serial.println("Using text rows.");
// drawing text
// so work out the beginning of the next line
boolean nextLine = rove_moveToBeginningOfNextTextLine();
Serial.print("Next line calculated:");
Serial.println(nextLine);
if (nextLine)
okToDraw = true;
}
else // not drawing text
{
Serial.println("Not drawing text, AND outside the rove area.");
}
}
}
else
{
Serial.println("Ok to draw - no roving.");
// otherwise just draw it here
okToDraw = true;
}
if (okToDraw)
sprite_drawSprite(spriteScaleX, spriteScaleY, rotation, spriteFilename);
}
void sprite_drawSprite(int sX, int sY, int rotation, String filename)
{
Serial.println("Draw sprite.");
// save the old settings
float oldTranslateX = translateX;
float oldTranslateY = translateY;
float oldScaleX = scaleX;
float oldScaleY = scaleY;
int oldRotation = rotateTransform;
// Serial.print("1.ScaleX:");
// Serial.println(scaleX);
// Serial.print("1.translateX:");
// Serial.println(translateX);
// apply the transform parameters
translateX = motorA.currentPosition();
translateY = motorB.currentPosition();
scaleX = sX;
scaleY = sY;
rotateTransform = rotation;
// Serial.print("2.ScaleX:");
// Serial.println(scaleX);
// Serial.print("2.translateX:");
// Serial.println(translateX);
// open the file
currentlyDrawingFromFile = true;
impl_exec_execFromStore(filename);
// undo the transformation
translateX = oldTranslateX;
translateY = oldTranslateY;
scaleX = oldScaleX;
scaleY = oldScaleY;
rotateTransform = oldRotation;
}
void sprite_drawRandomPositionedSprite()
{
Serial.println("This doesn't work yet.");
}