Java represents pixel color (alpha, red, green and blue) using a large int in the form 0xAARRGGBB. In the previous versions, I extracted color information like this in Java:
CODE
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
These integers had a range of 0 to 255. I then made it construct a quaternion of these values and send it over the xml-rpc connection. Eggy turned me on to the idea of sending the pure int (named "pixel" in the above code) and doing the conversion at the LSL end of the connection, to reduce the overhead of sending seperate values and the rotation syntax characters ('<', ',' etc). The system converted over quite readily. I made it scalable in the previous few updates, so it was pretty much a breeze.
The only problems I'm having are converting this color int into a rotation in LSL. I believe to have successfully duplicated the bit-shift right operator ('>>'), but for some reason its still not working like I expect it to.
Here's the code I'm using:
CODE
integer bitShiftRight(integer bitField, integer places) {
return (integer) (bitField / llPow(2, places));
}
rotation int2AppearenceRot(integer int) {
integer alpha = bitShiftRight(int, 24) & 255;
integer red = bitShiftRight(int, 16) & 255;
integer green = bitShiftRight(int, 8) & 255;
integer blue = int & 255;
// Scale the integers from a range of 0 to 255 to a range from 0.0 to 1.0
rotation ret;
ret.x = (float) red / 255.0;
ret.y = (float) green / 255.0;
ret.z = (float) blue / 255.0;
// I used the following code to kludge together protection from
// Image anomolies on the Java-end. (sometimes it sent -1 as alpha)
if (alpha > 0) {
ret.s = (float) alpha / 255.0;
} else {
ret.s = llFabs(alpha);
}
return ret;
}
setAppearence(integer appearence, integer side) {
rotation appearence = int2AppearenceRot(appearence);
vector color = <appearence.x, appearence.y, appearence.z>;
float alpha = appearence.s;
llSetPrimitiveParams([PRIM_COLOR, side, color, alpha]);
llSetTexture(BLANK_TEXTURE, side);
}
Please help

==Chris
EDIT: Grammatical correction.