topical media & game development
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:
- 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:
try keyboard.wrl
to check your keycodes
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:
Example 2
(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.