2008-11-11 04:10:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: arrays kernel math math.functions math.order math.vectors
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								namespaces opengl opengl.gl sequences ui ui.gadgets ui.gestures
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-07 20:47:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ui.gadgets.worlds ui.render accessors combinators literals ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-02-02 16:14:22 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: opengl.demo-support
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-08-13 20:21:44 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: FOV $[ 2.0 sqrt 1 + ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-22 20:08:45 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								CONSTANT: MOUSE-MOTION-SCALE 0.5
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: KEY-ROTATE-STEP 10.0
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								SYMBOL: last-drag-loc
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: demo-world < world yaw pitch distance ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: set-demo-orientation ( world yaw pitch distance -- world )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ >>yaw ] [ >>pitch ] [ >>distance ] tri* ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-15 23:36:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								GENERIC: far-plane ( gadget -- z )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								GENERIC: near-plane ( gadget -- z )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								GENERIC: distance-step ( gadget -- dz )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: demo-world far-plane ( gadget -- z )
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-15 23:36:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    drop 4.0 ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: demo-world near-plane ( gadget -- z )
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-15 23:36:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    drop 1.0 64.0 / ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: demo-world distance-step ( gadget -- dz )
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-15 23:36:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    drop 1.0 64.0 / ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-17 00:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: fov-ratio ( gadget -- fov ) dim>> dup first2 min v/n ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: yaw-demo-world ( yaw gadget -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-11 21:51:25 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ + ] with change-yaw relayout-1 ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: pitch-demo-world ( pitch gadget -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-11 21:51:25 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ + ] with change-pitch relayout-1 ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: zoom-demo-world ( distance gadget -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-11 21:51:25 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ + ] with change-distance relayout-1 ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: demo-world pref-dim* ( gadget -- dim )
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-17 00:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    drop { 640 480 } ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: -+ ( x -- -x x )
							 | 
						
					
						
							
								
									
										
										
										
											2008-07-11 21:51:25 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ neg ] keep ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 23:02:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: demo-world-frustum ( world -- -x x -y y near far )
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-17 00:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ near-plane ] [ far-plane ] [ fov-ratio ] tri [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        nip swap FOV / v*n
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-15 23:36:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        first2 [ -+ ] bi@
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-17 00:06:13 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ] 3keep drop ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 23:02:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								M: demo-world resize-world
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    GL_PROJECTION glMatrixMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    glLoadIdentity
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 23:02:50 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ [ 0 0 ] dip dim>> first2 glViewport ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ demo-world-frustum glFrustum ] bi ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: demo-world-set-matrix ( gadget -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT bitor glClear
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    GL_MODELVIEW glMatrixMode
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    glLoadIdentity
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ [ 0.0 0.0 ] dip distance>> neg glTranslatef ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ pitch>> 1.0 0.0 0.0 glRotatef ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ yaw>>   0.0 1.0 0.0 glRotatef ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    tri ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: reset-last-drag-rel ( -- )
							 | 
						
					
						
							
								
									
										
										
										
											2008-03-13 04:39:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    { 0 0 } last-drag-loc set-global ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: last-drag-rel ( -- rel )
							 | 
						
					
						
							
								
									
										
										
										
											2008-03-13 04:39:05 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    drag-loc [ last-drag-loc get v- ] keep last-drag-loc set-global ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: drag-yaw-pitch ( -- yaw pitch )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    last-drag-rel MOUSE-MOTION-SCALE v*n first2 ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2008-11-11 04:10:41 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: gl-vertex ( point -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dup length {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { 2 [ first2 glVertex2d ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { 3 [ first3 glVertex3d ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        { 4 [ first4 glVertex4d ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    } case ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: gl-normal ( normal -- ) first3 glNormal3d ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: do-state ( mode quot -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    swap glBegin call glEnd ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: rect-vertices ( lower-left upper-right -- )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    GL_QUADS [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        over first2 glVertex2d
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dup first pick second glVertex2d
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        dup first2 glVertex2d
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        swap first swap second glVertex2d
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] do-state ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								demo-world H{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down f f "LEFT"  } [ KEY-ROTATE-STEP neg swap yaw-demo-world ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down f f "RIGHT" } [ KEY-ROTATE-STEP     swap yaw-demo-world ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down f f "DOWN"  } [ KEY-ROTATE-STEP neg swap pitch-demo-world ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down f f "UP"    } [ KEY-ROTATE-STEP     swap pitch-demo-world ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down f f "="     } [ dup distance-step neg swap zoom-demo-world ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ key-down f f "-"     } [ dup distance-step     swap zoom-demo-world ] }
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { T{ button-down f f 1 }    [ drop reset-last-drag-rel ] }
							 | 
						
					
						
							
								
									
										
										
										
											2009-05-03 18:14:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    { T{ drag f 1 }             [ drag-yaw-pitch rot [ pitch-demo-world ] keep yaw-demo-world ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { mouse-scroll              [ scroll-direction get second over distance-step * swap zoom-demo-world ] }
							 | 
						
					
						
							
								
									
										
										
										
											2008-01-25 01:16:36 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								} set-gestures
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 |