:


Some 'techy' stuff

:Dynamic movement using scripts Topics: :Blaxxun Extentions Further documentation
Most blaxxun extentions are documented
extemely bad.

The only doucmentation is the 'Release Nodes'
See: www.blaxxun.com/developer
:Blaxxun Extentions - 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 Extentions - 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 Extentions - 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); } } :Blaxxun Extentions - Texture Text (1) What is it ?

:Blaxxun Extentions - Texture Text (2) Transform { translation -8 0 0 scale 0.5 0.5 1 children [ Shape { appearance Appearance { texture ImageTexture { url "images/font.gif" repeatS FALSE repeatT FALSE } material Material { diffuseColor 1 1 1 } } geometry Text { string [ "THIS ALLOWS US TO", "ADD TEXT IN CUSTOM FONTS", "EASILY", "", "ONE DOWNSIDE HOWEVER IS", "THAT IT IS ALYWAYS A", "FIXED-WIDTH FONT.", "", "ABCDEFGHIJKLMNOPQRSTUVWX", "YZ 1234567890 !@#%?,.:;*" ] fontStyle FontStyle { family ["TEXTURE 32 92 15 4 1.28 0 0"] justify "LEFT" } } } ] } :Blaxxun Extentions - Texture Text (3) VRML Syntax
Shape { appearance Appearance { texture ImageTexture { url "font.gif" } } geometry Text { string [ "TEXT-HERE" ] fontStyle FontStyle { family ["TEXTURE 32 92 15 4 1.28 0 0"] ## Parameters, first-char, last-char, cols, rows, ## aspect, extra-space, italic-shift } } } :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 - Relisited (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:

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

:Vectors To VRML Events - (1) What is the problem ?
:Vectors To VRML Events - (2) Translating direction to rotation
:Vectors To VRML Events - (3) More detailed
Direction vectors and rotations are something
fundementally different.

The best we can do is calculate a rotation
that 'rotates' a predefined 'defaultDirection'
in such a way that it is the same as our
intended 'direction'.
:Vectors To VRML Events - (4) Why do we ned 'up' ?
The notion of 'up' is needed because
there is one more degree of freedom to
tame, the 'ROLL' (U.S. Mill. term).


Transform { rotation 0 0 1 -1.57 children [ DEF ROLL_TRANS Transform { children [ Transform { translation 0 1 0 children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 } } geometry Cone {} } ] } Transform { translation 0 -1.5 0 children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 } } geometry Cylinder { height 3 radius 0.5 } } ] } Transform { translation 0.75 -1.5 0 children [ Shape { appearance Appearance { material Material { diffuseColor 1 1 1 } } geometry Box { size 0.5 3 0.5 } } ] } ] } ] } DEF ROLL_TIMER TimeSensor { loop TRUE } DEF ROLL_INTER OrientationInterpolator { key [ 0 0.5 1.0 ] keyValue [ 0 1 0 0, 0 1 0 3.14, 0 1 0 6.28] } ROUTE ROLL_TIMER.fraction_changed TO ROLL_INTER.set_fraction ROUTE ROLL_INTER.value_changed TO ROLL_TRANS.set_rotation :Vectors To VRML Events - (5) Some Code
// Rotation from 'def' to 'direction' rotA = new SFRotation(defDirection,direction); // Adjust 'up' vector, defUp = yAxis up = rotA.multVec(yAxis); // Fix orientation with respect to 'up' rotB = new SFRotation(direction.cross(up), direction.cross(yAxis)); // Combine both orientation = rotA.multiply(rotB); :Finally Let's wrap up...


Any Questions ?