Jump to content

How can I reverse this function?


Life Camino
 Share

You are about to reply to a thread that has been inactive for 3489 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I found this function that takes the start parameter from the on_rez event and converts it into a color vector, and I would like to know how I might do the reverse by converting a color vector into an integer that would work with this function?

 

vector RGBAtoColor(integer rgba)
{
    return < ((rgba >> 16) & 0xFF) / 255.0, ((rgba >> 8) & 0xFF) / 255.0, (rgba & 0xFF) / 255.0 >;
}

 

I'm not quite sure what is happening here.  I see that it is deriving a vector from the integer sent to the function, but how is it splitting up the integer to create the vector?  Being able to send a color vector to a rezzed object in this fashion would be great.  But, understanding how it works would be even better.  So, any help would be greatly appreciated.

Link to comment
Share on other sites

You are looking for Void Singer's last thread in these forums:

http://community.secondlife.com/t5/LSL-Scripting/Finity-s-End/m-p/1254183

In it, you will find both of the code snippets (uColor2Integer and uInteger2Color ) you are looking for.  Basically, all uColor2Integer is doing is grabbing the three components of the vector and assigning them to separate parts of hex integer, moving the Y to the left 8 digits and Z to the left 16 digits.  To decode the integer, she just reverses the process in uInteger2Color, grabbing the high bits of the hex integer and converting them to Z, the mid-level bits to Y and the low-bits to X.

 ETA: The particular function that you are looking at does one further step, converting a standard RGB color vector (<255.0,255.0,255.0>) to a normalized LSL color vector (<1.0,1.0,1.0>).  That's just arithmetic, dividing or multiplying by 255 as needed.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3489 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...