JavaScript does not support call-by-reference type of function parameters for basic types. Correspondingly, Realsoft 3D methods returning data back to the caller through the method parameters won't work. To overcome this limitation Realsoft 3D implements r3Float object type.
For example, the r3nurbs curve class implements method MEASURELENGTH(len), which returns the lenght of the curve through the function parameter 'len'. This would not be possible using JavaScript basic types:
// wont't work var len; curve.MEASURELENGHT(len);
because JavaScript basic types are passed to function as call-by-value parameters. To allow the MEASURELENGHT() method to actually change the value of the 'len' parameter, call-by-reference is required.
// this works var len = new r3Float(); curve.MEASURELENGHT(len);
r3Float - constructor for float
v = new r3Float()
value - floating point number
v - new float object
Creates a new float object. If you don't pass any parameters to the constructor, the value is initialized to zero.
v = new r3Float(10);
add - addition
v2 = v.add(v1);
v1 - float
v2 = result float
This adds the given float to the object in question and returns the result as a new float. The operation doesn't change the value of the object.
v = new r3Float(0.1); r = v.add(0.1);
fadd - float addition
v.fadd(v2);
v2 - float to be added
-
Float operation v = v+v2.
v = new r3Float(1); v.fadd(0.1); // add 0.1 to the current value
set - set value
v.set(value);
value - floating point number
-
Set new value to the float
v = new r3Float(); v.set(10.3);
sub - float subtraction
v3 = v.sub(v2);
v2 - float to be subracted
float - the result of the subtraction
Returns a new float containing the result of float operation 'v - v2'.
v = new r3Float(10); v2 = v.sub(5); v2.print(); // 5
fsub - float subtraction
v.fsub(v2);
v2 - float to be subracted
-
Subtracts given float 'v2' from the float in question.
v = new r3Float(1); v.fsub(0.5); v.print(); // 0.5
neg - negate
v2 = v.neg();
-
v2 - float
Returns negative value of the object.
v = new r3Float(1); v2 = v.neg();
fneg - negative
v.neg();
-
-
Makes the float negative float.
v = new r3Float(1); v.fneg(); v.print(); // -1
mul - multiplication
v2 = v.mul(f);
f - float number
v2 - result
Multiplies the float with the given value and returns the value.
v = new r3Float(2); v2 = v.mul(10); v2.print(); // 20
fmul - multiplication
v.fmul(f);
f - floating point number
-
Multiplies the float by given value
v = new r3Float(2); v.fmul(10); // new value == 20
div - division by scalar
v2 = v.div(f);
f - floating point number
v2 - float
Divides the float by given value and returns a new float holding the result.
v = new r3Float(10); v2 = v.div(2); v2.print(); // 5
fdiv - division by scalar
v.fdiv(f);
f - floating point number
-
Divides the float by given value.
v = new r3Float(1); v.fdiv(2); // 0.5
cmul
v3 = v.cmul(v2);
v2 - float
v3 - float
Component wise multiplication. Multiplies each component in 'v' by corresponding component of 'v2' and returns the result as a new float.
v = new r3Vect(1, 2, 3);
cmp - compare
b = v.cmp(v2, tolerance);
v2 - float
tolerance - tolerance
b - boolean, true if floats are identical within the given tolerance
Compare the given float 'v2' agains the float in question and return true if the floats are within the given tolerance. Otherwise returns false.
v = new r3Vect(1.1);
if(v.cmp(1.2, 0.01)) {
print("Not identical");
} else {
print("Identical");
}
print - print float
v.print()
-
-
Print out the current value of the float.
v.set(1.5); v.print();