: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 ?
Normal Text generates complex geometry
Limited in supported font-types
Example:
:Blaxxun Extentions - Texture Text (2)
: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:
TimeSensor sends SFTime events
Script compensates for correct speed
'Update' the world-state
: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
Object treated as point-mass and
has a Location
has an Orientation
has a Speed (in a certain direction)
can Accelerate (in a certain direction)
: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:
:Movement Vectors - Down To Earth (1)
Simple 'Racing' Physics
Gives a more realistic feeling
Turning changes direction of motion
Still has location, direction and speed
However, orientation == direction of motion
: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:
:Vectors To VRML Events - (1)
What is the problem ?
Position is a SFVec3f field
OK for 'translation' field in 'Transform'
Or 'position' field of a 'Viewpoint'
Direction is a SFVec3f field
Orientations are SFRotation in VRML !
Need to construct a rotation
:Vectors To VRML Events - (2)
Translating direction to rotation
Eh !?, This cannot be done !
Fundementally something different !
Need a 'defaultDirection' + 'rotation'
Rotate 'defaultDirection' to 'direction'
Now still infinite answers
A notion what is 'up' needed
: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).
: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...