author | unc0rr |
Tue, 18 Mar 2014 00:01:52 +0400 | |
changeset 10201 | 9bee9541edf1 |
parent 10200 | edc2fe0ca03f |
child 10202 | f7c8cb11a70e |
permissions | -rw-r--r-- |
10198 | 1 |
unit uLandGenTemplateBased; |
2 |
interface |
|
3 |
||
4 |
uses uLandTemplates; |
|
5 |
||
6 |
procedure GenTemplated(var Template: TEdgeTemplate); |
|
7 |
||
8 |
implementation |
|
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
9 |
uses uVariables, uConsts, uFloat, uLandOutline, uLandUtils, uRandom, SDLh, math; |
10198 | 10 |
|
11 |
||
12 |
procedure SetPoints(var Template: TEdgeTemplate; var pa: TPixAr; fps: PPointArray); |
|
13 |
var i: LongInt; |
|
14 |
begin |
|
15 |
with Template do |
|
16 |
begin |
|
17 |
pa.Count:= BasePointsCount; |
|
18 |
for i:= 0 to pred(pa.Count) do |
|
19 |
begin |
|
20 |
pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w)); |
|
21 |
if pa.ar[i].x <> NTPX then |
|
10199 | 22 |
pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2); |
10198 | 23 |
pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight) |
24 |
end; |
|
25 |
||
26 |
if canMirror then |
|
27 |
if getrandom(2) = 0 then |
|
28 |
begin |
|
29 |
for i:= 0 to pred(BasePointsCount) do |
|
30 |
if pa.ar[i].x <> NTPX then |
|
31 |
pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x; |
|
32 |
for i:= 0 to pred(FillPointsCount) do |
|
33 |
fps^[i].x:= LAND_WIDTH - 1 - fps^[i].x; |
|
34 |
end; |
|
35 |
||
36 |
(* Experiment in making this option more useful |
|
37 |
if ((not isNegative) and (cTemplateFilter = 4)) or |
|
38 |
(canFlip and (getrandom(2) = 0)) then |
|
39 |
begin |
|
40 |
for i:= 0 to pred(BasePointsCount) do |
|
41 |
begin |
|
42 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y + (LAND_HEIGHT - TemplateHeight) * 2; |
|
43 |
if pa.ar[i].y > LAND_HEIGHT - 1 then |
|
44 |
pa.ar[i].y:= LAND_HEIGHT - 1; |
|
45 |
end; |
|
46 |
for i:= 0 to pred(FillPointsCount) do |
|
47 |
begin |
|
48 |
FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y + (LAND_HEIGHT - TemplateHeight) * 2; |
|
49 |
if FillPoints^[i].y > LAND_HEIGHT - 1 then |
|
50 |
FillPoints^[i].y:= LAND_HEIGHT - 1; |
|
51 |
end; |
|
52 |
end; |
|
53 |
end |
|
54 |
*) |
|
55 |
// template recycling. Pull these off the floor a bit |
|
56 |
if (not isNegative) and (cTemplateFilter = 4) then |
|
57 |
begin |
|
58 |
for i:= 0 to pred(BasePointsCount) do |
|
59 |
begin |
|
60 |
dec(pa.ar[i].y, 100); |
|
61 |
if pa.ar[i].y < 0 then |
|
62 |
pa.ar[i].y:= 0; |
|
63 |
end; |
|
64 |
for i:= 0 to pred(FillPointsCount) do |
|
65 |
begin |
|
66 |
dec(fps^[i].y, 100); |
|
67 |
if fps^[i].y < 0 then |
|
68 |
fps^[i].y:= 0; |
|
69 |
end; |
|
70 |
end; |
|
71 |
||
72 |
if (canFlip and (getrandom(2) = 0)) then |
|
73 |
begin |
|
74 |
for i:= 0 to pred(BasePointsCount) do |
|
75 |
pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y; |
|
76 |
for i:= 0 to pred(FillPointsCount) do |
|
77 |
fps^[i].y:= LAND_HEIGHT - 1 - fps^[i].y; |
|
78 |
end; |
|
79 |
end |
|
80 |
end; |
|
10199 | 81 |
|
82 |
||
83 |
procedure Distort1(var Template: TEdgeTemplate; var pa: TPixAr); |
|
84 |
var i: Longword; |
|
85 |
begin |
|
86 |
for i:= 1 to Template.BezierizeCount do |
|
87 |
begin |
|
88 |
BezierizeEdge(pa, _0_5); |
|
89 |
RandomizePoints(pa); |
|
90 |
RandomizePoints(pa) |
|
91 |
end; |
|
92 |
for i:= 1 to Template.RandPassesCount do |
|
93 |
RandomizePoints(pa); |
|
94 |
BezierizeEdge(pa, _0_1); |
|
95 |
end; |
|
96 |
||
97 |
||
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
98 |
procedure FindPoint(si: LongInt; var newPoint: TPoint; var pa: TPixAr); |
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
99 |
const mapBorderMargin = 30; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
100 |
minDistance = 20; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
101 |
var p1, p2, mp: TPoint; |
10199 | 102 |
i, t1, t2, a, b, p, q, iy, ix, aqpb: LongInt; |
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
103 |
dab, d, distL, distR: LongInt; |
10199 | 104 |
begin |
105 |
// [p1, p2] is segment we're trying to divide |
|
106 |
p1:= pa.ar[si]; |
|
107 |
p2:= pa.ar[si + 1]; |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
108 |
writeln('====================== ', p1.x, '; ', p1.y, ' --- ', p2.x, '; ', p2.y); |
10199 | 109 |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
110 |
// perpendicular vector |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
111 |
a:= p2.y - p1.y; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
112 |
b:= p1.x - p2.x; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
113 |
dab:= DistanceI(a, b).Round; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
114 |
|
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
115 |
if (p1.x = NTPX) or (p2.x = NTPX) or (dab < minDistance * 3) then |
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
116 |
begin |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
117 |
newPoint:= p1; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
118 |
exit; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
119 |
end; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
120 |
|
10199 | 121 |
// its middle point |
122 |
mp.x:= (p1.x + p2.x) div 2; |
|
123 |
mp.y:= (p1.y + p2.y) div 2; |
|
124 |
||
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
125 |
// find distances to map borders |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
126 |
if a <> 0 then |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
127 |
begin |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
128 |
// left border |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
129 |
iy:= (mapBorderMargin - mp.x) * b div a + mp.y; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
130 |
d:= DistanceI(mp.x - mapBorderMargin, mp.y - iy).Round; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
131 |
t1:= a * (mp.x - mapBorderMargin) + b * (mp.y - iy); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
132 |
if t1 > 0 then distL:= d else distR:= d; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
133 |
|
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
134 |
// right border |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
135 |
iy:= (LAND_WIDTH - mapBorderMargin - mp.x) * b div a + mp.y; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
136 |
d:= DistanceI(mp.x - LAND_WIDTH + mapBorderMargin, mp.y - iy).Round; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
137 |
if t1 > 0 then distR:= d else distL:= d; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
138 |
end; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
139 |
|
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
140 |
if b <> 0 then |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
141 |
begin |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
142 |
// top border |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
143 |
ix:= (mapBorderMargin - mp.y) * a div b + mp.x; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
144 |
d:= DistanceI(mp.y - mapBorderMargin, mp.x - ix).Round; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
145 |
t2:= b * (mp.y - mapBorderMargin) + a * (mp.x - ix); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
146 |
if t2 > 0 then distL:= min(d, distL) else distR:= min(d, distR); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
147 |
|
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
148 |
// bottom border |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
149 |
ix:= (LAND_HEIGHT - mapBorderMargin - mp.y) * a div b + mp.x; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
150 |
d:= DistanceI(mp.y - LAND_HEIGHT + mapBorderMargin, mp.x - ix).Round; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
151 |
if t2 > 0 then distR:= min(d, distR) else distL:= min(d, distL); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
152 |
end; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
153 |
|
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
154 |
// now go through all other segments |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
155 |
for i:= 0 to pa.Count - 2 do |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
156 |
if (i <> si) and (pa.ar[i].x <> NTPX) and (pa.ar[i + 1].x <> NTPX) then |
10199 | 157 |
begin |
158 |
// check if it intersects |
|
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
159 |
t1:= (mp.x - pa.ar[i].x) * b - a * (mp.y - pa.ar[i].y); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
160 |
t2:= (mp.x - pa.ar[i + 1].x) * b - a * (mp.y - pa.ar[i + 1].y); |
10199 | 161 |
|
162 |
if (t1 > 0) <> (t2 > 0) then // yes it does, hard arith follows |
|
163 |
begin |
|
164 |
p:= pa.ar[i + 1].x - pa.ar[i].x; |
|
165 |
q:= pa.ar[i + 1].y - pa.ar[i].y; |
|
166 |
aqpb:= a * q - p * b; |
|
167 |
||
168 |
if (aqpb <> 0) then |
|
169 |
begin |
|
170 |
// (ix; iy) is intersection point |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
171 |
iy:= (((pa.ar[i].x - mp.x) * b + mp.y * a) * q - pa.ar[i].y * p * b) div aqpb; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
172 |
if abs(b) > abs(q) then |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
173 |
ix:= (iy - mp.y) * a div b + mp.x |
10199 | 174 |
else |
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
175 |
ix:= (iy - pa.ar[i].y) * p div q + pa.ar[i].x; |
10199 | 176 |
|
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
177 |
d:= DistanceI(mp.y - iy, mp.x - ix).Round; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
178 |
t1:= b * (mp.y - iy) + a * (mp.x - ix); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
179 |
if t1 > 0 then distL:= min(d, distL) else distR:= min(d, distR); |
10199 | 180 |
end; |
181 |
end; |
|
182 |
end; |
|
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
183 |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
184 |
|
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
185 |
// don't move new point for more than 3/4 length of initial segment |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
186 |
d:= dab * 3 div 4; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
187 |
if distL > d then distL:= d; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
188 |
if distR > d then distR:= d; |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
189 |
|
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
190 |
if distR + distL < minDistance * 2 then |
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
191 |
begin |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
192 |
// limits are too narrow, leave point alone |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
193 |
newPoint:= p1 |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
194 |
end |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
195 |
else |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
196 |
begin |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
197 |
// select distance within [-distL; distR] |
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
198 |
d:= -distL + minDistance + GetRandom(distR + distL - minDistance * 2); |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
199 |
//d:= distR - minDistance; |
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
200 |
|
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
201 |
// calculate new point |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
202 |
newPoint.x:= mp.x + a * d div dab; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
203 |
newPoint.y:= mp.y + b * d div dab; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
204 |
|
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
205 |
writeln('New Point ', newPoint.x, '; ', newPoint.y); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
206 |
end; |
10199 | 207 |
end; |
208 |
||
209 |
procedure DivideEdges(var pa: TPixAr); |
|
210 |
var npa: TPixAr; |
|
211 |
i: LongInt; |
|
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
212 |
newPoint: TPoint; |
10199 | 213 |
begin |
214 |
i:= 0; |
|
215 |
npa.Count:= 0; |
|
216 |
while i < pa.Count do |
|
217 |
begin |
|
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
218 |
npa.ar[npa.Count]:= pa.ar[i]; |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
219 |
inc(npa.Count); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
220 |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
221 |
if i < pa.Count - 1 then |
10199 | 222 |
begin |
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
223 |
FindPoint(i, newPoint, pa); |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
224 |
if (newPoint.x <> pa.ar[i].x) or (newPoint.y <> pa.ar[i].y) then |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
225 |
begin |
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
226 |
npa.ar[npa.Count]:= newPoint; |
10199 | 227 |
inc(npa.Count) |
10200
edc2fe0ca03f
More math, implementation is nearly complete, just still have an issue to resolve
unc0rr
parents:
10199
diff
changeset
|
228 |
end; |
10199 | 229 |
end; |
230 |
||
231 |
inc(i) |
|
232 |
end; |
|
233 |
||
234 |
pa:= npa; |
|
235 |
end; |
|
236 |
||
237 |
procedure Distort2(var Template: TEdgeTemplate; var pa: TPixAr); |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
238 |
var i: Longword; |
10199 | 239 |
begin |
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
240 |
for i:= 1 to Template.BezierizeCount do |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
241 |
DivideEdges(pa); |
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
242 |
|
10199 | 243 |
{for i:= 1 to Template.BezierizeCount do |
244 |
begin |
|
245 |
BezierizeEdge(pa, _0_5); |
|
246 |
RandomizePoints(pa); |
|
247 |
RandomizePoints(pa) |
|
248 |
end; |
|
249 |
for i:= 1 to Template.RandPassesCount do |
|
250 |
RandomizePoints(pa);} |
|
10201
9bee9541edf1
Fix detection of intersections, still need to check if passing any point in move, but result is already okayish
unc0rr
parents:
10200
diff
changeset
|
251 |
BezierizeEdge(pa, _0_1); |
10199 | 252 |
end; |
253 |
||
254 |
||
10198 | 255 |
procedure GenTemplated(var Template: TEdgeTemplate); |
256 |
var pa: TPixAr; |
|
257 |
i: Longword; |
|
258 |
y, x: Longword; |
|
259 |
fps: TPointArray; |
|
260 |
begin |
|
261 |
fps:=Template.FillPoints^; |
|
262 |
ResizeLand(Template.TemplateWidth, Template.TemplateHeight); |
|
263 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
264 |
for x:= 0 to LAND_WIDTH - 1 do |
|
265 |
Land[y, x]:= lfBasic; |
|
266 |
{$HINTS OFF} |
|
267 |
SetPoints(Template, pa, @fps); |
|
268 |
{$HINTS ON} |
|
269 |
||
10199 | 270 |
Distort1(Template, pa); |
10198 | 271 |
|
272 |
DrawEdge(pa, 0); |
|
273 |
||
274 |
with Template do |
|
275 |
for i:= 0 to pred(FillPointsCount) do |
|
276 |
with fps[i] do |
|
277 |
FillLand(x, y, 0, 0); |
|
278 |
||
279 |
DrawEdge(pa, lfBasic); |
|
280 |
||
281 |
MaxHedgehogs:= Template.MaxHedgehogs; |
|
282 |
hasGirders:= Template.hasGirders; |
|
283 |
playHeight:= Template.TemplateHeight; |
|
284 |
playWidth:= Template.TemplateWidth; |
|
285 |
leftX:= ((LAND_WIDTH - playWidth) div 2); |
|
286 |
rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; |
|
287 |
topY:= LAND_HEIGHT - playHeight; |
|
288 |
||
289 |
// HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? |
|
290 |
if (cTemplateFilter = 4) |
|
291 |
or (Template.canInvert and (getrandom(2) = 0)) |
|
292 |
or (not Template.canInvert and Template.isNegative) then |
|
293 |
begin |
|
294 |
hasBorder:= true; |
|
295 |
for y:= 0 to LAND_HEIGHT - 1 do |
|
296 |
for x:= 0 to LAND_WIDTH - 1 do |
|
297 |
if (y < topY) or (x < leftX) or (x > rightX) then |
|
298 |
Land[y, x]:= 0 |
|
299 |
else |
|
300 |
begin |
|
301 |
if Land[y, x] = 0 then |
|
302 |
Land[y, x]:= lfBasic |
|
303 |
else if Land[y, x] = lfBasic then |
|
304 |
Land[y, x]:= 0; |
|
305 |
end; |
|
306 |
end; |
|
307 |
end; |
|
308 |
||
309 |
||
310 |
end. |