Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6387 leency 1
;
2
;   application     :  Tiny ray tracer
3
;   compilator	    :  Fasm
4
;   system	    :  MenuetOS64/KolibriOS
5
;   author	    :  Maciej Guba aka macgub
6
;   email	    :  macgub3@wp.pl
7
;   web 	    :  http://macgub.hekko.pl
8
 
9
include "../../macros.inc"
10
 
11
timeout equ 3
12
XRES equ 500	    ; window size
13
YRES equ 500
14
maxx = XRES
15
maxy = YRES
16
use32
17
 
18
	       org    0x0
19
 
20
	       db     'MENUET01'	      ; 8 byte id
21
	       dd     0x01		      ; header version
22
	       dd     START		      ; start of code
23
	       dd     I_END		      ; size of image
24
	       dd     I_END		      ; memory for app
25
	       dd     I_END		    ; esp
26
	       dd     0x0 , 0x0 	      ; I_Param , I_Icon
27
 
28
START:				; start of execution
29
 
30
     call draw_window
31
 
32
still:
33
 
34
    mov  eax,23 		; wait here for event
35
    mov  ebx,timeout
36
    int  0x40
37
;    mov eax,11 		  ; check for event no wait
38
;    int 0x40
39
 
40
    cmp  eax,1			; redraw request ?
41
    je	 red
42
    cmp  eax,2			; key in buffer ?
43
    je	 key
44
    cmp  eax,3			; button in buffer ?
45
    je	 button
46
 
47
    jmp  noclose
48
 
49
  red:				; redraw
50
    call draw_window
51
    jmp  still
52
 
53
  key:				; key
54
    mov  eax,2			; just read it and ignore
55
    int  0x40
56
    jmp  still
57
 
58
  button:			; button
59
    mov  eax,17 		; get id
60
    int  0x40
61
 
62
    cmp  ah,1			; button id=1 ?
63
    jne  noclose
64
 
65
    mov  eax,-1 		; close this program
66
    int  0x40
67
  noclose:
68
 
69
; mov eax,13
70
; mov ebx,20*65536+maxx-25
71
; mov ecx,20*65536+maxy-25
72
; xor edx,edx
73
; int 0x40
74
 
75
 mov edi,screen
76
 mov ecx,maxx*maxy*3/4
77
 xor eax,eax
78
 cld
79
 rep stosd
80
 
81
 add [deg_counter],1
82
 cmp [deg_counter],360
83
 jne @f
84
 mov [deg_counter],0
85
@@:
86
 fninit
87
 fld	 [one_deg]
88
 fimul	 [deg_counter]
89
 fsincos
90
 fstp	 [sin]
91
 fstp	 [cos]
92
 
93
 mov  ecx,MAX_SPHERES	;MAX_LIGHTS
94
 mov  esi,non_rot_sphere  ;light
95
 mov  edi,sphere
96
 
97
.rotary:
98
 
99
 
100
 fld  dword[esi]
101
 fsub [xo]
102
 fmul [cos]
103
 fld  dword[esi+8]
104
 fsub [zo]
105
 fmul [sin]
106
 fchs
107
 faddp
108
 fadd [xo]   ; top of stack - new 'x'
109
 fstp dword[edi]
110
 
111
 fld  dword[esi+8]
112
 fsub [zo]
113
 fmul [cos]
114
 fld  dword[esi]
115
 fsub dword[xo]
116
 fmul [sin]
117
 faddp
118
 fadd [zo]
119
 fstp dword[edi+8]
120
; fld  dword[esi+4]
121
; fstp dword[edi+4]
122
 push dword[esi+4]
123
 pop  dword[edi+4]
124
 mov  dword[edi+12],0.0
125
 
126
 add  esi,12
127
 add  edi,16
128
 sub  ecx,1
129
 jnz  .rotary
130
 
131
 mov  ecx,MAX_LIGHTS
132
 mov  esi,non_rot_light
133
 mov  edi,light
134
 
135
.rotary_lights:
136
 
137
 
138
 fld  dword[esi]
139
 fsub [xo]
140
 fmul [cos]
141
 fld  dword[esi+4]
142
 fsub [yo]
143
 fmul [sin]
144
 fchs
145
 faddp
146
 fadd [xo]   ; top of stack - new 'x'
147
 fstp dword[edi]
148
 
149
 fld  dword[esi]
150
 fsub [xo]
151
 fmul [sin]
152
 fchs
153
 fld  dword[esi+4]
154
 fsub dword[yo]
155
 fmul [cos]
156
 faddp
157
 fadd [yo]
158
 fstp dword[edi+4]
159
; fld  dword[esi+8]
160
; fstp dword[edi+8]
161
 push dword[esi+8]
162
 pop  dword[edi+8]
163
 mov  dword[edi+12],0.0
164
 
165
 add  esi,12
166
 add  edi,16
167
 sub  ecx,1
168
 jnz  .rotary_lights
169
 
170
 
171
 
172
 call main_loop
173
 
174
 mcall 7,screen,,<0,0>
175
 
176
 
177
 
178
jmp still
179
 
180
 
181
 
182
include 'RAY.INC'
183
 
184
;   *********************************************
185
;   *******  WINDOW DEFINITIONS AND DRAW ********
186
;   *********************************************
187
draw_window:
188
 
189
	mcall 12,1
190
 
191
    mcall 48,4 ; get skin height
192
    lea ecx,[eax + (100 shl 16) + maxy+4]
193
    mov edi,title
194
    mcall 0,<100,maxx+9>,,0x74000000
195
 
196
	mcall 12,2
197
 
198
    ret
199
 
200
title db 'Ray tracing',0
201
xo dd 0.5
202
yo dd 0.5
203
zo dd 0.1
204
deg_counter dw 0
205
one_deg dd 0.017453
206
include 'dataray.inc'
207
sin dd ?
208
cos dd ?
209
screen rb XRES * YRES * 3
210
mem_stack:
211
 rb 65536
212
I_END:
213