Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llDetectedGrab() Example

Al Bravo
Retired
Join date: 29 Jun 2004
Posts: 373
11-02-2004 11:41
I am trying to make a control panel for a device. One of the things I would like to make is a slider for a value to go between 1000 & 4000 very quickly. I assume llDetectedGrab() is the function to make this happen. But, I can't seem to grasp this one. Anyone have a little snippet showing how/when/what this function returns?
Zar Zadoq
Learning the Second Life
Join date: 8 Nov 2004
Posts: 21
12-03-2005 23:27
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:

CODE
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);
}
}
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
12-04-2005 01:01
I can't get in world atm, but from what I remember I think its relative to the local axis of the object not sure though.

A quick sample to debug would go something like this...

CODE
default
{
touch(integer total_number)
{
if(llDetectedGrab(0) != ZERO_VECTOR)
{
llSay(0, (string)llDetectedGrab(0));
}
}
}
_____________________