Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
117 views

Javascript: Bent Dalgaard Larsen

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)
Available Formats
Download as PS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Javascript: Bent Dalgaard Larsen

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)
Available Formats
Download as PS, PDF, TXT or read online on Scribd
You are on page 1/ 13

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 MyScript.outgoing TO MyTrans.Transform


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
Browser.setDescription(’Hello world’)
Browser.print(’Hello world’)

Browser.getName();
Browser.getVersion();
Browser.getCurrentSpeed();
Browser.getCurrentFrameRate();
Browser.getWorldURL();

new_f = Browser.createVrmlFromString( str_f );


ROOT.addChildren = new_f;
Browser.addRoute();
Browser.deleteRoute();
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
• E.g.Math
– sin
– floor
– cos
• Workslike
normalJavaScript
Wanna
knowmore?
• Searchthenet!

You might also like