Example #1
0
    public void setLedBar(LedBar bar)
    {
        ledBar = bar;


        //@todo calculate position based on all three leds not just the first one.
    }
Example #2
0
    public float calculateDistance(LedBar bar)
    {
        float distanceOneToTwo   = calculateDistanceBetweenLeds(bar.Leds[0], bar.Leds[1]);
        float distanceTwoToThree = calculateDistanceBetweenLeds(bar.Leds[1], bar.Leds[2]);

        // Debug.Log("Distance 1 = " + distanceOneToTwo);
        // Debug.Log("Distance tWo to Three is: " + distanceTwoToThree);

        float distance = (ledBarSize * focalLenght) / (distanceOneToTwo + distanceTwoToThree);

        //Debug.Log("distance from camera to head is: " +  distance + "CM");

        // debugText.text = "Distance to head is: " + distance.ToString("0.##") + "cm";


        return(toCameraDistance(distance));
    }
Example #3
0
    public void calculateHeadRotation(LedBar ledbar)
    {
        float distanceOneToTwo   = calculateDistanceBetweenLeds(ledbar.Leds[0], ledbar.Leds[1]);
        float distanceTwoToThree = calculateDistanceBetweenLeds(ledbar.Leds[1], ledbar.Leds[2]);

        int percentageRight = (int)(distanceOneToTwo / (distanceOneToTwo + distanceTwoToThree) * 100);

        if (index < 10)
        {
            totalPercentageRight += percentageRight;
            index++;
        }
        else
        {
            int percentageRAVG = totalPercentageRight / 10;
            int percentageLAVG = 100 - percentageRAVG;
            checkLooking(percentageRAVG, percentageLAVG);
            // Debug.Log(percentageRAVG);
            index = 0;
            totalPercentageRight = 0;
        }
    }
Example #4
0
    // camera x = (((324 - 316)/640) * data) + 316;
    // camera y = (((244 - 236)/480) * data) + 236;

    Vector3 calculateCameraPosition(float x, float y, LedBar bar)
    {
        x = dataMaxX - x;

        float cameraX = (((cameraMaxX - cameraMinX) / dataMaxX) * x) + cameraMinX;
        float cameraY = (((cameraMaxY - cameraMinY) / dataMaxY) * y) + cameraMinY;


        float cameraDistance = distanceHandler.calculateDistance(bar);

        headRotationHandler.calculateHeadRotation(bar);
        Vector3 cameraPos = new Vector3(cameraX, cameraY, cameraDistance);

        float mainCameraX = camera.transform.localPosition.x;
        float mainCameraY = camera.transform.localPosition.y;

        float maxJumpThreshold = 0.1f;



        // keep speed in check and check if it does not jump to much.
        // without speed you lose the camera tracking

        if (cameraPos.x < mainCameraX + maxJumpThreshold && cameraPos.x > mainCameraX - maxJumpThreshold)
        {
            if (cameraPos.y < mainCameraY + maxJumpThreshold && cameraPos.y > mainCameraY - maxJumpThreshold)
            {
                // Debug.Log(cameraPos);
                return(cameraPos);
            }
        }

        //  return cameraPos;

        return(camera.transform.localPosition);
    }
Example #5
0
 private void PipeClient_onResponse(string response)
 {
     ledBar = JsonUtility.FromJson <LedBar>(response);
 }