topical media & game development

talk show tell print

Web3D/VR

game technique

Some 'techy' stuff

Dynamic movement using scripts

Topics:

Blaxxun Extensions

Further documentation

Most blaxxun extentions are documented

extemely bad.

The only doucmentation is the 'Release Nodes'

See: www.blaxxun.com/developer

Blaxxun Extensions - Keyboard Handling (1)

'Connecting' keyboard events


  function initialize() {
      // Request keyboard events
      oldMask = Browser.eventMask;
      // Request Key-Up&Down events only...
      Browser.eventMask = ((1<<5) | (1<<6)); 
      // Add 'me' as event observer
      Browser.addRoute(Browser,'event_changed',
                       me,     'onEvent');
  }
  

Blaxxun Extensions - Keyboard Handling (2)

'Dis-connecting' keyboard events


  function shutdown() {
      // Remove 'me' as event observer
      Browser.deleteRoute(Browser,'event_changed',
                          me,     'onEvent');
      // Restore old event Mask
      Browser.eventMask = oldMask;
  }
  

Blaxxun Extensions - Keyboard Handling (3)

Handling keyboard events


  function onEvent(e,time) {
      if (e.type == 'keydown') {
          if(e.keyCode == 32) space = TRUE;
          e.returnValue = false;
      } else if (e.type == 'keyup') {
          if(e.keyCode == 32) space = FALSE;
          e.returnValue = false;
      } else {
          Browser.print('Unknown event : '+e.type);
      }
  }
  

Scripting

These examples

Note these examples are 'homebrewed' there

is no 'official' way to do these things.

The sourcecode of the examples is available

from the MMA-1 webpage.

Game Loop - Revisited (1)

General Idea:

Game Loop - Revisited (2)

Code:


  function tick(timeValue,timeStamp) {
      // Initialization
      if(oldTick == 0) oldTick = v;
      while (oldTick < timeValue) {
          // Increment with 1/20th of a second
          oldTick = oldTick + 0.05;
          // And update the world-state
          update();
      }
  }
  

Movement Vectors - Simple Physics (1)

Simple Point-Mass Physics

Movement Vectors - Simple Physics (2)

Fields Needed:


  field SFVec3f    position    0 0 0
  field SFRotation orientation 0 1 0 0
  field SFVec3f    speed       0 0 0
  field SFVec3f    direction   0 0 1
  

Movement Vectors - Simple Physics (3)

Some Code:


  if(space) // Accelerate in currect direction
      speed = speed + direction*0.01;
  if(left)  // Turn left
      direction = (new SFRotation(0,1,0, 0.1)).
                   multVec(direction);
  if(right) // Turn right
      direction = (new SFRotation(0,1,0,-0.1)).
                   multVec(direction);
  position = position + speed;
  

Movement Vectors - Simple Physics (4)

An Example:

try keyboard.wrl to check your keycodes

Example 1

Movement Vectors - Down To Earth (1)

Simple Racing Physics

Movement Vectors - Down To Earth (2)

Fields Needed:


  field SFVec3f    position    0 0 0
  field SFRotation orientation 0 1 0 0
  field SFFloat    speed       0
  field SFVec3f    direction   0 0 1
  

Movement Vectors - Down To Earth (3)

Some Code:


  // Acc/De-cellerate
  if(up)   speed = speed + 0.01;
  if(down) speed = speed - 0.01;
  if(left) // Turn left
      direction = (new SFRotation(0,1,0, 0.1)).
                   multVec(direction);
  if(right) // Turn right
      direction = (new SFRotation(0,1,0,-0.1)).
                   multVec(direction);
  position = position + direction*speed;
  

Movement Vectors - Down To Earth (4)

An Example:

Example 2


[] readme course(s) preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthought(s) appendix reference(s) example(s) resource(s) _

(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.