Subversion Repositories Kolibri OS

Rev

Rev 7861 | Rev 8442 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5388 IgorA 1
use32
7205 IgorA 2
	org 0
5388 IgorA 3
	db 'MENUET01' ;идентиф. исполняемого файла всегда 8 байт
7205 IgorA 4
	dd 1, start, i_end, mem, stacktop, openfile_path, sys_path
5388 IgorA 5
 
8174 IgorA 6
include '../../../macros.inc'
7
include '../../../proc32.inc'
8
include '../../../KOSfuncs.inc'
9
include '../../../load_img.inc'
10
include '../../../develop/libraries/TinyGL/asm_fork/opengl_const.inc'
11
include '../../../develop/libraries/TinyGL/asm_fork/zbuffer.inc'
5388 IgorA 12
include 'vox_3d.inc'
13
include '../trunk/str.inc'
7861 IgorA 14
include 'lang.inc'
5388 IgorA 15
 
16
@use_library_mem mem.Alloc,mem.Free,mem.ReAlloc,dll.Load
7861 IgorA 17
if lang eq ru
8174 IgorA 18
caption db 'Просмотр вокселей 11.11.20',0 ;подпись окна
7861 IgorA 19
else
8174 IgorA 20
caption db 'Voxel viewer 11.11.20',0
7861 IgorA 21
end if
5388 IgorA 22
 
5949 IgorA 23
3d_wnd_l equ   5 ;отступ для tinygl буфера слева
24
3d_wnd_t equ  30 ;отступ для tinygl буфера сверху
25
3d_wnd_w equ 512
26
3d_wnd_h equ 512
27
 
5388 IgorA 28
IMAGE_TOOLBAR_ICON_SIZE equ 16*16*3
5393 IgorA 29
IMAGE_TOOLBAR_SIZE equ IMAGE_TOOLBAR_ICON_SIZE*10
5388 IgorA 30
image_data_toolbar dd 0
31
 
32
align 4
33
start:
34
	load_libraries l_libs_start,l_libs_end
35
	;проверка на сколько удачно загузилась библиотека
36
	mov	ebp,lib_0
37
	cmp	dword [ebp+ll_struc_size-4],0
38
	jz	@f
6259 IgorA 39
		mcall SF_TERMINATE_PROCESS
5388 IgorA 40
	@@:
6259 IgorA 41
	mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors
42
	mcall SF_SET_EVENTS_MASK,0xC0000027
5388 IgorA 43
	stdcall [OpenDialog_Init],OpenDialog_data ;подготовка диалога
44
 
45
	stdcall [buf2d_create], buf_0 ;создание буфера
46
 
7205 IgorA 47
	include_image_file 'toolbar_t.png', image_data_toolbar,,,6 ;6 - for gray icons
5393 IgorA 48
	mov eax,[image_data_toolbar]
49
	add eax,IMAGE_TOOLBAR_SIZE
50
	stdcall img_to_gray, [image_data_toolbar],eax,(IMAGE_TOOLBAR_SIZE)/3
5388 IgorA 51
 
6259 IgorA 52
	mcall SF_SYSTEM_GET,SSF_TIME_COUNT
5388 IgorA 53
	mov [last_time],eax
54
 
5949 IgorA 55
	stdcall [kosglMakeCurrent], 3d_wnd_l,3d_wnd_t,3d_wnd_w,3d_wnd_h,ctx1
5388 IgorA 56
	stdcall [glEnable], GL_DEPTH_TEST
57
	stdcall [glEnable], GL_NORMALIZE ;делам нормали одинаковой величины во избежание артефактов
58
	stdcall [glClearColor], 0.0,0.0,0.0,0.0
59
	stdcall [glShadeModel], GL_SMOOTH
60
 
61
	call but_new_file
7205 IgorA 62
	;проверка командной строки
63
	cmp dword[openfile_path],0
64
	je @f
65
		call but_open_file_cmd_lin
66
	@@:
5388 IgorA 67
 
68
align 4
69
red_win:
70
	call draw_window
71
 
72
align 4
73
still:
6259 IgorA 74
	mcall SF_SYSTEM_GET,SSF_TIME_COUNT
5388 IgorA 75
	mov ebx,[last_time]
76
	add ebx,50 ;задержка
77
	cmp ebx,eax
78
	jge @f
79
		mov ebx,eax
80
	@@:
81
	sub ebx,eax
6259 IgorA 82
	mcall SF_WAIT_EVENT_TIMEOUT
5388 IgorA 83
	bt word[opt_auto_rotate],0
84
	jnc @f
85
		or eax,eax
86
		jz timer_funct
87
	@@:
88
 
89
	cmp al,1
90
	jz red_win
91
	cmp al,2
92
	jz key
93
	cmp al,3
94
	jz button
5949 IgorA 95
	cmp al,6
96
	jne @f
97
		call mouse
98
	@@:
5388 IgorA 99
 
100
	jmp still
101
 
102
align 4
103
timer_funct:
104
	pushad
6259 IgorA 105
	mcall SF_SYSTEM_GET,SSF_TIME_COUNT
5388 IgorA 106
	mov [last_time],eax
107
 
108
	;автоматическое изменение угла обзора
109
	fld dword[angle_y]
110
	fsub dword[delt_size]
111
	fstp dword[angle_y]
112
	call draw_3d
8174 IgorA 113
	call [kosglSwapBuffers]
5388 IgorA 114
 
115
	popad
116
	jmp still
117
 
118
align 4
119
draw_window:
120
pushad
6259 IgorA 121
	mcall SF_REDRAW,SSF_BEGIN_DRAW
5388 IgorA 122
 
123
	; *** рисование главного окна (выполняется 1 раз при запуске) ***
124
	mov edx,[sc.work]
125
	or  edx,(3 shl 24)+0x30000000
6259 IgorA 126
	mcall SF_CREATE_WINDOW,(20 shl 16)+800,(20 shl 16)+570,,,caption
5388 IgorA 127
 
128
	; *** создание кнопок на панель ***
6259 IgorA 129
	mcall SF_DEFINE_BUTTON,(5 shl 16)+20,(5 shl 16)+20,3,[sc.work_button]
5388 IgorA 130
 
131
	mov ebx,(30 shl 16)+20
8174 IgorA 132
	mcall ,,,4
5388 IgorA 133
	add ebx,25 shl 16
8174 IgorA 134
	mcall ,,,5
5388 IgorA 135
	add ebx,30 shl 16
8174 IgorA 136
	mcall ,,,6
5388 IgorA 137
	add ebx,25 shl 16
8174 IgorA 138
	mcall ,,,7
5388 IgorA 139
	add ebx,25 shl 16
8174 IgorA 140
	mcall ,,,8
5388 IgorA 141
	add ebx,25 shl 16
8174 IgorA 142
	mcall ,,,9
5388 IgorA 143
	add ebx,25 shl 16
8174 IgorA 144
	mcall ,,,10
5388 IgorA 145
	add ebx,25 shl 16
8174 IgorA 146
	mcall ,,,11
5388 IgorA 147
	add ebx,25 shl 16
8174 IgorA 148
	mcall ,,,12
5388 IgorA 149
 
5393 IgorA 150
	call draw_toolbar_i
151
 
152
	stdcall [buf2d_draw], buf_0
8174 IgorA 153
	call [kosglSwapBuffers]
5393 IgorA 154
 
6259 IgorA 155
	mcall SF_REDRAW,SSF_END_DRAW
5393 IgorA 156
popad
157
	ret
158
 
159
 
160
align 4
161
draw_toolbar_i:
5388 IgorA 162
	; *** рисование иконок на кнопках ***
163
	mov edx,(7 shl 16)+7 ;icon new
6259 IgorA 164
	mcall SF_PUT_IMAGE,[image_data_toolbar],(16 shl 16)+16
5388 IgorA 165
 
166
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
167
	add edx,(25 shl 16) ;icon open
168
	int 0x40
169
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
170
	add edx,(25 shl 16) ;icon save
171
	int 0x40
172
 
173
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
174
	add edx,(30 shl 16) ;zoom +
175
	int 0x40
176
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
177
	add edx,(25 shl 16) ;zoom -
178
	int 0x40
5393 IgorA 179
 
5388 IgorA 180
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
5393 IgorA 181
	cmp word[opt_light],0
182
	jne @f
183
		add ebx,IMAGE_TOOLBAR_SIZE ;make gray icon
184
	@@:
5388 IgorA 185
	add edx,(25 shl 16) ;light on/off
186
	int 0x40
5393 IgorA 187
	cmp word[opt_light],0
188
	jne @f
189
		sub ebx,IMAGE_TOOLBAR_SIZE
190
	@@:
191
 
5388 IgorA 192
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
5393 IgorA 193
	cmp word[opt_cube_box],0
194
	jne @f
195
		add ebx,IMAGE_TOOLBAR_SIZE ;make gray icon
196
	@@:
5388 IgorA 197
	add edx,(25 shl 16) ;box on/off
198
	int 0x40
5393 IgorA 199
	cmp word[opt_cube_box],0
200
	jne @f
201
		sub ebx,IMAGE_TOOLBAR_SIZE
202
	@@:
203
 
5388 IgorA 204
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
5393 IgorA 205
	cmp word[opt_auto_rotate],0
206
	jne @f
207
		add ebx,IMAGE_TOOLBAR_SIZE ;make gray icon
208
	@@:
5388 IgorA 209
	add edx,(25 shl 16) ;auto rotate on/off
210
	int 0x40
5393 IgorA 211
	cmp word[opt_auto_rotate],0
212
	jne @f
213
		sub ebx,IMAGE_TOOLBAR_SIZE
214
	@@:
215
 
5388 IgorA 216
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
217
	add edx,(25 shl 16) ;info voxels
218
	int 0x40
219
	add ebx,IMAGE_TOOLBAR_ICON_SIZE
220
	add edx,(25 shl 16) ;refresh
221
	int 0x40
222
	ret
223
 
224
 
225
align 4
226
key:
6259 IgorA 227
	mcall SF_GET_KEY
5388 IgorA 228
 
229
	cmp ah,178 ;Up
230
	jne @f
5393 IgorA 231
		fld dword[angle_x]
5388 IgorA 232
		fadd dword[delt_size]
5393 IgorA 233
		fstp dword[angle_x]
8174 IgorA 234
		jmp .end0
5388 IgorA 235
	@@:
236
	cmp ah,177 ;Down
237
	jne @f
5393 IgorA 238
		fld dword[angle_x]
5388 IgorA 239
		fsub dword[delt_size]
5393 IgorA 240
		fstp dword[angle_x]
8174 IgorA 241
		jmp .end0
5388 IgorA 242
	@@:
243
	cmp ah,176 ;Left
244
	jne @f
5393 IgorA 245
		fld dword[angle_y]
5388 IgorA 246
		fadd dword[delt_size]
5393 IgorA 247
		fstp dword[angle_y]
8174 IgorA 248
		jmp .end0
5388 IgorA 249
	@@:
250
	cmp ah,179 ;Right
8174 IgorA 251
	jne still  ;@f
5393 IgorA 252
		fld dword[angle_y]
5388 IgorA 253
		fsub dword[delt_size]
5393 IgorA 254
		fstp dword[angle_y]
8174 IgorA 255
	.end0:
5388 IgorA 256
		call draw_3d
8174 IgorA 257
		call [kosglSwapBuffers]
258
	;@@:
5388 IgorA 259
	jmp still
260
 
261
 
262
align 4
5949 IgorA 263
mouse:
264
	push eax ebx
6259 IgorA 265
	mcall SF_MOUSE_GET,SSF_BUTTON_EXT
5949 IgorA 266
	bt eax,0
267
	jnc .end_m
268
		;mouse l. but. move
269
		cmp dword[mouse_drag],1
270
		jne .end_m
6259 IgorA 271
		mcall SF_MOUSE_GET,SSF_WINDOW_POSITION
5949 IgorA 272
		mov ebx,eax
273
		shr ebx,16 ;mouse.x
274
		cmp ebx,3d_wnd_l
275
		jg @f
276
			mov ebx,3d_wnd_l
277
		@@:
278
		sub ebx,3d_wnd_l
279
		cmp ebx,3d_wnd_w
280
		jle @f
281
			mov ebx,3d_wnd_w
282
		@@:
283
		and eax,0xffff ;mouse.y
284
		cmp eax,3d_wnd_t
285
		jg @f
286
			mov eax,3d_wnd_t
287
		@@:
288
		sub eax,3d_wnd_t
289
		cmp eax,3d_wnd_h
290
		jle @f
291
			mov eax,3d_wnd_h
292
		@@:
293
		finit
294
		fild dword[mouse_y]
295
		mov [mouse_y],eax
296
		fisub dword[mouse_y]
297
		fdiv dword[angle_dxm] ;если курсор движется по оси y (вверх или вниз) то поворот делаем вокруг оси x
298
		fadd dword[angle_x]
299
		fstp dword[angle_x]
300
 
301
		fild dword[mouse_x]
302
		mov [mouse_x],ebx
303
		fisub dword[mouse_x]
304
		fdiv dword[angle_dym] ;если курсор движется по оси x (вверх или вниз) то поворот делаем вокруг оси y
305
		fadd dword[angle_y]
306
		fstp dword[angle_y]
307
 
308
		call draw_3d
8174 IgorA 309
		call [kosglSwapBuffers]
5949 IgorA 310
		jmp .end_d
311
	.end_m:
312
	bt eax,16
313
	jnc @f
314
		;mouse l. but. up
315
		mov dword[mouse_drag],0
316
		jmp .end_d
317
	@@:
318
	bt eax,8
319
	jnc .end_d
320
		;mouse l. but. press
6259 IgorA 321
		mcall SF_MOUSE_GET,SSF_WINDOW_POSITION
5949 IgorA 322
		mov ebx,eax
323
		shr ebx,16 ;mouse.x
324
		cmp ebx,3d_wnd_l
325
		jl .end_d
326
		sub ebx,3d_wnd_l
327
		cmp ebx,3d_wnd_w
328
		jg .end_d
329
		and eax,0xffff ;mouse.y
330
		cmp eax,3d_wnd_t
331
		jl .end_d
332
		sub eax,3d_wnd_t
333
		cmp eax,3d_wnd_h
334
		jg .end_d
335
		mov dword[mouse_drag],1
336
		mov dword[mouse_x],ebx
337
		mov dword[mouse_y],eax
338
	.end_d:
339
 
340
	;stdcall [kmainmenu_dispatch_cursorevent], [main_menu]
341
	pop ebx eax
342
	ret
343
 
344
align 4
5388 IgorA 345
button:
6259 IgorA 346
	mcall SF_GET_BUTTON
5388 IgorA 347
	cmp ah,3
348
	jne @f
349
		call but_new_file
7861 IgorA 350
		jmp still
5388 IgorA 351
	@@:
352
	cmp ah,4
353
	jne @f
354
		call but_open_file
7861 IgorA 355
		jmp still
5388 IgorA 356
	@@:
357
	cmp ah,5
358
	jne @f
359
		call but_save_file
7861 IgorA 360
		jmp still
5388 IgorA 361
	@@:
362
	cmp ah,6
363
	jne @f
364
		call but_zoom_p
7861 IgorA 365
		jmp still
5388 IgorA 366
	@@:
367
	cmp ah,7
368
	jne @f
369
		call but_zoom_m
7861 IgorA 370
		jmp still
5388 IgorA 371
	@@:
372
	cmp ah,8
373
	jne @f
7861 IgorA 374
		call but_light
375
		jmp still
5388 IgorA 376
	@@:
377
	cmp ah,9
378
	jne @f
379
		call but_4
7861 IgorA 380
		jmp still
5388 IgorA 381
	@@:
382
	cmp ah,10
383
	jne @f
384
		call but_5
7861 IgorA 385
		jmp still
5388 IgorA 386
	@@:
387
	cmp ah,11
388
	jne @f
7861 IgorA 389
		call but_info
390
		jmp still
5388 IgorA 391
	@@:
392
	cmp ah,12
393
	jne @f
5393 IgorA 394
		call but_draw_cadr
7861 IgorA 395
		jmp still
5388 IgorA 396
	@@:
397
	cmp ah,1
398
	jne still
399
.exit:
400
	stdcall [buf2d_delete],buf_0
401
	stdcall mem.Free,[image_data_toolbar]
402
	stdcall mem.Free,[open_file_data]
403
	stdcall mem.Free,[open_file_ogl]
6259 IgorA 404
	mcall SF_TERMINATE_PROCESS
5388 IgorA 405
 
406
 
407
align 4
408
but_new_file:
5415 IgorA 409
	mov dword[angle_x], -30.0
5393 IgorA 410
	mov dword[angle_y], 180.0
411
	mov dword[angle_z], 180.0
5388 IgorA 412
	ret
413
 
414
align 4
415
open_file_data dd 0 ;указатель на память для открытия файлов
416
open_file_size dd 0 ;размер открытого файла
417
open_file_ogl dd 0 ;для записи координат шраней вокселей в показе opengl
418
v_zoom dd 0
419
 
420
align 4
421
but_open_file:
7861 IgorA 422
	copy_path open_dialog_name,communication_area_default_path,file_name,0
5388 IgorA 423
pushad
424
	mov [OpenDialog_data.type],0
425
	stdcall [OpenDialog_Start],OpenDialog_data
426
	cmp [OpenDialog_data.status],2
7205 IgorA 427
	je @f
428
		;код при удачном открытии диалога
429
		call but_open_file_cmd_lin
430
	@@:
431
popad
432
	ret
5388 IgorA 433
 
7205 IgorA 434
align 4
435
but_open_file_cmd_lin:
436
pushad
6259 IgorA 437
	mov [run_file_70.Function], SSF_GET_INFO
5388 IgorA 438
	mov [run_file_70.Position], 0
439
	mov [run_file_70.Flags], 0
440
	mov dword[run_file_70.Count], 0
441
	mov dword[run_file_70.Buffer], open_b
442
	mov byte[run_file_70+20], 0
443
	mov dword[run_file_70.FileName], openfile_path
6259 IgorA 444
	mcall SF_FILE,run_file_70
5388 IgorA 445
 
446
	mov ecx,dword[open_b+32] ;+32 qword: размер файла в байтах
447
	stdcall mem.ReAlloc,[open_file_data],ecx
448
	mov [open_file_data],eax
449
 
6259 IgorA 450
	mov [run_file_70.Function], SSF_READ_FILE
5388 IgorA 451
	mov [run_file_70.Position], 0
452
	mov [run_file_70.Flags], 0
453
	mov dword[run_file_70.Count], ecx
454
	m2m dword[run_file_70.Buffer], dword[open_file_data]
455
	mov byte[run_file_70+20], 0
456
	mov dword[run_file_70.FileName], openfile_path
6259 IgorA 457
	mcall SF_FILE,run_file_70
5388 IgorA 458
	cmp ebx,0xffffffff
459
	je .end_open_file
460
 
461
	mov [open_file_size],ebx
6259 IgorA 462
	mcall SF_SET_CAPTION,1,openfile_path
5388 IgorA 463
 
464
	mov eax,[open_file_data]
465
	movzx eax,byte[eax]
466
	mov dword[v_zoom],eax ;берем масштаб по умолчанию
467
	mov ecx,[open_file_size]
468
	sub ecx,vox_offs_data
469
	shr ecx,2
470
	imul ecx,vox_ogl_size
471
	add ecx,4 ;ecx = размер памяти необходимой для распаковки координат
472
	stdcall mem.ReAlloc,[open_file_ogl],ecx
473
	or eax,eax
474
	jz .end_open_file
475
		mov [open_file_ogl],eax
476
		stdcall buf_vox_obj_create_3d,[open_file_data],eax,0,0,[v_zoom]
477
		call draw_cadr_8
478
	.end_open_file:
479
popad
480
	ret
481
 
482
;description:
483
; рисование 8-ми кадров под разными углами поворота
484
align 4
485
draw_cadr_8:
486
	call but_new_file ;установка углов поворота по умолчанию
487
	stdcall [buf2d_clear], buf_0, [buf_0.color] ;чистим буфер
488
 
489
	;рисование 8-ми кадров
490
	fild dword[rot_angles+4]
491
	fstp dword[angle_y]
492
	call draw_3d
493
	call draw_cadr
494
	stdcall [buf2d_bit_blt], buf_0, 128, 0, buf_1
495
 
496
	fild dword[rot_angles+8]
497
	fstp dword[angle_y]
498
	call draw_3d
499
	call draw_cadr
500
	stdcall [buf2d_bit_blt], buf_0, 0, 128, buf_1
501
 
502
	fild dword[rot_angles+12]
503
	fstp dword[angle_y]
504
	call draw_3d
505
	call draw_cadr
506
	stdcall [buf2d_bit_blt], buf_0, 128, 128, buf_1
507
 
508
	fild dword[rot_angles+16]
509
	fstp dword[angle_y]
510
	call draw_3d
511
	call draw_cadr
512
	stdcall [buf2d_bit_blt], buf_0, 0, 256, buf_1
513
 
514
	fild dword[rot_angles+20]
515
	fstp dword[angle_y]
516
	call draw_3d
517
	call draw_cadr
518
	stdcall [buf2d_bit_blt], buf_0, 128, 256, buf_1
519
 
520
	fild dword[rot_angles+24]
521
	fstp dword[angle_y]
522
	call draw_3d
523
	call draw_cadr
524
	stdcall [buf2d_bit_blt], buf_0, 0, 384, buf_1
525
 
526
	fild dword[rot_angles+28]
527
	fstp dword[angle_y]
528
	call draw_3d
529
	call draw_cadr
530
	stdcall [buf2d_bit_blt], buf_0, 128, 384, buf_1
531
 
532
	; *** последний кадр ***
533
	fild dword[rot_angles]
534
	fstp dword[angle_y]
535
	call draw_3d
536
	call draw_cadr
537
	stdcall [buf2d_bit_blt], buf_0, 0, 0, buf_1
538
 
539
	call draw_3d
540
	; ***
541
 
542
	stdcall [buf2d_draw], buf_0 ;обновляем буфер на экране
543
	ret
544
 
545
align 4
5393 IgorA 546
rot_angles dd 180,225,270,315,0,45,90,135
5388 IgorA 547
 
548
align 4
549
draw_cadr:
550
	mov eax,dword[ctx1] ;eax -> TinyGLContext.GLContext
551
	mov eax,[eax] ;eax -> ZBuffer
8174 IgorA 552
	mov eax,[eax+ZBuffer.pbuf]
5388 IgorA 553
	mov dword[buf_1],eax
554
 
555
	mov dword[buf_1.w],512
556
	mov dword[buf_1.h],512
557
	stdcall [buf2d_img_hdiv2],buf_1
558
	mov dword[buf_1.h],256
559
	stdcall [buf2d_img_hdiv2],buf_1
560
	mov dword[buf_1.h],128
561
	stdcall [buf2d_img_wdiv2],buf_1
562
	mov dword[buf_1.w],256
563
	stdcall [buf2d_img_wdiv2],buf_1
564
	mov dword[buf_1.w],128
565
	ret
566
 
567
align 4
568
but_save_file:
7861 IgorA 569
	copy_path open_dialog_name,communication_area_default_path,file_name,0
5388 IgorA 570
	pushad
571
	mov [OpenDialog_data.type],1
572
	stdcall [OpenDialog_Start],OpenDialog_data
573
	cmp [OpenDialog_data.status],2
574
	je .end_save_file
575
	;код при удачном открытии диалога
576
 
6259 IgorA 577
	mov [run_file_70.Function], SSF_CREATE_FILE
5388 IgorA 578
	mov [run_file_70.Position], 0
579
	mov [run_file_70.Flags], 0
580
	mov ebx, dword[open_file_data]
581
	;пишем в файл новый масштаб
582
	mov edx,dword[v_zoom]
583
	mov byte[ebx],dl
584
	mov [run_file_70.Buffer], ebx
585
	mov ebx,[open_file_size]
586
	mov dword[run_file_70.Count], ebx ;размер файла
587
	mov byte[run_file_70+20], 0
588
	mov dword[run_file_70.FileName], openfile_path
6259 IgorA 589
	mcall SF_FILE,run_file_70
5388 IgorA 590
	;cmp ebx,0xffffffff
591
	;je .end_save_file
592
	; ... сообщение о неудачном сохранении ...
593
 
594
	.end_save_file:
595
	popad
596
	ret
597
 
598
align 4
599
proc but_zoom_p uses eax
600
    cmp dword[v_zoom],11 ;max=2^11=2048
601
    jge @f
602
        inc dword[v_zoom]
603
        stdcall buf_vox_obj_create_3d,[open_file_data],[open_file_ogl],0,0,[v_zoom]
604
		call draw_3d
8174 IgorA 605
		call [kosglSwapBuffers]
5388 IgorA 606
    @@:
607
    ret
608
endp
609
 
610
align 4
611
proc but_zoom_m uses eax
612
    cmp dword[v_zoom],1
613
    jle @f
614
        dec dword[v_zoom]
615
        stdcall buf_vox_obj_create_3d,[open_file_data],[open_file_ogl],0,0,[v_zoom]
616
		call draw_3d
8174 IgorA 617
		call [kosglSwapBuffers]
5388 IgorA 618
    @@:
619
    ret
620
endp
621
 
622
align 4
7861 IgorA 623
proc but_light uses eax ebx ecx edx
5388 IgorA 624
	xor word[opt_light],1
625
	cmp word[opt_light],0
626
	je @f
627
		stdcall [glEnable], GL_LIGHTING
628
		stdcall [glEnable], GL_LIGHT0
629
		jmp .end_light
630
	@@:
631
		stdcall [glDisable], GL_LIGHTING
632
		stdcall [glDisable], GL_LIGHT0
633
	.end_light:
5393 IgorA 634
	call draw_toolbar_i
5388 IgorA 635
	call draw_3d
8174 IgorA 636
	call [kosglSwapBuffers]
5388 IgorA 637
	ret
638
endp
639
 
640
align 4
5393 IgorA 641
proc but_4 uses eax ebx ecx edx
5388 IgorA 642
	xor word[opt_cube_box],1
5393 IgorA 643
	call draw_toolbar_i
5388 IgorA 644
	call draw_3d
8174 IgorA 645
	call [kosglSwapBuffers]
5388 IgorA 646
	ret
647
endp
648
 
649
align 4
5393 IgorA 650
proc but_5 uses eax ebx ecx edx
5388 IgorA 651
	xor word[opt_auto_rotate],1
5393 IgorA 652
	call draw_toolbar_i
5388 IgorA 653
	ret
654
endp
655
 
656
align 4
7861 IgorA 657
proc but_info uses eax ebx ecx edx edi
5388 IgorA 658
	;вычисление статистики по вокселям
659
	mov eax,[open_file_ogl]
660
	or eax,eax
661
	jz .end_stat
662
		mov ebx,[eax]
663
		mov ecx,ebx
664
		mov edx,ebx
665
		imul ebx,6
666
		add eax,4
667
align 4
668
		.cycle_0:
669
			bt word[eax+vox_ogl_planes],vox_ogl_gran_z0
670
			jc @f
671
			dec ebx
672
			@@:
673
			bt word[eax+vox_ogl_planes],vox_ogl_gran_z1
674
			jc @f
675
			dec ebx
676
			@@:
677
			bt word[eax+vox_ogl_planes],vox_ogl_gran_y0
678
			jc @f
679
			dec ebx
680
			@@:
681
			bt word[eax+vox_ogl_planes],vox_ogl_gran_y1
682
			jc @f
683
			dec ebx
684
			@@:
685
			bt word[eax+vox_ogl_planes],vox_ogl_gran_x0
686
			jc @f
687
			dec ebx
688
			@@:
689
			bt word[eax+vox_ogl_planes],vox_ogl_gran_x1
690
			jc @f
691
			dec ebx
692
			@@:
693
			add eax,vox_ogl_size
694
		loop .cycle_0
695
 
696
		mov eax,edx
697
		mov edi,txt_stat_m1.v
698
		stdcall convert_int_to_str,20
699
 
5949 IgorA 700
		mov eax,ebx
701
		mov edi,txt_stat_m2.v
702
		stdcall convert_int_to_str,20
5388 IgorA 703
 
5949 IgorA 704
		stdcall str_n_cat,txt_stat_m1.v,txt_stat_m2,50
5388 IgorA 705
		notify_window_run txt_stat_m1
706
	.end_stat:
707
	ret
708
endp
709
 
710
align 4
711
txt_stat_m1:
7861 IgorA 712
if lang eq ru
5388 IgorA 713
	db 'Статистика',13,10,'Вокселей: '
5949 IgorA 714
.v: rb 70
5388 IgorA 715
txt_stat_m2:
716
	db 13,10,'Отображаемых граней: '
7861 IgorA 717
else
718
	db 'Statistics',13,10,'Voxels: '
719
.v: rb 70
720
txt_stat_m2:
721
	db 13,10,'Facets displayed: '
722
end if
5388 IgorA 723
.v: rb 20
724
 
725
align 4
5393 IgorA 726
proc but_draw_cadr uses eax ebx ecx edx
727
	mov ebx,[angle_x]
728
	mov ecx,[angle_y]
729
	mov edx,[angle_z]
5388 IgorA 730
	call draw_cadr_8
5393 IgorA 731
	mov [angle_x],ebx
732
	mov [angle_y],ecx
733
	mov [angle_z],edx
734
	cmp word[opt_auto_rotate],0
735
	jne @f
736
		call draw_3d
8174 IgorA 737
		;call [kosglSwapBuffers]
5393 IgorA 738
	@@:
5388 IgorA 739
	ret
740
endp
741
 
742
align 4
743
draw_3d:
744
	stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT ;очистим буфер цвета и глубины
745
	stdcall [glPushMatrix]
746
 
747
	cmp word[opt_light],0
748
	je @f
749
		call SetLight
750
	@@:
751
	stdcall [glTranslatef], 0.0,0.0,0.5 ;координаты по оси z должны быть в пределах от 0.0 до 1.0, иначе изображение будет отсекаться
752
		;воксельный объект имеет координаты по осям от -0.5 до 0.5, потому его двигаем на +0.5
753
		;но все же при поворотах будут отсекатся края, которые вылезут за пределы плоскостей отсечения
754
		;в версии opengl под Win координаты идут от -1.0 до 1.0 потому там этого делать не нужно
755
	stdcall [glScalef], [scale], [scale], [scale] ;увеличиваем воксельный объект, что-бы не был очень маленьким
6259 IgorA 756
	stdcall [glScalef], 1.0, 1.0, 0.25 ;что-бы края объекта не вылазили за грани отсечения
5393 IgorA 757
	stdcall [glRotatef], [angle_x],1.0,0.0,0.0
5388 IgorA 758
	stdcall [glRotatef], [angle_y],0.0,1.0,0.0
759
	stdcall [glRotatef], [angle_z],0.0,0.0,1.0
760
	stdcall draw_voxels_3d,[open_file_ogl]
761
 
8174 IgorA 762
	call [glPopMatrix]
5388 IgorA 763
ret
764
 
765
align 4
766
proc SetLight
767
    stdcall [glLightfv], GL_LIGHT0, GL_POSITION, light_position
768
    stdcall [glLightfv], GL_LIGHT0, GL_SPOT_DIRECTION, light_dir
769
 
770
    stdcall [glLightfv], GL_LIGHT0, GL_DIFFUSE, white_light
771
    stdcall [glLightfv], GL_LIGHT0, GL_SPECULAR, white_light
772
 
773
    stdcall [glEnable], GL_COLOR_MATERIAL
774
    stdcall [glColorMaterial], GL_FRONT, GL_AMBIENT_AND_DIFFUSE
775
    stdcall [glMaterialfv], GL_FRONT, GL_SPECULAR, mat_specular
776
    stdcall [glMaterialf], GL_FRONT, GL_SHININESS, mat_shininess
777
    stdcall [glLightModelfv], GL_LIGHT_MODEL_AMBIENT, lmodel_ambient
778
 
779
    stdcall [glEnable], GL_LIGHTING
780
    stdcall [glEnable], GL_LIGHT0
781
 
782
    ;;;stdcall [glLightModeli], GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE
783
    ret
784
endp
785
 
786
align 4
5393 IgorA 787
proc img_to_gray, buf_rgb:dword, buf_g24:dword, pixels:dword
788
pushad
789
	mov esi,[buf_rgb]
790
	mov edi,[buf_g24]
791
	mov ecx,[pixels]
792
	mov ebx,3
793
align 4
5388 IgorA 794
	@@:
5393 IgorA 795
		movzx eax,byte[esi]
796
		movzx edx,byte[esi+1]
797
		add eax,edx
798
		movzx edx,byte[esi+2]
799
		add eax,edx
800
		xor edx,edx
801
		div ebx ;shr eax,2
802
		mov ah,al
803
		mov word[edi],ax
804
		mov byte[edi+2],al
805
		add esi,3
806
		add edi,3
807
		loop @b
808
popad
5388 IgorA 809
	ret
810
endp
811
 
5393 IgorA 812
 
5388 IgorA 813
;данные для диалога открытия файлов
814
align 4
815
OpenDialog_data:
816
.type			dd 0 ;0 - открыть, 1 - сохранить, 2 - выбрать дтректорию
817
.procinfo		dd procinfo	;+4
818
.com_area_name		dd communication_area_name	;+8
819
.com_area		dd 0	;+12
820
.opendir_path		dd plugin_path	;+16
821
.dir_default_path	dd default_dir ;+20
822
.start_path		dd file_name ;+24 путь к диалогу открытия файлов
823
.draw_window		dd draw_window	;+28
824
.status 		dd 0	;+32
825
.openfile_path		dd openfile_path	;+36 путь к открываемому файлу
826
.filename_area		dd filename_area	;+40
827
.filter_area		dd Filter
828
.x:
829
.x_size 		dw 420 ;+48 ; Window X size
830
.x_start		dw 10 ;+50 ; Window X position
831
.y:
832
.y_size 		dw 320 ;+52 ; Window y size
833
.y_start		dw 10 ;+54 ; Window Y position
834
 
835
default_dir db '/rd/1',0
836
 
837
communication_area_name:
838
	db 'FFFFFFFF_open_dialog',0
839
open_dialog_name:
840
	db 'opendial',0
841
communication_area_default_path:
842
	db '/rd/1/File managers/',0
843
 
844
Filter:
845
dd Filter.end - Filter ;.1
846
.1:
847
db 'VOX',0
848
db 'TXT',0
849
.end:
850
db 0
851
 
852
 
853
 
854
system_dir_0 db '/sys/lib/'
855
lib_name_0 db 'proc_lib.obj',0
856
system_dir_1 db '/sys/lib/'
857
lib_name_1 db 'libimg.obj',0
858
system_dir_2 db '/sys/lib/'
859
lib_name_2 db 'buf2d.obj',0
6889 IgorA 860
system_dir_3 db '/sys/lib/'
6259 IgorA 861
lib_name_3 db 'tinygl.obj',0
862
 
7861 IgorA 863
align 4
864
head_f_i:
865
if lang eq ru
866
head_f_l db '"Системная ошибка',0
867
err_message_found_lib_0 db 'Не найдена библиотека ',39,'proc_lib.obj',39,'" -tE',0
868
err_message_import_0 db 'Ошибка при импорте библиотеки ',39,'proc_lib.obj',39,'" -tE',0
869
err_message_found_lib_1 db 'Не найдена библиотека ',39,'libimg.obj',39,'" -tE',0
870
err_message_import_1 db 'Ошибка при импорте библиотеки ',39,'libimg.obj',39,'" -tE',0
871
err_msg_found_lib_2 db 'Не найдена библиотека ',39,'buf2d.obj',39,'" -tE',0
872
err_msg_import_2 db 'Ошибка при импорте библиотеки ',39,'buf2d',39,'" -tE',0
873
err_msg_found_lib_3 db 'Не найдена библиотека ',39,'tinygl.obj',39,'" -tE',0
874
err_msg_import_3 db 'Ошибка при импорте библиотеки ',39,'tinygl',39,'" -tE',0
875
else
876
head_f_l db '"System error',0
877
err_message_found_lib_0 db 'Sorry I cannot found library ',39,'proc_lib.obj',39,'" -tE',0
878
err_message_import_0 db 'Error on load import library ',39,'proc_lib.obj',39,'" -tE',0
879
err_message_found_lib_1 db 'Sorry I cannot found library ',39,'libimg.obj',39,'" -tE',0
880
err_message_import_1 db 'Error on load import library ',39,'libimg.obj',39,'" -tE',0
881
err_msg_found_lib_2 db 'Sorry I cannot found library ',39,'buf2d.obj',39,'" -tE',0
882
err_msg_import_2 db 'Error on load import library ',39,'buf2d',39,'" -tE',0
883
err_msg_found_lib_3 db 'Sorry I cannot found library ',39,'tinygl.obj',39,'" -tE',0
884
err_msg_import_3 db 'Error on load import library ',39,'tinygl',39,'" -tE',0
885
end if
886
 
5388 IgorA 887
l_libs_start:
888
	lib_0 l_libs lib_name_0, sys_path, file_name, system_dir_0,\
889
		err_message_found_lib_0, head_f_l, proclib_import,err_message_import_0, head_f_i
890
	lib_1 l_libs lib_name_1, sys_path, file_name, system_dir_1,\
891
		err_message_found_lib_1, head_f_l, import_libimg, err_message_import_1, head_f_i
892
	lib_2 l_libs lib_name_2, sys_path, library_path, system_dir_2,\
893
		err_msg_found_lib_2,head_f_l,import_buf2d,err_msg_import_2,head_f_i
894
	lib_3 l_libs lib_name_3, sys_path, library_path, system_dir_3,\
895
		err_msg_found_lib_3,head_f_l,import_lib_tinygl,err_msg_import_3,head_f_i
896
l_libs_end:
897
 
898
align 4
899
import_libimg:
900
	dd alib_init1
8174 IgorA 901
;	img_is_img  dd aimg_is_img
902
;	img_info    dd aimg_info
903
;	img_from_file dd aimg_from_file
904
;	img_to_file dd aimg_to_file
905
;	img_from_rgb dd aimg_from_rgb
906
;	img_to_rgb  dd aimg_to_rgb
5388 IgorA 907
	img_to_rgb2 dd aimg_to_rgb2
908
	img_decode  dd aimg_decode
8174 IgorA 909
;	img_encode  dd aimg_encode
910
;	img_create  dd aimg_create
5388 IgorA 911
	img_destroy dd aimg_destroy
8174 IgorA 912
;	img_destroy_layer dd aimg_destroy_layer
913
;	img_count   dd aimg_count
914
;	img_lock_bits dd aimg_lock_bits
915
;	img_unlock_bits dd aimg_unlock_bits
916
;	img_flip    dd aimg_flip
917
;	img_flip_layer dd aimg_flip_layer
918
;	img_rotate  dd aimg_rotate
919
;	img_rotate_layer dd aimg_rotate_layer
920
;	img_draw    dd aimg_draw
921
;	img_convert dd aimg_convert
5388 IgorA 922
 
923
	dd 0,0
924
	alib_init1   db 'lib_init',0
8174 IgorA 925
;	aimg_is_img  db 'img_is_img',0 ;определяет по данным, может ли библиотека сделать из них изображение
926
;	aimg_info    db 'img_info',0
927
;	aimg_from_file db 'img_from_file',0
928
;	aimg_to_file db 'img_to_file',0
929
;	aimg_from_rgb db 'img_from_rgb',0
930
;	aimg_to_rgb  db 'img_to_rgb',0 ;преобразование изображения в данные RGB
5388 IgorA 931
	aimg_to_rgb2 db 'img_to_rgb2',0
932
	aimg_decode  db 'img_decode',0 ;автоматически определяет формат графических данных
8174 IgorA 933
;	aimg_encode  db 'img_encode',0
934
;	aimg_create  db 'img_create',0
5388 IgorA 935
	aimg_destroy db 'img_destroy',0
8174 IgorA 936
;	aimg_destroy_layer db 'img_destroy_layer',0
937
;	aimg_count   db 'img_count',0
938
;	aimg_lock_bits db 'img_lock_bits',0
939
;	aimg_unlock_bits db 'img_unlock_bits',0
940
;	aimg_flip    db 'img_flip',0
941
;	aimg_flip_layer db 'img_flip_layer',0
942
;	aimg_rotate  db 'img_rotate',0
943
;	aimg_rotate_layer db 'img_rotate_layer',0
944
;	aimg_draw    db 'img_draw',0
945
;	aimg_convert db 'img_convert',0
5388 IgorA 946
 
947
align 4
948
proclib_import: ;описание экспортируемых функций
949
	OpenDialog_Init dd aOpenDialog_Init
950
	OpenDialog_Start dd aOpenDialog_Start
951
dd 0,0
952
	aOpenDialog_Init db 'OpenDialog_init',0
953
	aOpenDialog_Start db 'OpenDialog_start',0
954
 
955
align 4
956
import_buf2d:
957
	init dd sz_init
958
	buf2d_create dd sz_buf2d_create
959
	buf2d_create_f_img dd sz_buf2d_create_f_img
960
	buf2d_clear dd sz_buf2d_clear
961
	buf2d_draw dd sz_buf2d_draw
962
	buf2d_delete dd sz_buf2d_delete
963
	buf2d_line dd sz_buf2d_line
964
	buf2d_rect_by_size dd sz_buf2d_rect_by_size
965
	buf2d_filled_rect_by_size dd sz_buf2d_filled_rect_by_size
966
	buf2d_circle dd sz_buf2d_circle
967
	buf2d_img_hdiv2 dd sz_buf2d_img_hdiv2
968
	buf2d_img_wdiv2 dd sz_buf2d_img_wdiv2
969
	buf2d_conv_24_to_8 dd sz_buf2d_conv_24_to_8
970
	buf2d_conv_24_to_32 dd sz_buf2d_conv_24_to_32
971
	buf2d_bit_blt dd sz_buf2d_bit_blt
972
	buf2d_bit_blt_transp dd sz_buf2d_bit_blt_transp
973
	buf2d_bit_blt_alpha dd sz_buf2d_bit_blt_alpha
974
	buf2d_curve_bezier dd sz_buf2d_curve_bezier
975
	buf2d_convert_text_matrix dd sz_buf2d_convert_text_matrix
976
	buf2d_draw_text dd sz_buf2d_draw_text
977
	buf2d_crop_color dd sz_buf2d_crop_color
978
	buf2d_offset_h dd sz_buf2d_offset_h
979
	buf2d_flood_fill dd sz_buf2d_flood_fill
980
	buf2d_set_pixel dd sz_buf2d_set_pixel
981
	dd 0,0
982
	sz_init db 'lib_init',0
983
	sz_buf2d_create db 'buf2d_create',0
984
	sz_buf2d_create_f_img db 'buf2d_create_f_img',0
985
	sz_buf2d_clear db 'buf2d_clear',0
986
	sz_buf2d_draw db 'buf2d_draw',0
987
	sz_buf2d_delete db 'buf2d_delete',0
988
	sz_buf2d_line db 'buf2d_line',0
989
	sz_buf2d_rect_by_size db 'buf2d_rect_by_size',0
990
	sz_buf2d_filled_rect_by_size db 'buf2d_filled_rect_by_size',0
991
	sz_buf2d_circle db 'buf2d_circle',0
992
	sz_buf2d_img_hdiv2 db 'buf2d_img_hdiv2',0
993
	sz_buf2d_img_wdiv2 db 'buf2d_img_wdiv2',0
994
	sz_buf2d_conv_24_to_8 db 'buf2d_conv_24_to_8',0
995
	sz_buf2d_conv_24_to_32 db 'buf2d_conv_24_to_32',0
996
	sz_buf2d_bit_blt db 'buf2d_bit_blt',0
997
	sz_buf2d_bit_blt_transp db 'buf2d_bit_blt_transp',0
998
	sz_buf2d_bit_blt_alpha db 'buf2d_bit_blt_alpha',0
999
	sz_buf2d_curve_bezier db 'buf2d_curve_bezier',0
1000
	sz_buf2d_convert_text_matrix db 'buf2d_convert_text_matrix',0
1001
	sz_buf2d_draw_text db 'buf2d_draw_text',0
1002
	sz_buf2d_crop_color db 'buf2d_crop_color',0
1003
	sz_buf2d_offset_h db 'buf2d_offset_h',0
1004
	sz_buf2d_flood_fill db 'buf2d_flood_fill',0
1005
	sz_buf2d_set_pixel db 'buf2d_set_pixel',0
1006
 
1007
;--------------------------------------------------
1008
align 4
1009
import_lib_tinygl:
1010
 
1011
macro E_LIB n
1012
{
1013
	n dd sz_#n
1014
}
8174 IgorA 1015
include '../../../develop/libraries/TinyGL/asm_fork/export.inc'
5388 IgorA 1016
	dd 0,0
1017
macro E_LIB n
1018
{
1019
	sz_#n db `n,0
1020
}
8174 IgorA 1021
include '../../../develop/libraries/TinyGL/asm_fork/export.inc'
5388 IgorA 1022
 
1023
last_time dd 0
1024
 
1025
align 4
1026
buf_0: dd 0 ;указатель на буфер изображения
1027
	dw 530 ;+4 left
1028
	dw 30 ;+6 top
1029
.w: dd 256 ;+8 w
1030
.h: dd 512 ;+12 h
1031
.color: dd 0xffffd0 ;+16 color
1032
	db 24 ;+20 bit in pixel
1033
 
1034
align 4
1035
buf_1: dd 0 ;указатель на буфер изображения
1036
	dw 0 ;+4 left
1037
	dw 0 ;+6 top
1038
.w: dd 512 ;+8 w
1039
.h: dd 512 ;+12 h
1040
.color: dd 0xffffff ;+16 color
1041
	db 24 ;+20 bit in pixel
1042
 
1043
scale dd 1.414213562
1044
angle_x dd 0.0
1045
angle_y dd 0.0
1046
angle_z dd 0.0
1047
delt_size dd 3.0
5949 IgorA 1048
angle_dxm dd 2.8444 ;~ 3d_wnd_w/180 - прибавление углов поворота сцены при вращении мышей
1049
angle_dym dd 2.8444 ;~ 3d_wnd_h/180
5388 IgorA 1050
 
1051
opt_light dw 0 ;опция для включения/выключения света
1052
opt_cube_box dw 1 ;опция для рисования рамки вокруг объекта
5393 IgorA 1053
opt_auto_rotate dw 0 ;опция для автоматического поворота объекта
5388 IgorA 1054
 
1055
light_position dd 0.0, 0.0, 2.0, 1.0 ; Расположение источника [0][1][2]
1056
	;[3] = (0.0 - бесконечно удаленный источник, 1.0 - источник света на определенном расстоянии)
1057
light_dir dd 0.0,0.0,0.0 ;направление лампы
1058
 
1059
mat_specular dd 0.3, 0.3, 0.3, 1.0 ; Цвет блика
1060
mat_shininess dd 3.0 ; Размер блика (обратная пропорция)
1061
white_light dd 0.8, 0.8, 0.8, 1.0 ; Цвет и интенсивность освещения, генерируемого источником
1062
lmodel_ambient dd 0.3, 0.3, 0.3, 1.0 ; Параметры фонового освещения
1063
 
1064
 
1065
align 16
1066
i_end:
8174 IgorA 1067
	ctx1 rb 28 ;sizeof.TinyGLContext = 28
1068
	mouse_drag dd 0 ;режим поворота сцены от перемещении курсора мыши
1069
	mouse_x dd 0
1070
	mouse_y dd 0
5388 IgorA 1071
	rb 4096
1072
stacktop:
1073
	sys_path rb 1024
5949 IgorA 1074
	file_name rb 2048
5388 IgorA 1075
	library_path rb 1024
1076
	plugin_path rb 4096
1077
	openfile_path rb 4096
1078
	filename_area rb 256
5949 IgorA 1079
	sc system_colors
1080
	procinfo process_information
1081
	run_file_70 FileInfoBlock
5388 IgorA 1082
mem: