Advertisement
Guest User

CastRay() LInden Lab Jira report

a guest
Aug 12th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //(c)2018 Denise. Virtual Kitten
  2. // if you use this code please leave it unchanged do not sell or make any product relying on this code.
  3.  
  4. float GetBoundaryUsingCastRay(string raytype, float width){
  5.      list ray=[];
  6.      if(raytype=="-y") { ray = llCastRay(llGetPos()+<-(width/2),0.0,0.0>,llGetPos() + <width/2, -50.0, 0.0>,[RC_MAX_HITS, 5]);
  7.      } else   if(raytype=="-x") { ray = llCastRay(llGetPos()+<0.0,-(width/2),0.0>, llGetPos() + <-50.0, (width/2), 0.0>,[RC_MAX_HITS, 5]);
  8.      } else   if(raytype=="x") { ray = llCastRay(llGetPos()+<0.0,-(width/2),0.0>, llGetPos() + <50.0,(width/2), 0.0>,[RC_MAX_HITS, 5]);
  9.      } else   if(raytype=="y") { ray = llCastRay(llGetPos()+<-(width/2),0.0,0.0>, llGetPos() + <(width/2), 50.0, 0.0>,[RC_MAX_HITS, 5]);
  10.      } else return -1;
  11.      // We have a Ray
  12.     llOwnerSay((string)ray + " raytype = " + raytype);
  13.      vector mypos = llGetPos();
  14.      integer i=0;
  15.      float pos =566666;
  16.      integer position;
  17.      mypos = llGetPos();
  18.      do {
  19.            key lkID =  llList2Key(ray, i);
  20.            vector pos =    llList2Vector(ray,i+1);
  21.            // llOwnerSay("position " + (string)pos+ " i = " +(string)(i+1));
  22.          
  23.            if(llSubStringIndex(raytype, "x")!=-1) {
  24.                if((integer)pos.x != (integer)mypos.x ) {
  25.                  // llOwnerSay(">>position " + (string)pos+ " i = " +(string)(i+1));
  26.                   position= i+1;
  27.                  i = llGetListLength(ray) - 1;
  28.                };
  29.            } else if(llSubStringIndex(raytype, "y")!=-1) {
  30.                  if((integer)pos.y != (integer)mypos.y ) {
  31.                  // llOwnerSay(">>position " + (string)pos+ " i = " +(string)(i+1));
  32.                   position= i+1;
  33.                  i = llGetListLength(ray) - 1;
  34.                };
  35.            }
  36.            
  37.            i+=2;
  38.      } while(i<=llGetListLength(ray) - 1);
  39.      vector collision_pos = llList2Vector(ray,position);
  40.     // llOwnerSay("Position on x" + (string)collision_pos.x);
  41.      if(llSubStringIndex(raytype, "-y")!=-1 ){ return (integer)llFabs((mypos.y - collision_pos.y));
  42.      } else if(llSubStringIndex(raytype, "-x")!=-1) { return (integer)llFabs((mypos.x-collision_pos.x));
  43.      } else if(llSubStringIndex(raytype, "x")!=-1) {return (integer)llFabs((collision_pos.x-mypos.x ));
  44.      } else if(llSubStringIndex(raytype, "y")!=-1) { return (integer)llFabs((collision_pos.y -mypos.y));
  45.      } else return -1;
  46. }
  47.  
  48. default
  49. {
  50.     state_entry()
  51.     {
  52.           llVolumeDetect(TRUE);
  53.                // get boundaries
  54.         float boundaryonposy = 0;//GetBoundaryUsingCastRay("y", 0);
  55.         float boundaryonnegy = 0;//GetBoundaryUsingCastRay("-y",0);
  56.         float  boundaryonposx = GetBoundaryUsingCastRay("x",0);   // ******** Only detect on x acess for a collision
  57.         float  boundaryonnegx = 0;//GetBoundaryUsingCastRay("-x",0);
  58.         llOwnerSay(
  59.                  "Boundary marker on +x  is: "+(string)boundaryonposx +
  60.                  " Boundary marker on -x  is: "+(string)boundaryonnegx +  
  61.                  " \nBoundary marker on y  is: "+(string)boundaryonposy +
  62.                  " Boundary marker on -y  is: "+(string)boundaryonnegy);
  63.        
  64.     }
  65.    collision_start(integer num) // depends on state_entry    llVolumeDetect(TRUE);
  66.     {
  67.         key p_collision =llDetectedKey(0);
  68.         llOwnerSay("Collided");
  69.         integer vBitType = llDetectedType(0);
  70.         if (!(vBitType & AGENT || vBitType &  AGENT_BY_LEGACY_NAME)) {
  71.            integer l = llDetectedLinkNumber(0);
  72.            vector vAviPos = llDetectedPos(0);
  73.            vector vAviVel = llDetectedVel(0);
  74.            vector vObjPos = llList2Vector(llGetLinkPrimitiveParams(l,[PRIM_POSITION]),0);
  75.        
  76.            vector vAviToObj = vObjPos - vAviPos;
  77.            vector vAviToObjNorm = llVecNorm(<vAviToObj.x, vAviToObj.y, 0.0>);
  78.            // Rotation vRotAxis = vAviToObjNorm *llEuler2Rot(<0, 0, PI_BY_TWO>);
  79.         }
  80.     }
  81.     touch_start(integer total_number)
  82.     {
  83.         llSay(0, "Touched.");
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement