#VRML V2.0 utf8 ## ##@ scene NavigationInfo { type ["NONE"] } DEF DEFAULT_VIEWPOINT Viewpoint { position 0 40 0 orientation 1 0 0 -1.57 } ##@ floor... Shape { geometry Box { size 40 0.1 40 } appearance Appearance { texture ImageTexture { url "local/game/images/grid.gif" } } } ##@ object : DEF OBJECT Transform { children Transform { rotation 1 0 0 1.57 children [ Shape { geometry Cone {} appearance Appearance { material Material { emissiveColor 1 0 0 } } } DEF SWITCH Switch { whichChoice -1 choice [ ## Flame Transform { translation 0 -2 0 rotation 1 0 0 3.14 children Shape { geometry Cone { bottomRadius 0.6 } appearance Appearance { material Material { emissiveColor 1 1 0 } } } } ] } ] } } ##@ script DEF SCRIPT Script { directOutput TRUE field SFNode me USE SCRIPT field SFTime oldTick 0 eventIn SFTime tick field SFInt32 oldMask 0 eventIn SFNode onEvent eventOut SFVec3f position_changed eventOut SFRotation orientation_changed eventOut SFInt32 flame_choice eventOut SFInt32 hide_text field SFVec3f speed 0 0 0 field SFVec3f position 0 0 0 field SFVec3f direction 0 0 1 field SFRotation orientation 0 0 1 0 field SFRotation rotA 0 0 1 0 field SFRotation rotB 0 0 1 0 field SFVec3f defDirection 0 0 1 field SFVec3f yAxis 0 1 0 field SFVec3f up 0 1 0 ##@ keys (!) field SFBool upk FALSE field SFBool down FALSE field SFBool left FALSE field SFBool right FALSE field SFBool space FALSE field SFInt32 k_upk 1004 ##38 field SFInt32 k_down 1005 ##40 field SFInt32 k_left 1006 ##37 field SFInt32 k_right 1007 ##39 field SFInt32 k_space 32 ##@ functions url "javascript: function initialize() { connectKeyboard(); } function shutdown() { disconnectKeyboard(); } function connectKeyboard() { // tell what events oldMask = Browser.eventMask; Browser.eventMask = ((1<<5) | (1<<6)); // KeyUp&Down Only... // add event observer Browser.addRoute(Browser,'event_changed',me,'onEvent'); } function disconnectKeyboard() { // remove event observer Browser.deleteRoute(Browser,'event_changed',me,'onEvent'); Browser.eventMask = oldMask; } ##@ onEvent function onEvent(e,t) { if (e.type == 'keydown') { if(e.keyCode == k_left) { left = TRUE; e.returnValue = false; } else if(e.keyCode == k_upk) { upk = TRUE; e.returnValue = false; } else if(e.keyCode == k_right) { right = TRUE; e.returnValue = false; } else if(e.keyCode == k_down) { down = TRUE; e.returnValue = false; } else if(e.keyCode == k_space) { space = TRUE; e.returnValue = false; } } else if (e.type == 'keyup') { if(e.keyCode == 37) { left = FALSE; e.returnValue = false; } else if(e.keyCode == k_upk) { upk = FALSE; e.returnValue = false; } else if(e.keyCode == k_right) { right = FALSE; e.returnValue = false; } else if(e.keyCode == k_down) { down = FALSE; e.returnValue = false; } else if(e.keyCode == k_space) { space = FALSE; e.returnValue = false; } } else { Browser.print('Unknown event : '+e.type); } } ##@ tick and update function tick(v,t) { if(oldTick == 0) { oldTick = v; } while (oldTick < v) { update(); oldTick = oldTick + 0.05; } } function update() { // Y-as wordt eigenlijkniet gebruikt, beweging // i beperkt tot x/z vlak, // maar voor de volledigheid wordt het wel // allemaal netjes berekend... // Spatiebalk = gas geven if(space) { speed[0] = speed[0] + direction[0]*0.01; speed[1] = speed[1] + direction[1]*0.01; speed[2] = speed[2] + direction[2]*0.01; flame_choice = 0; hide_text = -1; } else { flame_choice = -1; } // Pijltjes toetsen = draaien if(upk) { } if(down) { } if(left) { direction = (new SFRotation(0,1,0, 0.1)).multVec(direction); } if(right) { direction = (new SFRotation(0,1,0,-0.1)).multVec(direction); } // verplaats object position = position.add(speed); position_changed = position; // output de juiste updates rotA = new SFRotation(defDirection,direction); up = rotA.multVec(yAxis); rotB = new SFRotation(direction.cross(up), direction.cross(yAxis)); orientation = rotA.multiply(rotB); orientation_changed = orientation; } " } ##@ sensor and routing DEF TIMER TimeSensor { enabled TRUE loop TRUE } ROUTE TIMER.time_changed TO SCRIPT.tick ROUTE SCRIPT.position_changed TO OBJECT.translation ROUTE SCRIPT.orientation_changed TO OBJECT.rotation ROUTE SCRIPT.flame_choice TO SWITCH.whichChoice ##@ manual... EXTERNPROTO STText [ exposedField MFString string ] [ "@vr-example-text-proto.wrl" ] DEF HIDE_TEXT Switch { whichChoice 0 choice [ Group { children [ Transform { translation 0 1.8 0 children [ Shape { appearance Appearance { material Material { diffuseColor 0 0 0 emissiveColor 0 0 0 specularColor 0 0 0 transparency 0.4 } } geometry Box { size 27 0.1 20 } } ] } Transform { translation -13.5 2 -9 rotation 1 0 0 -1.57 children [ STText { string [ " BOGUS LITTLE GAME ", " (ASTEROIDS MOTION) ", "", "CONTROLS", "---------------------", "SPACEBAR :ACCELERATE", "LEFT/RIGHT:TURN", "---------------------", "", "SHOWS", "---------------------", "BLAXXUN KEYBOARD ", "SCRIPT BASED MOTION ", "GAME LOOP ", "BLAXXUN TEXTURE-TEXT ", "---------------------", "", "PRESS SPACE TO START!" ] } ] } ] } ] } ROUTE SCRIPT.hide_text TO HIDE_TEXT.whichChoice ##