User:Jack Abraham
Revision as of 22:14, 6 July 2010 by Jack Abraham (talk | contribs)
Lantern by day, filler of blank (personal) pages.
Code Snippets
What am I looking at?
A function I just threw in to replace phantom bullets for quickly acquiring a point of interest -- whatever your camera's focused on (in this sim, within 20m) is returned, allowing quicker, more intuitive targeting of other objects. PERMISSION_TRACK_CAMERA must be previously set. Requires llCastRay.
<lsl>key camPing() {
// End points at the camera and 20m in front of it vector camPos = llGetCameraPos(); // Clamp the end position to within the sim // From an SLUniverse post by Chalice Yao // http://www.sluniverse.com/php/vb/scripting/46344-llcastray-available-testing-maybe-only.html#post969497 float xSteps; float ySteps; vector camRot = llRot2Fwd(llGetCameraRot()); fXSteps = llAbs( ( 256.0 * !!camRot.x ) - camPos.x ) / camRot.x; fYSteps = llAbs( ( 256.0 * !!camRot.y ) - camPos.y ) / camRot.y; if(xSteps > ySteps) xSteps = ySteps; if ( xSteps > 20.0 ) xSteps = 20.0
// Cast the ray; ignore hits on land, otherwise get the root key list contacts = llCastRay( camPos, camPos + ( camRot * xSteps ), RC_REJECT_LAND, RC_GET_ROOT_KEY );
// Return values if ( llList2Integer( contacts, -1 ) > 0 ) { // Got a return return llList2Key( contacts, 0 ); } return NULL_KEY;
} </lsl>