Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help With A Math Rotation Problem

Infrared Wind
Gridologist
Join date: 7 Jan 2007
Posts: 662
08-09-2007 22:47
Hi -

If anyone can help with this math rotation problem it would be great.

Here's the problem:

I'm making a humidity gauge with a rotating arrow based on RL weather
numbers. Using llHTTPRequest/http_response I assign a float number
to a variable, for example: "34.4".

The dial graphic background was created in a graphics program, so the
ticks are not perfect, but they're essentially 2.7 degrees apart around
the dial. .

To point at O% humidity on the dial the arrow (a stretched cube) is
turned 231 degrees on the Y axes. To point at 100% humidity the arrow is
turned to 140 degrees on the Y axes. 50% is at 4 degrees on the Y axes.

So the way I've got it working so far is this:

I assign the http_response to a var:

float n1 = (integer)n;

Then I have a long list of if clauses, which I've only bothered
to assign whole numbers so far:

if(n1 == 0) n1 = 231.0;
if(n1 == 2) n1 = 236.4;
if(n1 == 3) n1 = 239.1;
if(n1 == 4) n1 = 241.8;

...etc...

if(n1 == 97) n1 = 130.9;
if(n1 == 98) n1 = 133.6;
if(n1 == 99) n1 = 136.3;

...etc...

And then...

rotation hand_rot = llEuler2Rot(<1 * n1 * DEG_TO_RAD, 0, 0>;);

This works...but there must be a better way; a way to derive the range of
SL Y axes degrees from the float numbers mathematically instead of
foolishly with a calculator manually as I have done.

Well...if anyone knows what the hell I'm talking about and can
offer some light...I'd be stoked!

- Infrared
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
08-10-2007 02:28
Try:
CODE

//humidity should be in the range [0.0, 100.0]
rotation hand_rot = llEuler2Rot(<(231.0 + humidity * 0.027) * DEG_TO_RAD, 0, 0>);
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Infrared Wind
Gridologist
Join date: 7 Jan 2007
Posts: 662
08-10-2007 03:14
From: Strife Onizuka
Try:
CODE

//humidity should be in the range [0.0, 100.0]
rotation hand_rot = llEuler2Rot(<(231.0 + humidity * 0.027) * DEG_TO_RAD, 0, 0>);


Whoa...you're the man! =)

That's exactly what I was looking for. I just needed a bit of direction.
After playing I found this to do what I wanted:

rotation hand_rot = llEuler2Rot(<1 * (230.0 + humidity * 2.72) * DEG_TO_RAD, 0, 0>;);

SWEET...thank you, Strife. I'm stoked!

- Infrared