I would be interested in a good example of llDetectedGrab for something like this as well.
I got this to work on a single cylinder as a dial. But the only way I could get llDetectedGrab to work like this on an object was to turn physics on.
Then I can no longer make the "dial" turn independently if I try to link or joint it to a panel. With a link, it starts rotating the whole panel, not just the dial. And I could never get the joint to allow the dial to turn independently on its local z-axis.
And of course, even if I could get the dial to rotate on a joint hinge, I could not use that object as an attached HUD (can't use joints on an attatchement I guess).
So Question one:
Do I really need physics turned on in the object that is to be the dial (ie something that can be "turned" by llDetectedGrab)?
Is there a way to put a bunch of these dials onto a linked object so it can become a HUD attachement?
I also would appreciate any feedback on the code as to how I could do something better or if I am doing something silly. Its my first LSL program!
Here's the code I tried:
default
{
state_entry()
{
// Could not get it to work at all without Physics on
llSetStatus(STATUS_PHYSICS, TRUE);
llWhisper(0, "Knob Activated");
// Get and display the current z rotation as an integer
// Get the current rotation of the Knob and convert to vector
vector curEul = llRot2Euler(llGetLocalRot()) * RAD_TO_DEG;
// Only care about the Z axis
integer curVal = llRound(curEul.z);
// For some reason the result of hte llGetLocalRot and the conversion
// End up with a range of 0 to 180 then -180 to -1
// So have to convert to 0 - 360 range
if (curVal < 0)
{
curVal += 360;
}
// Display the current z value as hover text
llSetText((string)curVal,<0,1,0>,1);
}
touch(integer total_number)
{
// Get the value of the detected grab when touched
// Probably should filter touches just for grabs
vector grabVec = llDetectedGrab(0);
// The value of the llDetected grab is usually less than 1
// and I just need something to act as an increment / decrement value
integer incVal = llRound(grabVec.x * 10);
// Get the current rotation
vector curEul = llRot2Euler(llGetLocalRot()) * RAD_TO_DEG;
// Convert to range of 0 - 360
if (curEul.z < 0)
{
curEul.z += 360;
}
// Increment or dectrement the z axis value
vector newEul = curEul + <0, 0, incVal>;
// Convert it to an integer for display/use
integer curVal = llRound(newEul.z);
if (curVal < 0)
{
curVal = 0;
newEul.z = 0;
}
if (curVal >= 360)
{
curVal = 360;
newEul.z = 359.9;
}
// Set the new position
llSetLocalRot(llEuler2Rot(newEul * DEG_TO_RAD));
// Update the hover text
llSetText((string)curVal,<0,1,0>,1);
}
}