0% found this document useful (0 votes)
128 views13 pages

JavaScript Syntax and VRML Access Guide

JavaScript provides a simple syntax similar to C/C++/Java for accessing and manipulating VRML scenes. It allows defining variables, arithmetic, comparisons, conditionals like if/else and switch statements, loops like for and while, and comments. Important objects include SFVec3f for vectors and Browser for interacting with the VRML world. The Math object provides common mathematical functions.

Uploaded by

postscript
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views13 pages

JavaScript Syntax and VRML Access Guide

JavaScript provides a simple syntax similar to C/C++/Java for accessing and manipulating VRML scenes. It allows defining variables, arithmetic, comparisons, conditionals like if/else and switch statements, loops like for and while, and comments. Important objects include SFVec3f for vectors and Browser for interacting with the VRML world. The Math object provides common mathematical functions.

Uploaded by

postscript
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PS, PDF, TXT or read online on Scribd

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!

You might also like