Difference between revisions of "User:Dzonatas Sol/HttpCastRayLLSD"

From Second Life Wiki
Jump to: navigation, search
m
 
Line 1: Line 1:
This code does the very basic functionality to process casted rays by a query and to return the result as LLSD. This doesn't represent ideal functionality. It just allows us to research this basic functionality for potential optimization. It's not to be used to implement a full ray-tracer even if it is possible. It is meant to detect an object and use smart methods to not cast rays again through the area of that object. For now, we just use the bouding-box as the default area. It would be more ideal if there was an easier way to detect static objects, yet we could compare return values to detect any changes in the scene. Maybe if there was an extra filter to llCastRay that only returned static objects, like if it tested the object is "locked" in position.
+
This code does the very basic functionality to process casted rays by a query and to return the result as LLSD. This doesn't represent ideal functionality. It just allows us to research this basic functionality for potential optimization. It's not to be used to implement a full ray-tracer even if it is possible. It is meant to detect an object and use smart methods to not cast rays again through the area of that object. For now, we just use the bounding-box as the default area. Maybe if there was an extra filter to llCastRay that only returned static objects...
  
 
<lsl>
 
<lsl>

Latest revision as of 14:01, 1 August 2010

This code does the very basic functionality to process casted rays by a query and to return the result as LLSD. This doesn't represent ideal functionality. It just allows us to research this basic functionality for potential optimization. It's not to be used to implement a full ray-tracer even if it is possible. It is meant to detect an object and use smart methods to not cast rays again through the area of that object. For now, we just use the bounding-box as the default area. Maybe if there was an extra filter to llCastRay that only returned static objects...

<lsl> default {

   state_entry()
   {
       llSay(0, "Rebooted.");
       llRequestURL();
   }

   http_request(key id, string method, string body)
   {
       if (method == URL_REQUEST_GRANTED)
       {
           llSay(0,"URL: " + body);
       }
       else if (method == URL_REQUEST_DENIED)
       {
           llSay(0, "Something went wrong, no url. " + body);
       }
       else if (method == "GET")
       {
           string  query      = llGetHTTPHeader(id, "x-query-string"); 
           list    qvar       = llParseString2List(query, ["filter=", "&sx=", "&sy=","&sz=","&ex=", "&ey=","&ez="], [""]);
           integer filter     = (integer)llList2String(qvar, 0);
           float   x          = (float)llList2String(qvar, 1);
           float   y          = (float)llList2String(qvar, 2);
           float   z          = (float)llList2String(qvar, 3);
           vector start       = <x,y,z> ;
           x                  = (float)llList2String(qvar, 4);
           y                  = (float)llList2String(qvar, 5);
           z                  = (float)llList2String(qvar, 6);
           vector end         = <x,y,z> ;
           llSay(0, (string)start + " " + (string)end) ;
           list     results = llCastRay( start, end, filter, 0 ) ;
           key      uuid    = llList2Key(results, 0);
           string   vec     = llList2String(results, 1);
           list     box    = llGetBoundingBox(uuid);
           vector   center = (llList2Vector(box, 0) + llList2Vector(box, 1)) * 0.5;
           vector   size   = llList2Vector(box, 1) - llList2Vector(box, 0);
           
           string text ;
           text += "<llsd><map>" ;
           text += "<key>ID</key>" ;
           text += "<string>" + (string)uuid  + "<string>" ;
           text += "<key>Point</key>" ;
           text += "<string>" + (string)vec    + "<string>" ;
           text += "<key>Center</key>" ;
           text += "<string>" + (string)center + "<string>" ;
           text += "<key>Size</key>" ;
           text += "<string>" + (string)size   + "<string>" ;
           text += "</map></llsd>" ;
           llHTTPResponse(id,200, text );
       }
       else
       {
           llHTTPResponse(id,405,"Unsupported Method");
       }
   }

} </lsl>