private void callGameObjByKinect(short[] depthBuf) { //Color32[] img = new Color32[depthBuf.Length]; minDepth = 0; // initialize mindepth per frame minPoint.Set(0, 0); for (int pix = 0; pix < depthBuf.Length; pix += 2) { // 's' key was pressed and two canvas vertex(leftTop, rightBottom) are not detected // restrict depth range from 800mm to 1000mm b/c IR noise (kinect depth accruacy decreases with increasing distance from the sensor) if (depthSnapshot != null && pointCount == 2 && depthBuf [pix] >= 700 && depthSnapshot [pix] <= 1000) // pointCount != 2 -> two points were detected { Vector2 currentPtr = valueToPoint(pix, 320); if (currentPtr.x > ROIVertex [0].x && currentPtr.x <ROIVertex [1].x && currentPtr.y> ROIVertex[0].y && currentPtr.y < ROIVertex [1].y) { short depthDiff = (short)(depthSnapshot [pix] - depthBuf [pix]); if (minDepth < depthDiff) // find greatest depth diff //Debug.Log("point detected "+depthSnapshot[pix]+","+depthBuf[pix]); { minPoint = currentPtr; minDepth = depthDiff; } } } } Debug.Log("mindep : " + minDepth); // if(minDepth <= errorRange){ // stable state // if(isDetected == false){ // Debug.Log("stable state"); // } // isDetected = true; // }else{ // // } // // if (minDepth > 30 && isDetected == true && pointCount < 2) { // Debug.Log((pointCount + 1)+" point detected"); // ROIVertex [pointCount++] = minPoint; // // isDetected = false; // until canvas state turn back to stable state // } //test// if (pointCount == 2 && minDepth > errorRange) { if (isDetected == false) { isDetected = true; } float x, y; //find x,y ratio x = (minPoint.x - ROIVertex[0].x) / (ROIVertex[1].x - ROIVertex[0].x); y = (minPoint.y - ROIVertex[0].y) / (ROIVertex[1].y - ROIVertex[0].y); // b/c kinect look at the canvas in reverse // coordinates transformation from kinect to unity y = 1 - y; // for debuging if (guiT != null) { guiT.transform.position = new Vector3(x, y, 0f); } //y -= 0.06f; // adjust calibration manually text.guiText.text = "spandex pos : " + x + "," + y; Vector2 worldPoint = new Vector2(Screen.width * x, Screen.height * y); //2. find game object by kinect input(2D coordinates) GameObject gameObject = findGameObject(worldPoint.x, worldPoint.y); GameObject colorSelector = findColorSelector(worldPoint.x, worldPoint.y); //3. call the onSpandexDown method if (gameObject != null) { if (gameObject.name == "canvas") { drawingOnGUI canvasScript = gameObject.GetComponent <drawingOnGUI>(); canvasScript.OnCanvasDown(worldPoint, minDepth); // TODO complete params } else if (colorSelector != null) { GameObject.Find("Control - Circular Color Picker").SendMessage("OnCanvasDown", worldPoint); } else { gameObject.SendMessage("OnCanvasDown"); } //Debug.Log ("gameobject found : " + gameObject.name); } prevMinPtr = worldPoint; } else if (pointCount == 2 && minDepth < errorRange && isDetected == true) { isDetected = false; if (findGameObject(prevMinPtr.x, prevMinPtr.y).name == "canvas") // 'spandex canvas up' on 'drawing canvas' { GameObject.Find("canvas").SendMessage("OnCanvasUp"); } prevMinPtr.Set(0, 0); } }
private void callGameObjByKinect(StSendData kinectInput) { if (isDetected == false) // for canvas up event { isDetected = true; } float x, y; //find x,y ratio x = kinectInput.fSymbolPosX; y = kinectInput.fSymbolPosY; // coordinates transformation from kinect to unity y = 1 - y; // adjust calibration manually //y -= 0.03f; //real valid input Vector2 worldPoint = new Vector2(Screen.width * x, Screen.height * y); //2. find game object by kinect input(2D coordinates) GameObject gameObject = findGameObject(worldPoint.x, worldPoint.y); GameObject colorSelector = findColorSelector(worldPoint.x, worldPoint.y); //Debug.Log (gameObject.name); //3. call the onSpandexDown method if (gameObject != null) { if (gameObject.name == "canvas") { isOnCanvas = true; //TODO Sandart drawingOnGUI canvasScript = gameObject.GetComponent <drawingOnGUI>(); if (canvasScript != null) { canvasScript.OnCanvasDown(worldPoint, (short)kinectInput.fSymbolDepth); // TODO complete params } else { Sandart sandScript = gameObject.GetComponent <Sandart>(); sandScript.OnCanvasDown(worldPoint, (short)kinectInput.fSymbolDepth); } } else if (colorSelector != null) { GameObject.Find("Control - Circular Color Picker").SendMessage("OnCanvasDown", worldPoint); if (isOnCanvas == true) { isOnCanvas = false; GameObject.Find("canvas").SendMessage("OnCanvasUp"); } } else { if (isOnCanvas == true) { isOnCanvas = false; GameObject.Find("canvas").SendMessage("OnCanvasUp"); } gameObject.SendMessage("OnCanvasDown"); } Debug.Log("gameobject found : " + gameObject.name); } prevMinPtr = worldPoint; // for canvas up event // else if(pointCount == 2 && minDepth < errorRange && isDetected == true){ // End of canvas down // isDetected = false; // // if(findGameObject(prevMinPtr.x,prevMinPtr.y).name == "canvas") // 'spandex canvas up' on 'drawing canvas' // GameObject.Find("canvas").SendMessage("OnCanvasUp"); // // prevMinPtr.Set (0,0); // } }