JanusVR Documentation
[BUILD] Javascript: Vector Functions & Misc.
There are several built-in functions that allow you to operate on room elements' attributes.
There are several built-in functions that allow you to operate on room elements' attributes.
• Vector(x, y, z) - Can be used either as a regular function or as a constructor. If no arguments are supplied, will create zero vector. If a single number is supplied, will create a vector with all of its components initialized to that number. Supplying an object will create a vector from its x y and z properties, essentially cloning the existing vector.
• translate(v1, v2) - Returns a new vector that is the result of adding the v1 and v2 vectors together.
• scalarMultiply(v1, n or v2) - Returns a new vector that is the result of scalar multiplying v1 with the second argument. If the second argument is a number n, then the result is a vector with components (x1 * n, y1 * n, z1 * n). If the second argument is a vector with components (x2, y2, z2), then the result is a vector with components (x1 * x2, y1 * y2, z1 * z2).
• cross(v1, v2) - Returns the cross product of v1 and v2.
• normalized(v) - Returns a normalized version of the given vector.
• distance(p1, p2) - Returns the distance between the two given points(vectors).
• equals(v1, v2) - Returns whether v1 and v2 have the same x,y,z values (introduced in 34.11, note that the == operator will instead compare memory locations, rather than compare the x,y,z components)
• copy( {v1,v2} or {v1,x} or {v1,x,y,z} ) - Copies the x y & z values of v2 (a vector) into v1 (also a vector). If a single number is provided as the second argument (x), this number will be assigned to all three x y & z values of v1. If three individual numbers are provided as the second, third and fourth arguments (x,y,z) they will be assigned to v1's x y & z values. Returns v1.
• scale(v1, s) - Scales the x, y, and z values of v1 by the number s. Returns v1.
• add(v1, v2) - Adds each of the x, y, and z values of v1 and v2. Returns v1.
• XMLHttpRequest.addEventListener(event, function) - Attaches an event handler to the specified node. Currently only supported event is "load".
• XMLHttpRequest.removeEventListener(event, function) - Removes an event handler from the specified node.
• XMLHttpRequest.open(method, url) - Specifies the type of request for an XMLHttpRequest. Takes either "GET" or "POST" as the first argument.
• XMLHttpRequest.send([data]) - Executes the request defined by the open function. The [data] parameter is optional and consists of a string of information that you would like to be sent along with the request.
• XMLHttpRequest.responseText - A property that returns a string containing a response to an XMLHttpRequest. Returns null if the request was unsuccessful or has not yet been sent.
• removeKey(dictionary, key) - Removes a key-value pair from the given dictionary by key.
• print(value) - Prints the value to the chat log and debugger output.
• debug(value) - Logs the given value in the debugger output and returns it. Useful for examinining results of expressions without having to abstract them into a variable and print them.
• uniqueId() - returns a unique number that you can use, say in specifying the js_id of a new object.