Multiple displays issue with camera depth

Ask for help and post bugs.

Re: Multiple displays issue with camera depth

Postby Timo » Fri Nov 10, 2017 2:12 pm

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
Posts: 19
Joined: Mon Oct 23, 2017 2:48 am

Re: Multiple displays issue with camera depth

Postby Timo » Thu Nov 16, 2017 12:23 pm

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;
               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.startDist = dist;
                  endGroup = false;
               if(delta1 >= deltaLimit || delta >= deltaLimit){
                  endGroup = true;
                  detect = detectObjects[detectObjects.Count-1];

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

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

         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];
            gColor =;
         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(, _dist * _dir * scale, gColor);

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


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.
Posts: 19
Joined: Mon Oct 23, 2017 2:48 am

Re: Multiple displays issue with camera depth

Postby valyard » Tue Nov 21, 2017 10:45 pm

Timo, sorry this is too much code which requires deeper understanding of the problem space. No time right now unfortunately.
As for the screenWidth and screenHeight changes, these will go to develop branch as soon as I have time to compile a new build.
Site Admin
Posts: 439
Joined: Mon Sep 08, 2014 11:57 pm

Re: Multiple displays issue with camera depth

Postby Timo » Wed Nov 22, 2017 12:52 pm

No worries sir. I'm still trying to get something to work. I have an algorithm sketched out, I just need to make it useable.
I will see how I get on. Obviously it would be a useful addition for future TS users trying to do the same, if we manage to get this working.

Posts: 19
Joined: Mon Oct 23, 2017 2:48 am


Return to Help and Bugs

Who is online

Users browsing this forum: No registered users and 1 guest