-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
295 lines (218 loc) · 7.21 KB
/
main.cpp
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include <vector>
#include <cmath>
#include "Gesture.h"
#define EXPORT extern "C" __declspec(dllexport)
std::vector<Gesture*> gestureList;
double point_distance(double x1, double y1, double x2, double y2)
{
return sqrt(pow(x2-x1, 2) + pow(y2-y1, 2));
}
// POINTS FUNCTIONS****************
EXPORT double gesture_point_number(double id)
{
return gestureList[static_cast<int>(id)]->GetPoints().size();
}
EXPORT double gesture_point_x(double id, double index)
{
int ind = static_cast<int>(index) - 1;
if (ind < 0)
ind = 0;
return gestureList[static_cast<int>(id)]->GetPoints().at(ind)->x;
}
EXPORT double gesture_point_y(double id, double index)
{
int ind = static_cast<int>(index) - 1;
if (ind < 0)
ind = 0;
return gestureList[static_cast<int>(id)]->GetPoints().at(ind)->y;
}
//END OF POINTS FUNCTIONS**********
EXPORT double gesture_shape_create(double cutoff, double width, double height)
{
Gesture* newGesture = new Gesture((int)cutoff, (int)width, (int)height);
gestureList.push_back(newGesture);
// Return the element that references the new gesture.
return gestureList.size()-1;
}
EXPORT double gesture_shape_recreate(double id, double cutoff, double width, double height)
{
// Exit and return error if id is out of range.
if (id < 0 || id >= gestureList.size())
return -1;
// Get the reference to the gesture object we wish to recreate.
Gesture* gestureToRecreate = gestureList[(int)id];
gestureToRecreate->Recreate((int)cutoff, (int)width, (int)height);
return id;
}
EXPORT double gesture_shape_setup(double id, double cutoff, double width, double height)
{
// Check that the id passed is out of bounds (returning an error value: -1)
if (id < 0 || id >= gestureList.size())
return -1;
// Get the reference to the gesture object we wish to modify.
Gesture* gestureToModify = gestureList[(int)id];
// Change gesture's attributes.
gestureToModify->SetCutoff((int)cutoff);
gestureToModify->SetWidth((int)width);
gestureToModify->SetHeight((int)height);
return 1;
}
EXPORT double gesture_shape_subdivide(double id)
{
// Check that the id passed is out of bounds (returning an error value: -1)
if (id < 0 || id >= gestureList.size())
return -1;
Gesture* g = gestureList[(int)id];
int lastX = g->GetPoint()->x;
int lastY = g->GetPoint()->y;
std::vector<Gesture::Point> tempPoints;
for (std::vector<Gesture::Point*>::iterator itr = g->GetPoints().begin(); itr != g->GetPoints().end()-1; ++itr)
{
Gesture::Point temp;
tempPoints.push_back((**itr));
tempPoints.push_back(temp);
tempPoints.back().x = 0;
int px = (int)((**(itr+1)).x * 0.5);
int py = (int)((**(itr+1)).y * 0.5);
tempPoints.back().x = px;
tempPoints.back().y = py;
}
// Clear the current points list of this object.
while (g->GetPoints().size() > 0)
{
delete g->GetPoints().back();
g->GetPoints().erase(g->GetPoints().end());
}
// Copy values tempPoints to the points list of this object.
while (g->GetPoints().size() < tempPoints.size())
{
g->GetPoints().push_back(new Gesture::Point);
g->GetPoints().back()->x = tempPoints[g->GetPoints().size()-1].x;
g->GetPoints().back()->y = tempPoints[g->GetPoints().size()-1].y;
}
// Copy the last point.
g->GetPoints().push_back(new Gesture::Point);
g->GetPoints().back()->x = lastX;
g->GetPoints().back()->y = lastY;
return 1;
}
EXPORT double gesture_shape_addpoint(double id, double x, double y)
{
// Check if the id is out of range and return an error (-1)
if (id < 0 || id >= gestureList.size())
return -1;
// Allocate memory for the new point object.
Gesture::Point* newPoint = NULL;
newPoint = new Gesture::Point;
// If memory was not allocated, return an error (-1)
if (newPoint == NULL)
return -1;
// Retrieve a reference to the gesture and add a point.
Gesture* g = gestureList[(int)id];
g->GetPoints().push_back(newPoint);
g->GetPoints().back()->x = (int)x;
g->GetPoints().back()->y = (int)y;
return 1;
}
EXPORT double gesture_shape_mirror(double id, double replace)
{
// Exit and return error if id is out of bounds
if (id < 0 || id >= gestureList.size())
return -1;
//Cast id to type: int
int ID = static_cast<int>(id);
Gesture* g = gestureList[ID]; // Retrieve a reference to the id object.
int gestureID;
// To replace or not to replace.
if (replace == 0)
gestureID = static_cast<int>(gesture_shape_create(g->GetCutoff(), g->GetWidth(), g->GetHeight()));
else
gestureID = ID;
for (std::vector<Gesture::Point*>::iterator it = g->GetPoints().begin(); it != g->GetPoints().end(); ++it)
{
(*it)->x *= -1;
}
return gestureID;
}
EXPORT double gesture_shape_rotate(double id, double angle, double replace)
{
if (id < 0 || id >= gestureList.size())
return -1;
// Cast id to type: int
int ID = static_cast<int>(id);
Gesture* g = gestureList[ID]; // Retrieve a reference to the id object.
int gestureID;
// To replace or not to replace.
if (replace == 0)
gestureID = static_cast<int>(gesture_shape_create(g->GetCutoff(), g->GetWidth(), g->GetHeight()));
else
gestureID = ID;
for (std::vector<Gesture::Point*>::iterator it = g->GetPoints().begin(); it != g->GetPoints().end(); ++it)
{
//Rotate
// (*it)->x =
// (*it)->y
}
return gestureID;
}
EXPORT double gesture_shape_flip(double id, double replace)
{
double ID;
if (replace == 0)
{
Gesture* g = gestureList[static_cast<int>(id)];
ID = gesture_shape_create(g->GetCutoff(), g->GetWidth(), g->GetHeight());
}
else
ID = id;
// Loop through all the points and invert the Y value of each point.
for (int i = 0; i < static_cast<int>(gestureList[static_cast<int>(ID)]->GetPoints().size()); ++i)
{
gestureList[static_cast<int>(ID)]->GetPoints().at(i)->y *= -1;
}
return ID;
}
EXPORT double gesture_shape_reverse(double id, double replace)
{
double ID;
std::vector<Gesture::Point*> tempPoints; // Temp to store points so we can do switch-a-roo (t=a, a=b, b=t)
int tempxo, tempyo; // Don't know what these shits are for.
if (replace == 0)
{
Gesture* g = gestureList[static_cast<int>(id)];
ID = gesture_shape_create(g->GetCutoff(), g->GetWidth(), g->GetHeight());
}
else
ID = id;
for (int i = 0; i < static_cast<int>(gesture_point_number(ID)); ++i)
{
tempPoints.push_back(new Gesture::Point);
tempPoints.back()->x = gestureList[static_cast<int>(ID)]->GetPoints().at(i)->x;
tempPoints.back()->y = gestureList[static_cast<int>(ID)]->GetPoints().at(i)->y;
}
//Don't know what these shits are for.
tempxo = static_cast<int>(gesture_point_x(ID, gesture_point_number(ID)));
tempyo = static_cast<int>(gesture_point_y(ID, gesture_point_number(ID)));
for (int i = 0; i < gesture_point_number(ID); ++i)
{
gestureList[static_cast<int>(ID)]->GetPoints().at(i)->x = tempPoints.at(static_cast<int>(gesture_point_number(ID))-1-i)->x - tempxo;
gestureList[static_cast<int>(ID)]->GetPoints().at(i)->y = tempPoints.at(static_cast<int>(gesture_point_number(ID))-1-i)->y - tempyo;
delete tempPoints[i];
}
return ID;
}
EXPORT double gesture_shape_enable(double id, double enable)
{
gestureList[static_cast<int>(id)]->SetEnabled(static_cast<int>(enable));
return id;
}
EXPORT double gesture_shape_enable_all(double enable)
{
for (int i=0; i <static_cast<int>(gestureList.size()); ++i)
gestureList[i]->SetEnabled(static_cast<int>(enable));
return enable;
}
int main()
{
return 0;
}