JavaScript
BentDalgaard
Larsen
Overview
• SimpleJavaScript
syntax
• Different
waysto
accesstheVRML
scene
• Importantobjects
Syntax - 1
• Verymuchlike C/C++/Java
• Noneedtodefine
variables
– Although
thespecificationsaysthat var should
buesed
• Types
– Numbers(integers,float),
booleans,
strings,objects,
null,undefined
• Automatic
conversion
– A=”a”
+9=
”a9”
Syntax - 2
• Arithmetic
– + * / % ++ -- -
• Comparison
– == != > >= < <=
• Boolean
– && || !
• Strings
– ’hello’ + ’world’
Syntax - 3
if (condition) { statements; }else{ statements;}
switch (expression) {
case ’label’:
statement;
break;
default:
statements;
}
for (initial-statement;test;increment)
{statements}
Syntax - 4
do {
statements;
} while (condition);
while (condition) {
statements;
}
Canbceombinedwith:
break;
continue;
Syntax - 5
for (variable in object) {
statements;
}
with (object) {
statements;
}
Comments:
// comment type 1
/* comment type 2 */
AccessingVRML
scene -1
DEF MyTrans Transform { ... }
DEF MyScript Script {
eventIn SFVec3f incoming
eventOut SFVec3f outgoing
url [’javascript:
function incoming(value) {
outgoing =value;
}’]}
ROUTE [Link] TO [Link]
AccessingVRML
scene -2
DEF MyTrans Transform { ... }
DEF MyScript Script {
field SFNode MT USE MyTrans
EventIn SFVec3f incoming
url [’javascript:
function incoming(value) {
MT.set_translation = value
}’]}
The
Browser
Object
[Link](’Hello world’)
[Link](’Hello world’)
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
new_f = [Link]( str_f );
[Link] = new_f;
[Link]();
[Link]();
Objects
• SFVec3f,
SFColor
etc.
arejust
objects
variable = new SFVec3f();
variable = new SFVec3f(1,2,3);
Variable[0]=9; Variable[1]=5; Variable[2]=0;
The
Math
Object
• [Link]
– sin
– floor
– cos
• Workslike
normalJavaScript
Wanna
knowmore?
• Searchthenet!