Repository navigation
Expand file tree
/
Copy pathwarpfunc.c
More file actions
174 lines (144 loc) · 5.54 KB
/
Copy pathwarpfunc.c
File metadata and controls
174 lines (144 loc) · 5.54 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
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
#include "warpfunc.h"
point_t warp_up_away(point_t a, int t){
int x = a.x;
int y = a.y;
point_t r;
y += (BEZ_SCALEDOWN/10 * 5) * t;
x = (x-BEZ_SCALEDOWN*160) * (500 - y/BEZ_SCALEDOWN) / 500;
y = y * (1000 - y/BEZ_SCALEDOWN) / 1000;
x += BEZ_SCALEDOWN*160;
// x += (BEZ_SCALEDOWN/10 * 2) * t;
r.x=x; r.y=y; return r;
}
//#define BEZ_SCALEDOWN 1
point_t warp_perspective(point_t a, int t){
int x = a.x;
int y = a.y;
point_t r;
point_t A = {0*BEZ_SCALEDOWN,0*BEZ_SCALEDOWN+t*400};
point_t C = {30*BEZ_SCALEDOWN+t*50,180*BEZ_SCALEDOWN+t*200};
point_t B = {320*BEZ_SCALEDOWN,10*BEZ_SCALEDOWN+t*420};
point_t D = {(320-40)*BEZ_SCALEDOWN-t*80,200*BEZ_SCALEDOWN+t*220};
point_t Z = psub(padd(A,D),padd(B,C));
point_t dX = psub(B,A);
point_t dY = psub(C,A);
int xmax = BEZ_SCALEDOWN*320;
int ymax = BEZ_SCALEDOWN*200;
int xyscale = 4096; // NOT LARGER, or else it overflows int32_t
int xyscale_log2 = 12;
// scale x and y
x = x * xyscale / xmax;
y = y * xyscale / ymax;
// quickfix
// x += 2000;
// calc xy(and scale)
int xy = x * y / xyscale;
r = pscale(Z, xy, xyscale_log2);
r = padd(r, pscale(dX, x, xyscale_log2));
r = padd(r, pscale(dY, y, xyscale_log2));
r = padd(r, A);
return r;
}
inline point_t warp_perspective_generic(point_t a, int t, int* coords, int* deltas){
point_t A, B, C, D;
point_t dA, dB, dC, dD;
A.x = coords[0]; A.y = coords[1];
B.x = coords[2]; B.y = coords[3];
C.x = coords[4]; C.y = coords[5];
D.x = coords[6]; D.y = coords[7];
dA.x = deltas[0]; dA.y = deltas[1];
dB.x = deltas[2]; dB.y = deltas[3];
dC.x = deltas[4]; dC.y = deltas[5];
dD.x = deltas[6]; dD.y = deltas[7];
//inline point_t warp_perspective_generic(point_t a, int t, point_t A, point_t B, point_t C, point_t D,
// point_t dA, point_t dB, point_t dC, point_t dD){
int x = a.x;
int y = a.y;
point_t r;
// scale by BEZ_SCALEDOWN, so that the user can enter points in screen coordinates
A = pmul(A, BEZ_SCALEDOWN);
B = pmul(B, BEZ_SCALEDOWN);
C = pmul(C, BEZ_SCALEDOWN);
D = pmul(D, BEZ_SCALEDOWN);
// apply t-movement
A = padd(pmul(dA,t),A);
B = padd(pmul(dB,t),B);
C = padd(pmul(dC,t),C);
D = padd(pmul(dD,t),D);
point_t Z = psub(padd(A,D),padd(B,C));
point_t dX = psub(B,A);
point_t dY = psub(C,A);
int xmax = BEZ_SCALEDOWN*320;
int ymax = BEZ_SCALEDOWN*200;
int xyscale = 4096; // NOT LARGER, or else it overflows int32_t
int xyscale_log2 = 12;
// scale x and y
x = x * xyscale / xmax;
y = y * xyscale / ymax;
// quickfix
// x += 2000;
// calc xy(and scale)
int xy = x * y / xyscale;
r = pscale(Z, xy, xyscale_log2);
r = padd(r, pscale(dX, x, xyscale_log2));
r = padd(r, pscale(dY, y, xyscale_log2));
r = padd(r, A);
return r;
}
point_t warp_perspective_1(point_t a, int t){
return warp_perspective_generic(a, t,
(int[]){0,0, 320,10, 30, 180, 280,200},
(int[]){0,400, 0,420, 50, 200, -80,220});
}
point_t warp_perspective_2(point_t a, int t){ // fast drift left
return warp_perspective_generic(a, t,
(int[]){0,10, 320,0, 40, 200, 290,180},
(int[]){-1000,400, -800,420, -1050, 200, -880,220});
}
point_t warp_perspective_3(point_t a, int t){ // upside-down
return warp_perspective_generic(a, t,
(int[]){300,200,30,180, 340,10, 0,0},
(int[]){0,400, 0,420, 50, 200, -80,220});
}
point_t warp_perspective_rotright(point_t a, int t){ // rotate right
t = (t-30)*2;
return warp_perspective_generic(a, t,
(int[]){0,0, 320,30, 30, 180, 290,200},
(int[]){-500,700, -500,-300, 400, 600, 400,-200});
}
point_t warp_perspective_5(point_t a, int t){ // slightly fast drift left
return warp_perspective_generic(a, t,
(int[]){0,0, 320,30, 40, 200, 290,180},
(int[]){-700,-150, -600,0, -750, 0, -680,220});
}
point_t warp_perspective_4(point_t a, int t){ // mirrored to 1
return warp_perspective_generic(a, t,
(int[]){0,10, 320,0, 40, 200, 290,180},
(int[]){0,400, 0,420, 50, 200, -80,220});
}
point_t warp_perspective_6(point_t a, int t){ // right side drifting up
return warp_perspective_generic(a, t,
(int[]){0,10, 320,0, 40, 200, 290,180},
(int[]){-200,50, -70,560, -330, 70, -80,520});
}
point_t warp_perspective_inverted(point_t a, int t){ // trapezoid inverted
return warp_perspective_generic(a, t,
(int[]){80,15, 245,2, 0, 200, 320,180},
(int[]){0,400, 0,420, 50, 200, -80,220});
}
point_t warp_perspective_zoomin(point_t a, int t){ // zoom in
return warp_perspective_generic(a, t,
(int[]){0,10, 320,0, 40, 200, 290,180},
(int[]){-500,-1000, 1500,-1000, -500,1000, 1500,1000});
}
point_t warp_perspective_zoomout(point_t a, int t){ // zoom out
t -= 40;
return warp_perspective_generic(a, t,
(int[]){-10,0, 330,20, 30, 180, 300,195},
(int[]){2400,1000, -800,1000, 2400,-1000, -800,-1000});
}
point_t warp_perspective_7(point_t a, int t){ // significant right slant, almost no drift
return warp_perspective_generic(a, t,
(int[]){0,30, 320,0, 40, 200, 290,173},
(int[]){-20,60, -20,60, -90, 80, -90,80});
}