import gui $include "guih.icn" class Untitled : Dialog(chat_input, chat_output, text_field_1, subwin) method component_setup() self.setup() end method end_dialog() end method init_dialog() end method on_exit(ev) write("goodbye") exit(0) end method on_br(ev) end method on_kp(ev) end method on_mr(ev) end method on_subwin(ev) write("subwin") end method on_about(ev) sav := &window &window := &null Notice("please10 - a 3D demo by Jeffery") &window := sav end method on_chat(ev) chat_output.set_contents(put(chat_output.get_contents(), chat_input.get_contents())) chat_output.set_selections([*(chat_output.get_contents())]) chat_input.set_contents("") end method setup() local exit_menu_item, image_1, menu_1, menu_2, menu_bar_1, overlay_item_1, overlay_set_1, text_menu_item_2 self.set_attribs("size=800,750", "bg=light gray", "label=Edie") menu_bar_1 := MenuBar() menu_bar_1.set_pos("0", "0") menu_bar_1.set_attribs("bg=very light green", "font=serif,bold,16") menu_1 := Menu() menu_1.set_label("File") exit_menu_item := TextMenuItem() exit_menu_item.set_label("Exit") exit_menu_item.connect(self, "on_exit", ACTION_EVENT) menu_1.add(exit_menu_item) menu_bar_1.add(menu_1) menu_2 := Menu() menu_2.set_label("Help") text_menu_item_2 := TextMenuItem() text_menu_item_2.set_label("About") text_menu_item_2.connect(self, "on_about", ACTION_EVENT) menu_2.add(text_menu_item_2) menu_bar_1.add(menu_2) self.add(menu_bar_1) overlay_set_1 := OverlaySet() overlay_set_1.set_pos(6, 192) overlay_set_1.set_size(780, 558) overlay_item_1 := OverlayItem() overlay_set_1.add(overlay_item_1) overlay_set_1.set_which_one(overlay_item_1) self.add(overlay_set_1) subwin := Subwindow3D() subwin.set_pos(14, 195) subwin.set_size("767", "551") subwin.connect(self, "on_subwin", ACTION_EVENT) subwin.connect(self, "on_br", BUTTON_RELEASE_EVENT) subwin.connect(self, "on_mr", MOUSE_RELEASE_EVENT) subwin.connect(self, "on_kp", KEY_PRESS_EVENT) self.add(subwin) chat_input := TextField() chat_input.set_pos("12", "162") chat_input.set_size("769", "25") chat_input.set_draw_border() chat_input.set_attribs("bg=very light green") chat_input.connect(self, "on_chat", ACTION_EVENT) chat_input.set_contents("") self.add(chat_input) chat_output := TextList() chat_output.set_pos("10", "29") chat_output.set_size("669", "127") chat_output.set_draw_border() chat_output.set_attribs("bg=very pale whitish yellow") chat_output.set_contents([""]) self.add(chat_output) image_1 := Image() image_1.set_pos("686", "31") image_1.set_size("106", "120") image_1.set_filename("edie.gif") image_1.set_internal_alignment("c", "c") image_1.set_scale_up() self.add(image_1) end initially self.Dialog.initially() end # # N3Dispatcher is a custom dispatcher. Currently it knows about 3D # subwindows but we will extend it for networked 3D applications. # class N3Dispatcher : Dispatcher(subwins, nets, connections) method add_subwin(sw) insert(subwins, sw) end method do_net(x) write("do net ", image(x)) end method do_nullstep() if xdelta ~= 0 then { cam_move(xdelta) moved := 1 } if ydelta ~= 0 then { cam_orient_yaxis(ydelta) moved := 1 } if lookdelta ~= 0 then { looky +:= lookdelta; moved := 1 } if (\((dor := curr_room.exits[1]).delt)) ~=== 0 then { if not (dor.delta()) then dor.done_opening() else moved := 1 } if \moved then { Eye(posx,posy,posz,lookx,looky,lookz) return } end method cam_move(dir) local deltax := dir * cam_lx, deltaz := dir * cam_lz if curr_room.disallows(posx+deltax,posz+deltaz) then { deltax := 0 if curr_room.disallows(posx+deltax,posz+deltaz) then { deltaz := 0; deltax := dir*cam_lx if curr_room.disallows(posx+deltax,posz+deltaz) then { fail } } } #calculate new position posx +:= deltax posz +:= deltaz #update look at spot lookx := posx + cam_lx lookz := posz + cam_lz end # # Orient the camera # method cam_orient_yaxis(turn) #update camera angle cam_angle +:= turn if abs(cam_angle) > 2 * &pi then cam_angle := 0.0 cam_lx := sin(cam_angle) cam_lz := -cos(cam_angle) lookx := posx + cam_lx lookz := posz + cam_lz end # # Execute one event worth of motion and update the camera # method do_cve_event() local L := Pending() case ev := Event() of { Key_Up: { xdelta := 0.05 while L[1]===Key_Up_Release & L[4]===Key_Up do { Event(); Event(); xdelta +:= 0.05 } cam_move(xdelta) # Move Foward } Key_Down: { xdelta := -0.05 while L[1]===Key_Down_Release & L[4]===Key_Down do { Event(); Event(); xdelta -:= 0.05 } cam_move(xdelta) # Move Backward } Key_Left: { ydelta := -0.05 while L[1]===Key_Left_Release & L[4]===Key_Left do { Event(); Event(); ydelta -:= 0.05 } cam_orient_yaxis(ydelta) # Turn Left } Key_Right: { ydelta := 0.05 while L[1]=== Key_Right_Release & L[4] === Key_Right do { Event(); Event(); ydelta +:= 0.05 } cam_orient_yaxis(ydelta) # Turn_Right } "w": looky +:= (lookdelta := 0.05) #Look Up "s": looky +:= (lookdelta := -0.05) #Look Down "q": exit(0) "d": { dor := curr_room.exits[1] if \ (dor.delt) === 0 then { dor.start_opening() } else dor.done_opening() dor.delta() } -166 | -168 | (-(Key_Up|Key_Down) - 128) : xdelta := 0 -165 | -167 | (-(Key_Left|Key_Right) - 128) : ydelta := 0 -215 | -211 : lookdelta := 0 } Eye(posx,posy,posz,lookx,looky,lookz) end method message_loop(r) local L connections := [] dialogwins := set() every insert(dialogwins, (!dialogs).win) every put(connections, !dialogwins | !subwins | !nets) while \r.is_open do { if x := select(connections,1)[1] then { if member(subwins, x) then { &window := x do_cve_event() } else if member(dialogwins, x) then do_event() else if member(nets, x) then do_net(x) else write("unknown selector ", image(x)) # do at least one step per select() for smoother animation do_nullstep() } else do_validate() | do_ticker() | do_nullstep() | delay(idle_sleep) } end initially subwins := set() nets := set() dialogs := set() tickers := set() idle_sleep_min := 10 idle_sleep_max := 50 compute_idle_sleep() end class Subwindow3D : Component () method display() initial please(cwin) write("subwin3d display()") Refresh(cwin) end method init() if /self.parent then fatal("incorrect ancestry (parent null)") self.parent_dialog := self.parent.get_parent_dialog_reference() self.cwin := (Clone ! ([self.parent.get_cwin_reference(), "gl", "size="||w_spec||","||h_spec, "pos=14,195", "inputmask=mck"] ||| self.attribs)) | stop("can't open 3D win") self.cbwin := (Clone ! ([self.parent.get_cbwin_reference(), "gl", "size="||w_spec||","||h_spec, "pos=14,195"] ||| self.attribs)) set_accepts_focus() dispatcher.add_subwin(self.cwin) end end procedure main() local d # # overwrite the system dispatcher with one that knows about subwindows # gui::dispatcher := N3Dispatcher() d := Untitled() d.show_modal() end link cve procedure make_cooridoor() cooridoor := Room("cooridoor", -5, 0, 4, 10, 5, 3.95, "wall2.gif") put(Rooms, cooridoor) return cooridoor end procedure make_SH167(cooridoor) SH167 := Room("SH 167", -5, 0, 0, 10, 5, 6) SH167.floor := Wall("floor2.gif",-5,0,0, -5,0,-6, 5,0,-6, 5,0,0) d := Door(3, 0, 0) SH167.add_door(d) cooridoor.add_door(d, 1) # PILLAR -- should redo as a single (cube) object pillar := Box() pillar.mkwall(4,0,-6,4,5,-6, 4,5,-5.5,4,0,-5.5) pillar.mkwall(4,0,-5.5,3.5,0,-5.5,3.5,5,-5.5,4,5,-5.5) pillar.mkwall(3.5,0,-5.5,3.5,5,-5.5,3.5,5,-6,3.5,0,-6) SH167.add_obstacle(pillar) pleasewindow := Wall("wall2.gif", -5,1.5,-6.2,-5,5,-6.2,5,5,-6.2,5,1.5,-6.2) SH167.add_decoration(pleasewindow) whiteboard := Wall("whiteboard.gif", -4.95,1.5,-.5,-4.95,4,-.5,-4.95,4,-5.5,-4.95,1.5,-5.5) SH167.add_decoration(whiteboard) put(Rooms, SH167) return SH167 end #CONTROLS: #up arrow - move foward #down arrow - move backward #left arrow - rotate camera left #right arrow - rotate camera right # ' w ' key - look up # ' s ' key - look down # ' d ' key - toggle door open/closed #if you get lost in space (may happen once in a while) #just restart the program $include "keysyms.icn" #GLOBAL variables global posx, posy, posz # current eye x,y,z position global lookx, looky, lookz # current look x position and so on global cam_lx, cam_lz, cam_angle # eye angles for orientation global xdelta, ydelta, lookdelta global Rooms, curr_room procedure please(d) &window := d WAttrib("texmode=on") #initialize globals posx := 0.0; posy := 2.75; posz := -3.0 lookx := lookz := 0.0; looky := 2.5 cam_lx := cam_angle := 0.0; cam_lz := -1.0 # render graphics Rooms := [ ] cooridoor := make_cooridoor() curr_room := make_SH167(cooridoor) every (!Rooms).render() xdelta := ydelta := lookdelta := 0 dispatcher.cam_move(0.01) Eye(posx,posy,posz,lookx,looky,lookz) # ready for event processing loop end ### Ivib-v2 layout ## #class|Canvas|17|Name Table|table|integer|0|11|string|custom|integer|1| #string|editable_text_list|integer|1|string|image|integer|1|string|menu #|integer|2|string|menu_bar|integer|1|string|overlay_item|integer|1|str #ing|overlay_set|integer|1|string|panel|integer|1|string|text_field|int #eger|2|string|text_list|integer|1|string|text_menu_item|integer|2|Supe #rClass Name|string|Dialog|Import Name|string|gui|Button Groups|class|B #uttonGroupSet|2|Parent Canvas|1|Boxes|list|0|Checkbox Groups|class|Che #ckBoxGroupSet|2|Parent Canvas|1|Boxes|list|0|Gen Indent|integer|3|Gen #Main|integer|1|Gen Component Setup|integer|1|Gen Init Dialog|integer|1 #|Gen Initially|integer|1|Dialog Struct|class|CDialog|4|Min Width|null| #Min Height|null|Ticker Rate|null|Attribs|list|2|string|bg=light gray|s #tring|label=Edie|Name|string|Untitled|Width|integer|800|Height|integer #|750|Items|list|6|class|CanvasMenuBar|26|Parent Canvas|1|Name|string|m #enu_bar_1|Class Name|string|MenuBar|Import Name|string|gui|X Fix|null| #Y Fix|null|W Fix|null|H Fix|null|W Default|integer|1|H Default|integer #|1|X Spec|string|0|Y Spec|string|0|W Spec|string|100%|H Spec|integer|2 #9|X Align|string|l|Y Align|string|t|Is shaded|null|Is Button Subclass| #null|Draw Border|null|Attribs|list|2|string|bg=very light green|string #|font=serif,bold,16|Tooltip|null|Accel|null|Event Handlers|list|0|Clas #s Variable|null|Parent Component|1|Menus|list|2|class|CanvasMenu|17|Na #me|string|menu_1|Class Name|string|Menu|Import Name|string|gui|Accel|n #ull|Label|string|File|Label Left|null|Label Right|null|Is shaded|null| #Img Left|null|Img Left Width|null|Img Left Height|null|Img Right|strin #g|9,c1,0~~~~~~~~000~~~~~~00000~~~~0000000~~0000000000000000~~00000~~~~ #000~~~~~~0~~~~~~~~|Img Right Width|integer|9|Img Right Height|integer| #9|Event Method|null|Class Variable|null|Children|list|1|class|CanvasTe #xtMenuItem|16|Name|string|exit_menu_item|Class Name|string|TextMenuIte #m|Import Name|string|gui|Accel|null|Label|string|Exit|Label Left|null| #Label Right|null|Is shaded|null|Img Left|null|Img Left Width|null|Img #Left Height|null|Img Right|null|Img Right Width|null|Img Right Height| #null|Event Method|string|on_exit|Class Variable|null|class|CanvasMenu| #17|Name|string|menu_2|Class Name|string|Menu|Import Name|string|gui|Ac #cel|null|Label|string|Help|Label Left|null|Label Right|null|Is shaded| #null|Img Left|null|Img Left Width|null|Img Left Height|null|Img Right| #string|9,c1,0~~~~~~~~000~~~~~~00000~~~~0000000~~0000000000000000~~0000 #0~~~~000~~~~~~0~~~~~~~~|Img Right Width|integer|9|Img Right Height|int #eger|9|Event Method|null|Class Variable|null|Children|list|1|class|Can #vasTextMenuItem|16|Name|string|text_menu_item_2|Class Name|string|Text #MenuItem|Import Name|string|gui|Accel|null|Label|string|About|Label Le #ft|null|Label Right|null|Is shaded|null|Img Left|null|Img Left Width|n #ull|Img Left Height|null|Img Right|null|Img Right Width|null|Img Right # Height|null|Event Method|string|on_about|Class Variable|null|class|Ca #nvasOverlaySet|27|Parent Canvas|1|Name|string|overlay_set_1|Class Name #|string|OverlaySet|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix| #null|H Fix|null|W Default|null|H Default|null|X Spec|integer|6|Y Spec| #integer|192|W Spec|integer|780|H Spec|integer|558|X Align|string|l|Y A #lign|string|t|Is shaded|null|Is Button Subclass|null|Draw Border|null| #Attribs|list|0|Tooltip|null|Accel|null|Event Handlers|null|Class Varia #ble|null|Parent Component|1|Children|list|1|class|CanvasOverlayItem|27 #|Parent Canvas|1|Name|string|overlay_item_1|Class Name|string|OverlayI #tem|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix|null #|W Default|null|H Default|null|X Spec|integer|0|Y Spec|integer|0|W Spe #c|string|100%|H Spec|string|100%|X Align|string|l|Y Align|string|t|Is #shaded|null|Is Button Subclass|null|Draw Border|null|Attribs|list|0|To #oltip|null|Accel|null|Event Handlers|null|Class Variable|null|Parent C #omponent|20|Children|list|0|Parent OverlaySet|20|Which One|23|class|Ca #nvasCustom|25|Parent Canvas|1|Name|string|subwin|Class Name|string|Sub #window3D|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|null|H Fix #|null|W Default|null|H Default|null|X Spec|integer|14|Y Spec|integer|1 #95|W Spec|string|767|H Spec|string|551|X Align|string|l|Y Align|string #|t|Is shaded|null|Is Button Subclass|null|Draw Border|null|Attribs|lis #t|0|Tooltip|null|Accel|null|Event Handlers|list|4|list|2|string|ACTION #_EVENT|string|on_subwin|list|2|string|BUTTON_RELEASE_EVENT|string|on_b #r|list|2|string|MOUSE_RELEASE_EVENT|string|on_mr|list|2|string|KEY_PRE #SS_EVENT|string|on_kp|Class Variable|integer|1|Parent Component|1|clas #s|CanvasTextField|27|Parent Canvas|1|Name|string|chat_input|Class Name #|string|TextField|Import Name|string|gui|X Fix|null|Y Fix|null|W Fix|n #ull|H Fix|null|W Default|null|H Default|null|X Spec|string|12|Y Spec|s #tring|162|W Spec|string|769|H Spec|string|25|X Align|string|l|Y Align| #string|t|Is shaded|null|Is Button Subclass|null|Draw Border|integer|1| #Attribs|list|1|string|bg=very light green|Tooltip|null|Accel|null|Even #t Handlers|list|1|list|2|string|ACTION_EVENT|string|on_chat|Class Vari #able|integer|1|Parent Component|1|Contents|string||Filter String|strin #g||class|CanvasTextList|29|Parent Canvas|1|Name|string|chat_output|Cla #ss Name|string|TextList|Import Name|string|gui|X Fix|null|Y Fix|null|W # Fix|null|H Fix|null|W Default|null|H Default|null|X Spec|string|10|Y #Spec|string|29|W Spec|string|669|H Spec|string|127|X Align|string|l|Y #Align|string|t|Is shaded|null|Is Button Subclass|null|Draw Border|inte #ger|1|Attribs|list|1|string|bg=very pale whitish yellow|Tooltip|null|A #ccel|null|Event Handlers|list|0|Class Variable|integer|1|Parent Compon #ent|1|Select One|null|Select Many|null|Checked|list|1|null|Contents|li #st|1|string||class|CanvasImage|29|Parent Canvas|1|Name|string|image_1| #Class Name|string|Image|Import Name|string|gui|X Fix|null|Y Fix|null|W # Fix|null|H Fix|null|W Default|null|H Default|null|X Spec|string|686|Y # Spec|string|31|W Spec|string|106|H Spec|string|120|X Align|string|l|Y # Align|string|t|Is shaded|null|Is Button Subclass|null|Draw Border|nul #l|Attribs|list|0|Tooltip|null|Accel|null|Event Handlers|list|0|Class V #ariable|null|Parent Component|1|File name|string|edie.gif|X Internal A #lignment|string|c|Y Internal Alignment|string|c|Scale Up Flag|integer| #1|Initial Focus|null|Event Handlers|list|0|