Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HUD Compass...

Miles05 Reitveld
Kitsune Mage
Join date: 24 Apr 2005
Posts: 28
01-29-2006 11:07
Hi there. After many tries, I have failed in trying to get a HUD compass to work for me. How would one go about doing so? I know little about rotations, and if anyone has an example I could use, please share! (I'll be on for several more hours) Thanks in advance. :)
Kage Seraph
I Dig Giant Mecha
Join date: 3 Nov 2004
Posts: 513
01-29-2006 16:34
Here's what I use for a text-based compass:

adapted from a compass script elsewhere in the library

CODE
integer horizonOn ;
integer resolutionFactor = 15;//to calibrate multiplicatively
integer fudgeFactor = 0;//to calibrate additively

default
{
state_entry()
{
llSetTimerEvent(0.5);
}

touch_start(integer total_number)
{
if(horizonOn)
{
horizonOn = FALSE;
llSetTimerEvent(0);
llSetText("",<1,1,1>,0);
}
else
{
horizonOn = TRUE;
llSetTimerEvent(0.5);
}
}

timer()
{
//adapted from the flying tako
//and http://forums.secondlife.com/showthread.php?t=28047
rotation currRot=llGetRot();
vector currEuler=llRot2Euler(currRot);
float zRotAngle=currEuler.z;//boat heading
float heading=PI_BY_TWO-zRotAngle;
while (heading<0) heading+=TWO_PI;
heading=heading*RAD_TO_DEG;
integer evenHeading = llRound(heading + fudgeFactor);
string direction; // this is the variable we will set the text with
vector vel = llRot2Fwd(currRot);// get the current velocity
integer x = llRound(vel.x); // round the x value of the velocity and assign it to a new variable
integer y = llRound(vel.y); // round the y value of the velocity and assign it to a new variable
if((llAbs(x) > llAbs(y)) && (x > 0))
{
direction="East";
}
else if((llAbs(x) > llAbs(y)) && (x < 0))
{

direction = "West";
}
else if((llAbs(y) > llAbs(x)) && (y > 0))
{

direction = "North";
}
else if((llAbs(y) > llAbs(x)) && (y < 0))
{

direction = "South";
}
else if((llAbs(y) == llAbs(x)) && (x > 0 && y > 0))
{

direction = "Northeast";
}
else if((llAbs(y) == llAbs(x)) && (x < 0 && y > 0))
{

direction = "Northwest";
}
else if((llAbs(y) == llAbs(x)) && (x < 0 && y < 0))
{

direction = "Southwest";
}
else if((llAbs(y) == llAbs(x)) && (x > 0 && y < 0))
{

direction = "Southeast";
}
string readout = direction+"\n("+(string)evenHeading+" deg.)";
llSetText(readout,<1,1,1>,1);
}


link_message(integer sender_num, integer num, string message, key id)
{
if(message == "hide compass")
{
state dormant;
}
string part1 = llList2String(llParseString2List(message, [","], []),0);
string part2 = llList2String(llParseString2List(message, [","], []),1);
if( part1 == "face" && part2 == "default")
{
llSetText("",<1,1,1>,1);
}
else if( part1 == "face" && part2 != "default")
{
llSetText("",<1,1,1>,1);
}
}

state_exit()
{
llSetTimerEvent(0.0);
llSetText("",<1,1,1>,1);
}
}

state dormant
{
state_entry()
{
llSetText("",<1,1,1>,1);
}

link_message(integer sender_num, integer num, string message, key id)
{
if(message == "show compass")
{
state default;
}
}
}