User:Opensource Obscure/Reflexive llSetLinkPrimitiveParamsFast
< User:Opensource Obscure
Jump to navigation
Jump to search
Revision as of 14:20, 14 March 2010 by Opensource Obscure (talk | contribs) (Created page with '* this needs server 1.38 * put it in the root prim * add child prims to the linkset as needed <lsl> float rate = 0.1; vector NEAR_COL = <1.0, 1.0, 0.0>; vector FAR_COL = <0....')
- this needs server 1.38
- put it in the root prim
- add child prims to the linkset as needed
<lsl>
float rate = 0.1;
vector NEAR_COL = <1.0, 1.0, 0.0>; vector FAR_COL = <0.2, 0.0, 0.5>;
float distance_moltiplier = 0.1; // x alpha
vector NEAR_SIZE = <1, 2, 4.0>; vector FAR_SIZE = <0.5, .5, 10>;
float NEAR = 5.0; float FAR = 20.0;
//------- don't change below
float DIFF; vector COL_DIFF; vector SIZE_DIFF; vector pos_init; rotation rot_init; integer prim_number;
vector GetLinkLocalPos(integer link) {//This function may not produce a perfect result, expect there to be some drift. This will not work in attachments.
//vector pos = llGetRootPosition(); return (llList2Vector(llGetObjectDetails(llGetLinkKey(link), (list)OBJECT_POS) + pos_init, 0) - pos_init) / rot_init;
}
default {
state_entry() { pos_init = llGetPos(); rot_init = llGetRootRotation(); prim_number = llGetObjectPrimCount( llGetKey() ); DIFF = FAR - NEAR; COL_DIFF = FAR_COL - NEAR_COL; SIZE_DIFF = FAR_SIZE - NEAR_SIZE; llSensorRepeat("", NULL_KEY, AGENT, FAR, PI, rate); } sensor(integer total_number) { vector pos_det = llDetectedPos(0); integer i; for(i=1; i<=prim_number; ++i) { vector pos_local = (pos_init + GetLinkLocalPos(i)); float distance_local = llVecMag(pos_det - pos_local); float scale_local = (distance_local - NEAR) / (DIFF); if (scale_local < 0.0) scale_local = 0.0; llSetLinkPrimitiveParamsFast(i, [ PRIM_COLOR, ALL_SIDES, NEAR_COL + ((COL_DIFF) * scale_local), 1, // distance_local*distance_moltiplier, PRIM_SIZE, NEAR_SIZE + ((SIZE_DIFF) * scale_local) ]); } }
} </lsl>