This is primarily for Jess and Noah.
All variables in TorqueScript are represented by strings, which means
every time you do floating point calculations there's a string->float-
>string conversion, introducing small errors. With enough
calculations, the errors become rather large.
So, I developed an extension to TorqueScript which introduces two new
classes. mexFloat and mexVector. mexFloat is used for floating point
calculations. mexVector is used for vector calculations. They both
store their values internally, on the C++ side, so there are no string-
>float->string conversions when doing math with them.
Here are the files:
http://www.progranism.com/junk/TorqueMathEx/mexfloat.h http://www.progranism.com/junk/TorqueMathEx/mexfloat.cc http://www.progranism.com/junk/TorqueMathEx/mexvector.cc Those simply need to be included in the project and the project re-
built. Or you can just download my EXE:
http://www.progranism.com/junk/TorqueMathEx/torqueDemo.exe
Usage is pretty simple. Just be careful around the constructors and
set functions. Some take strings, some take mexFloat, and some take
TorqueScript string/numerical values.
Example:
%a = new mexVector(0, 0, 1);
%ap = new mexVector(1, 3.9, 5.8);
%a = %a.normalize();
%ap = %ap.normalize();
%vec = %a.cross(%ap);
%theta = %a.dot(%ap).acos();
%rotation = %vec.getValue() SPC %theta.getValue();
/////////////////////////////////
echo(new mexFloat(2).add(new mexFloat(3)).divide(new
mexFloat(42)).getValue()); // 0.11904761904761904761904761904762
///////////////////////////////////
new mexVector().setValue(new mexFloat(5), new mexFloat(2), new
mexFloat(8));
Jess: I'll send you a copy of the spawnRail function that uses the
Math Extension. I hope it helps! My few tests show the Math extension
to be more accurate. Not by a whole lot, but hopefully it's enough to
get those rails on spot.