Page 3 of 3

Re: Multiple displays issue with camera depth

PostPosted: Fri Nov 10, 2017 2:12 pm
by Timo
Each scan beam is shown in the inspector numerically and it's distance is displayed next to that. So I think they do have a numerical id.
Distance is from 21mm to 3000mm and the number of scan beams are controlled with a maximum value.
So 512 beams gives 0 to 511 numerical beams, with distance at 3000 or less when the beam hits an obstacle.

As I move my hand across the screen, the distances are clustered which can be interpreted as a touch etc. Obstacles in this case. I can possibly add an id to an obstacle when one is added to the obstacle list. I will look into this.

So perhaps I could pass the beams' numerical ids to touchscript? And let touchscript workout the obstacles as touch inputs, instead of using the current codes obstacle list.

EDIT After thinking more about this, the waterfall Unity project I'm using to test the scanners, is already translating the scan data to onscreen touch interaction. When a hand is placed on screen in the path of the waterfall, the water behaves as if a physical object is placed in its way and splashes appear with the main waterfall's flow below the obstacle being affected.
My actual project just needs touch and drag information computed from the scanner data. I hoped Touchscript would be a case of plug and play, but I guess I will have to try to convert the waterfall code to my requirements.

Thank you. Timo

Re: Multiple displays issue with camera depth

PostPosted: Thu Nov 16, 2017 12:23 pm
by Timo
Hi valyard, I believe I have found the id's method for the scanner beams and I am wondering if these can be passed to TS as you previously mentioned.
Please could you check this code and let me know if it's useable?
Code: Select all
bool endGroup = true;
      float deltaLimit = 100; //  (mm)
      for(int i = 1; i < distances.Count-1; i++){
         //float a = d * i + offset;
         //Vector3 dir = new Vector3(-Mathf.Cos(a), -Mathf.Sin(a), 0);
         Vector3 dir = directions[i];
         long dist = distances[i];
         float delta = Mathf.Abs((float)(distances[i] - distances[i-1]));
         float delta1 = Mathf.Abs((float)(distances[i+1] - distances[i]));
            
         if(dir.y > 0){
            DetectObject detect;
            if(endGroup){
               Vector3 pt = dist * dir * scale;
               if(dist < limit && (delta < deltaLimit && delta1 < deltaLimit)){
//               bool isArea = detectAreaRect.Contains(pt);
//               if(isArea && (delta < deltaLimit && delta1 < deltaLimit)){
                  detect = new DetectObject();
                  detect.idList.Add(i);
                  detect.distList.Add(dist);
                  
                  detect.startDist = dist;
                  detectObjects.Add(detect);
                  
                  endGroup = false;
               }
            }else{
               if(delta1 >= deltaLimit || delta >= deltaLimit){
                  endGroup = true;
               }else{
                  detect = detectObjects[detectObjects.Count-1];
                  detect.idList.Add(i);
                  detect.distList.Add(dist);
               }
            }
         }
      }

      drawCount = 0;
      for(int i = 0; i < detectObjects.Count; i++){
         DetectObject detect = detectObjects[i];

         // noise
         if(detect.idList.Count < noiseLimit){
            continue;
         }

         int offsetCount = detect.idList.Count / 3;
         int avgId = 0;
         for(int n = 0; n < detect.idList.Count; n++){
            avgId += detect.idList[n];
         }
         avgId = avgId / (detect.idList.Count);

         long avgDist = 0;
         for(int n = offsetCount; n < detect.distList.Count - offsetCount; n++){
            avgDist += detect.distList[n];
         }
         avgDist = avgDist / (detect.distList.Count - offsetCount * 2);

         //float a = d * avgId + offset;
         //Vector3 dir = new Vector3(-Mathf.Cos(a), -Mathf.Sin(a), 0);
         Vector3 dir = directions[avgId];
         long dist = avgDist;


         //float a0 = d * detect.idList[offsetCount] + offset;
         //Vector3 dir0 = new Vector3(-Mathf.Cos(a0), -Mathf.Sin(a0), 0);
         int id0 = detect.idList[offsetCount];
         Vector3 dir0 = directions[id0];
         long dist0 = detect.distList[offsetCount];

         //float a1 = d * detect.idList[detect.idList.Count-1 - offsetCount] + offset;
         //Vector3 dir1 = new Vector3(-Mathf.Cos(a1), -Mathf.Sin(a1), 0);
         int id1 = detect.idList[detect.idList.Count-1 - offsetCount];
         Vector3 dir1 = directions[id1];
         long dist1 = detect.distList[detect.distList.Count-1 - offsetCount];

         Color gColor;
         if(drawCount < groupColors.Length){
            gColor = groupColors[drawCount];
         }else{
            gColor = Color.green;
         }
         for(int j = offsetCount; j < detect.idList.Count - offsetCount; j++){
            //float _a = d * detect.idList[j] + offset;
            //Vector3 _dir = new Vector3(-Mathf.Cos(_a), -Mathf.Sin(_a), 0);
            int _id = detect.idList[j];
            Vector3 _dir = directions[_id];
            long _dist = detect.distList[j];
            Debug.DrawRay(Vector3.zero, _dist * _dir * scale, gColor);
         }

         Debug.DrawLine(dist0 * dir0 * scale, dist1 * dir1 * scale, gColor);
         Debug.DrawRay(Vector3.zero, dist * dir * scale, Color.green);

         drawCount++;
      }


Would you also be able to update your input source tutorial to included the changes you mentioned, for screenWidth and screenHeight?

Many thanks in advance. Timo.