some 3D on pascal

  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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
program ThreeDi;
uses
GraphABC, System, System.Collections.Generic;
const
n = 21;gr = 16;
var
radius: array[1..n] of real; angular: array[1..n] of real; height: array[1..n] of real;
x: array[1..n] of real; a: array[1..n] of real; z: array[1..n] of real;
displayX: array[1..n] of real; displayY: array[1..n] of real;
grs: array[1..gr] of string; colors: array[1..gr] of color;
num: array of integer;numZ: array[1..gr] of integer;
numP: array of point; grstang: array[1..gr] of integer;
zx, zy, koef, k1, fps, mousex, mousey, alpha1, alpha2, alpha3: real;
slepper, panelWidth, panelX, osz, osx, cod, x12, y12, y13, x13, angularX: integer;
vers, text: string;
sw, rang, lol, drawbody, drawskeleton, drawparticles, drawpanel, rectfps: boolean;
//Процедура задания начальных координат
procedure InitMap;
begin;
radius[1] := 60; angular[1] := 90; height[1] := 25+50;
radius[2] := 60; angular[2] := 90; height[2] := -35+50;
radius[3] := 60; angular[3] := 180; height[3] := 25+50;
radius[4] := 60; angular[4] := 180; height[4] := -35+50;
radius[5] := 60; angular[5] := 270; height[5] := 25+50;
radius[6] := 60; angular[6] := 270; height[6] := -35+50;
radius[7] := 60; angular[7] := 0; height[7] := 25+50;
radius[8] := 60; angular[8] := 0; height[8] := -35+50;
radius[9] := 30; angular[9] := 90; height[9] := -15;
radius[10] := 60; angular[10] := 90; height[10] := -35+50;
radius[11] := 30; angular[11] := 180; height[11] := -15;
radius[12] := 60; angular[12] := 180; height[12] := -35+50;
radius[13] := 30; angular[13] := 270; height[13] := -15;
radius[14] := 60; angular[14] := 270; height[14] := -35+50;
radius[15] := 30; angular[15] := 0; height[15] := -15;
radius[16] := 60; angular[16] := 0; height[16] := -35+50;
radius[17] := 30; angular[17] := 90; height[17] := -150;
radius[18] := 30; angular[18] := 180; height[18] := -150;
radius[19] := 30; angular[19] := 270; height[19] := -150;
radius[20] := 30; angular[20] := 0; height[20] := -150;
grs[1] := '001-002-004-003'; colors[1] := argb(255, 50, 80, 100);
grs[2] := '005-006-008-007'; colors[2] := argb(255, 50, 80, 100);
grs[3] := '003-004-006-005'; colors[3] := argb(255, 50, 80, 100);
grs[4] := '001-002-008-007'; colors[4] := argb(255, 50, 80, 100);
grs[5] := '002-004-006-008'; colors[5] := argb(255, 50, 80, 100);
grs[6] := '001-003-005-007'; colors[6] := argb(255, 50, 80, 100);
grs[7] := '009-010-012-011'; colors[7] := argb(255, 50, 80, 100);
grs[8] := '013-014-016-015'; colors[8] := argb(255, 50, 80, 100);
grs[9] := '011-012-014-013'; colors[9] := argb(255, 50, 80, 100);
grs[10] := '009-010-016-015'; colors[10] := argb(255, 50, 80, 100);
grs[11] := '010-012-014-016'; colors[11] := argb(255, 50, 80, 100);
grs[12] := '009-011-013-015'; colors[12] := argb(255, 50, 80, 100);
grs[13] := '009-017-018-011'; colors[13] := argb(255, 50, 80, 100);
grs[14] := '020-019-013-015'; colors[14] := argb(255, 50, 80, 100);
grs[15] := '018-019-013-011'; colors[15] := argb(255, 50, 80, 100);
grs[16] := '020-017-009-015'; colors[16] := argb(255, 50, 80, 100);
sw := true; rang := true; drawbody := true; drawskeleton := true; drawpanel := false; rectfps := false;
drawparticles := true;
SetWindowTitle(floattostr(MouseX));
koef := 3;k1 := 1;slepper := 0;
osz := 0;osx := 0;
angularX := 0;
panelwidth := 200;
alpha1 := 16.97; alpha2 := 15.97; alpha3 := 0.0528;
end;
procedure MouseMove(x11, y11, mb: integer);
begin
angularX := (round(-(x11 + x12) / 5));
x13 := x11;
y13 := y11;
end;
//Процедура математических вычислений, главная часть "движка"
procedure MainMath;
begin;
{$omp parallel for }
{$omp parallel for }
for var mathh := 1 to n do
begin
ZX := (Window.Width - panelwidth) / 2; ZY := Window.height / 2;
koef := (ZX + ZY) / 300;
a[mathh] := (angular[mathh] + angularX) * (3.14159 / 180);
x[mathh] := osx + (radius[mathh] * sin(a[mathh]));
z[mathh] := osz + (radius[mathh] * cos(a[mathh]));
displayX[mathh] := zx + (koef * (x[mathh] * (alpha1 / (alpha2 + z[mathh] * alpha3))));
displayY[mathh] := zy + (koef * (height[mathh] * (alpha1 / (alpha2 + z[mathh] * alpha3))));
end;
end;
//Оганичиваем FPS
procedure cutfps;
begin;
if fps >= 31 then slepper += 2;
if fps <= 29 then slepper -= 1;
if slepper <= 30 then slepper += 3;
if slepper > 30 then slepper -= 2;
sleep(round(slepper * 1.5));
end;
//Процедура просчёта граней, которые будут вырисовываться первыми, без вырисовки.
procedure Rangularing;
begin;
SetLength(num, 4);
for var t := 1 to gr do
begin
text := copy(grs[t], 1, 3);
val(text, num[0], cod);
text := copy(grs[t], 5, 3);
val(text, num[1], cod);
text := copy(grs[t], 9, 3);
val(text, num[2], cod);
text := copy(grs[t], 13, 3);
val(text, num[3], cod);
numZ[t] := round(((z[num[0]] + z[num[1]] + z[num[2]] + z[num[3]]) / 4));
end;
for var T := 2 TO gr - 1 do
begin
for var T1 := 1 TO gr - (T - 1) do
begin
if numZ[T1] < numZ[T1 + 1] THEN begin
SWAP(numZ[T1], numZ[T1 + 1]); SWAP(grs[T1], grs[T1 + 1]);SWAP(colors[t1], colors[t1 + 1]);
end;
end;
end;
end;
//Вырисовка "заранжированных" граней.
procedure DrawRangularing;
begin;
if sw = true then begin
SetLength(num, 4);setlength(numP, 4);
for var t := 1 to gr do
begin
text := copy(grs[t], 1, 3);
val(text, num[0], cod);
text := copy(grs[t], 5, 3);
val(text, num[1], cod);
text := copy(grs[t], 9, 3);
val(text, num[2], cod);
text := copy(grs[t], 13, 3);
val(text, num[3], cod);
for var gg := 0 to 3 do
begin
numP[gg].X := round(displayX[num[gg]]);
numP[gg].Y := round(displayY[num[gg]]);
end;
if drawbody = true then setbrushcolor(colors[t]);
if drawbody = false then setbrushcolor(argb(0, 0, 0, 0));
if drawskeleton = true then setpencolor(clblack);
if drawskeleton = false then setpencolor(argb(0, 0, 0, 0));
Polygon(numP);
end;
end;
end;
procedure SimpleDraw;
begin;
for var d := 1 to n do
putpixel(round(displayx[d]), round(displayy[d]), clblack);
end;
//Обработчик события нажатия клавиш мыши
procedure MyMouseDown(mxx, myy, mb: integer);
begin
MouseX := mxx;
MouseY := myy;
end;
procedure BackPanel;
begin;
OnMouseDown := MyMouseDown;
vers := ' xClick ' + (floattostr(MouseX)) + ' yClick ' + floattostr(MouseY) + ' xMouse ' + inttostr(x13) + ' yMouse ' + inttostr(y12);
SetWindowTitle(vers);
PanelX := Window.Width - panelwidth;setbrushcolor(clsilver);setpencolor(clblack);
FillRectangle(PanelX, 0, Window.Width, Window.height);DrawRectangle(PanelX, 0, Window.Width, Window.height);
setbrushcolor(argb(0, 0, 0, 0));
TextOut(PanelX + 5, 2, 'Текущий FPS:');TextOut(PanelX + 95, 2, floattostr(round(fps)));
TextOut(PanelX + 5, 22, 'Угол поворота камеры:'); TextOut(PanelX + 160, 22, inttostr(angularX));
TextOut(panelX + 5, 39, 'Повернуть модель на 1 градус');
TextOut(panelX + 5, 80, 'Переменная приломнения #1');TextOut(panelX + 90, 100, inttostr(round(alpha1)));
TextOut(panelX + 5, 120, 'Переменная приломнения #2');TextOut(panelX + 80, 137, floattostr((alpha2)));
TextOut(panelX + 5, 160, 'Переменная приломнения #3');TextOut(panelX + 80, 177, floattostr((alpha3)));
TextOut(panelx + 5, 195, 'Рендеринг'); Textout(panelx + 5, 212, 'Каркас'); TextOut(panelx + 5, 230, 'Боковое меню');
Textout(panelx + 5, 248, 'Ограничить FPS до 30');Textout(panelx + 5, 264, 'Ранжирование');Textout(panelx + 5, 281, 'Вырисовка');
setbrushcolor(clblack);FillRectangle(PanelX + 5, 60, PanelX + 20, 75);
FillRectangle(Window.Width - 5, 60, Window.Width - 20, 75);
FillRectangle(PanelX + 5, 100, PanelX + 20, 115);FillRectangle(Window.Width - 5, 100, Window.Width - 20, 115);
FillRectangle(PanelX + 5, 137, PanelX + 20, 152);FillRectangle(Window.Width - 5, 137, Window.Width - 20, 152);
FillRectangle(PanelX + 5, 177, PanelX + 20, 192);FillRectangle(Window.Width - 5, 177, Window.Width - 20, 192);
FillRectangle(Window.Width - 37, 195, Window.Width - 22, 210);
FillRectangle(Window.Width - 37, 212, Window.Width - 22, 227);
FillRectangle(Window.Width - 37, 229, Window.Width - 22, 245);
FillRectangle(Window.Width - 37, 247, Window.Width - 22, 262);
FillRectangle(Window.Width - 37, 264, Window.Width - 22, 279);
FillRectangle(Window.Width - 37, 281, Window.Width - 22, 296);
//Блок основных проверок hажатий кнопок
{$omp parallel for }
for var i := 1 to 14 do
begin
//
if (PanelX + (i + 5)) = MouseX then begin
{$omp parallel for }
for var l := 1 to 14 do
begin
if (60 + l) = MouseY then begin
for var j := 1 to n do
begin
angular[j] := angular[j] + 3;MouseX := 0; MouseY := 0;
end;
end;
if (100 + l) = MouseY then begin
alpha1 := alpha1 - 1;MouseX := 0; MouseY := 0;
end;
if (137 + l) = MouseY then begin
alpha2 := alpha2 - 0.1;MouseX := 0; MouseY := 0;
end;
if (177 + l) = MouseY then begin
alpha3 := alpha3 - 0.009;MouseX := 0; MouseY := 0;
end;
end;
end;
//
if (Window.Width - 20) + i = MouseX then begin
{$omp parallel for }
for var l := 1 to 14 do
begin
if (60 + l) = MouseY then begin
for var j := 1 to n do
begin
angular[j] := angular[j] - 3;MouseX := 0; MouseY := 0;
end;
end;
if (100 + l) = MouseY then begin
alpha1 := alpha1 + 1;MouseX := 0; MouseY := 0;
end;
if (137 + l) = MouseY then begin
alpha2 := alpha2 + 0.1;MouseX := 0; MouseY := 0;
end;
if (177 + l) = MouseY then begin
alpha3 := alpha3 + 0.009;MouseX := 0; MouseY := 0;
end;
end;
end;
//
if (Window.Width - 37) + i = MouseX then begin
{$omp parallel for }
for var l := 1 to 14 do
begin
if (195 + l) = MouseY then begin
if drawbody = true then drawbody := false
else drawbody := true;
MouseX := 0; MouseY := 0;
end;
if (212 + l) = MouseY then begin
if drawskeleton = true then drawskeleton := false
else drawskeleton := true;
MouseX := 0; MouseY := 0;
end;
if (229 + l) = MouseY then begin
if drawpanel = true then drawpanel := false;
panelwidth := 0;
MouseX := 0; MouseY := 0;
end;
if (247 + l) = MouseY then begin
if rectfps = false then rectfps := true
else rectfps := false;
MouseX := 0;MouseY := 0;
end;
if (264 + l) = MouseY then begin
if rang = false then rang := true
else rang := false;
MouseX := 0; MouseY := 0;
end;
if (281 + l) = MouseY then begin
if sw = false then sw := true
else sw := false;
MouseX := 0; MouseY := 0;
end;
end;
end;
//
end;
end;
begin
InitMap;
for var j := 1 to 99999 do
begin
LockDrawing;
window.Clear;
MainMath;
if rang = true then Rangularing;
x12 := x13;
y12 := y13;
OnMouseMove := MouseMove;
if sw = true then DrawRangularing;
if drawparticles = true then SimpleDraw;
OnMouseDown := MyMouseDown;
if drawpanel = false then begin
window.Title := floattostr(round(fps));
setbrushcolor(clsilver);setpencolor(clblack);
textout(1, 1, 'Вернуть боковое меню');
FillRectangle(150, 2, 165, 17);
for var i := 1 to 14 do
begin
if (150 + i) = MouseX then begin
for var l := 1 to 14 do
begin
if (2 + l) = MouseY then begin
drawpanel := true;MouseX := 0;MouseY := 0;Panelwidth := 200;
end;
end;
end;
end;
end;
if drawpanel = true then BackPanel;
k1 += 1;
fps := k1 / Milliseconds * 1000;
if rectfps = true then cutfps;
Redraw;
end;
end.