Basic javascript in VRML (part 3)

Introduction

This tutorial page explains basic vrmlscript in particular directOutput and array access methods.

Functions

Functions are included in javascript which are used much like normal definied functions. First we look at the Math.xxx series of functions. They are generally used in the form of a=Math.xxx(x); Also normal functions can be made to return values in the same way

.xxx function usage
.length Returns the number of values in a field. For MFXXX fields this is the number of entries, for SFXXX fields this is the number of values

Vector functions and SFVec2f SFVec3f

A vector is a field which represents line in 2D or 3D space.
Basically the coordinates of one point minus a second point.

Some of these functions are also used for general mathematical purposes.

.xxx function usage
.multiply(x) Multiply x by the field values.
.divide(x) Divide the field values by x.
.add(x) Add x to the field values
.subtract(x) Subtract x by the field values.
.dot(x) Get the dot product of the field values and x.
.cross(x) Get the cross product of the field value and x
.normalize() Returns the normalized value of the field.
.negate() Returns the negative value of the field.
.length() Returns the length of a vector.

Examples

Notes