#VRML V2.0 utf8 ## ##:@* race ##@ 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 "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 } } } ] } } ##@ 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 hide_text field SFFloat speed 0 field SFVec3f position 0 0 0 field SFVec3f direction 0 0 1 field SFRotation orientation 0 0 1 0 ##@ directional 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 field SFBool upk FALSE field SFBool down FALSE field SFBool left FALSE field SFBool right FALSE field SFBool space FALSE ##@ 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; } ##@ event handling function onEvent(e,t) { if (e.type == 'keydown') { if(e.keyCode == 37) { left = TRUE; e.returnValue = false; } else if(e.keyCode == 38) { upk = TRUE; e.returnValue = false; } else if(e.keyCode == 39) { right = TRUE; e.returnValue = false; } else if(e.keyCode == 40) { down = TRUE; e.returnValue = false; } else if(e.keyCode == 32) { space = TRUE; e.returnValue = false; } ##@ keyup } else if (e.type == 'keyup') { if(e.keyCode == 37) { left = FALSE; e.returnValue = false; } else if(e.keyCode == 38) { upk = FALSE; e.returnValue = false; } else if(e.keyCode == 39) { right = FALSE; e.returnValue = false; } else if(e.keyCode == 40) { down = FALSE; e.returnValue = false; } else if(e.keyCode == 32) { space = FALSE; e.returnValue = false; } } else { Browser.print('Unknown event : '+e.type); } } ##@ tick function tick(v,t) { if(oldTick == 0) { oldTick = v; } while (oldTick < v) { update(); oldTick = oldTick + 0.05; } } ##@ update function update() { // Y-as wordt eigenlijkniet gebruikt, beweging // i beperkt tot x/z vlak, // maar voor de volledigheid wordt het wel // allemaal netjes berekend... if(space) { hide_text = -1; } // Up/Down = gas/rem if(upk) { speed = speed + 0.01; } if(down) { speed = speed - 0.01; } // Left/Right = sturen // Eigenlijk zou snelheid sturen moeten beinvloeden if(left) { direction = (new SFRotation(0,1,0, 0.1)).multVec(direction); } if(right) { direction = (new SFRotation(0,1,0,-0.1)).multVec(direction); } ##@ positioning position[0] = position[0] + direction[0]*speed; position[1] = position[1] + direction[1]*speed; position[2] = position[2] + direction[2]*speed; position_changed = position; // 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; } " } ##@ timer DEF TIMER TimeSensor { enabled TRUE loop TRUE } ##@ routing ROUTE TIMER.time_changed TO SCRIPT.tick ROUTE SCRIPT.position_changed TO OBJECT.translation ROUTE SCRIPT.orientation_changed TO OBJECT.rotation ##@ explanation EXTERNPROTO STText [ exposedField MFString string ] [ "@vr-STText.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 ", " (RACING MOTION) ", "", "CONTROLS", "---------------------", "UP :ACCELERATE", "DOWN :BRAKE ", "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 ##