in reply to Perl and Quaternions
G'day Fair Strides,
Some sample input data, actual results and expected results would have helped. A short script that reproduced your problem would have helped even more: we could have run it, tweaked it and suggested modifications. The guidelines in "How do I post a question effectively?" explain how to do this.
"Here's the code I have for reading the info from a hash-of-hashes ..."
As I already alluded to, you provide no indication of the structure of this "hash-of-hashes" nor what data populates it. In the code, you have variables with no indication of how they were declared or what values they might hold. In order to troubleshoot this, we'd need to make many guesses regarding data, context and the value of variables: guessing is not a good way to proceed.
"and the code that takes the measure of degrees ..."
Much the same comments apply here also. It looks like Tk code but you don't specify this. It contains non-essential, distracting clutter like font families and sizes; but important information, such as variable declarations, is missing.
Here's a few comments on what you have provided:
See also: Math::Trig (for pi constants and functions such as deg2rad); Math::Quaternion (for the creation and manipulation of quaternions); SecondLife::Rotation (for an example of how to subclass Math::Quaternion, should you need that).
"The game has a built-in scripting language, ..."
[The following (in the spoiler) has nothing at all to do with Perl; it's about NWScript. Of interest to the OP, but of little or no interest to others.]
Firstly, the code you posted looks like NWScript (again, something else unspecified). I'm assuming you're writing a mod for one of BioWare's "Stars Wars" titles. If this is a wrong assumption, don't bother reading any more.
[Disclaimer: While I know about NWScript, I've never played, or written mods for, any of BioWare's "Stars Wars" titles.]
This is incorrect syntax:
float fOrient = GetFacing( GetFirstPC() -90.0 );
This is correct syntax; although, I don't think it's doing what you want:
float fOrient = GetFacing( GetFirstPC() ) - 90.0;
In-game orientation starts at zero for East and moves anticlockwise: E=0; N=90; W=180; S=270.
Normal compass orientation starts at zero for North and moves clockwise: N=0; E=90; S=180; W=270.
Therefore, I believe you want logic more like this Perl code:
my %game = qw{E 0.0 N 90.0 W 180.0 S 270.0}; for (qw{N E S W}) { my $real = (360 + 90 - $game{$_}) % 360; printf "game: %s = %5.1f; real: %5.1f\n" => $_, $game{$_}, $real; }
Output:
game: N = 90.0; real: 0.0 game: E = 0.0; real: 90.0 game: S = 270.0; real: 180.0 game: W = 180.0; real: 270.0
However, NWScript only allows integers as operands for its modulo (%) operator, so you'll need to do some casting like this:
float fOrient = IntToFloat( (360 + 90 - FloatToInt(GetFacing(GetFirstPC()))) % 360 );
Note that GetFacing() returns a floating point number BUT it's rounded to the nearest whole degree. This has two implications:
The reference I used for the above information can be downloaded from NWN Lexicon v1.69.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl and Quaternions
by Fair Strides (Acolyte) on May 08, 2014 at 13:39 UTC | |
by kcott (Archbishop) on May 09, 2014 at 03:54 UTC |