// draws coordinate grid on screen private void DrawGrid() { int rectX = (int)foregroundImgRect.xMin; int rectY = (int)foregroundImgRect.yMin; float scaleX = foregroundImgRect.width / depthImageWidth; float scaleY = foregroundImgRect.height / depthImageHeight; // draw grid float c = 0.3f; for (int x = 0; x < depthImageWidth; x += 100) { int sX = (int)(x * scaleX); int sMaxY = (int)((depthImageHeight - 1) * scaleY); Color clrLine = new Color(c, 0, 0, 1); KinectInterop.DrawLine(rectX + sX, rectY, rectX + sX, rectY + sMaxY, 1, clrLine); c += 0.1f; } c = 0.3f; for (int y = 0; y < depthImageHeight; y += 100) { int sY = (int)((depthImageHeight - y) * scaleY); int sMaxX = (int)((depthImageWidth - 1) * scaleX); Color clrLine = new Color(0, c, 0, 1); KinectInterop.DrawLine(rectX, rectY + sY, rectX + sMaxX, rectY + sY, 1, clrLine); c += 0.1f; } }
// Update is called once per frame void Update() { if (manager && manager.IsInitialized()) { Texture2D depthImage = manager ? manager.GetUsersLblTex() : null; if (bodySlicer && bodySlicer.getLastFrameTime() != lastFrameTime) { lastFrameTime = bodySlicer.getLastFrameTime(); int sliceCount = bodySlicer.getBodySliceCount(); if (depthImage) { //depthImage = GameObject.Instantiate(depthImage) as Texture2D; for (int i = 0; i < sliceCount; i++) { BodySliceData bodySlice = bodySlicer.getBodySliceData((BodySlice)i); if (depthImage && bodySlice.isSliceValid && bodySlice.startDepthPoint != Vector2.zero && bodySlice.endDepthPoint != Vector2.zero) { KinectInterop.DrawLine(depthImage, (int)bodySlice.startDepthPoint.x, (int)bodySlice.startDepthPoint.y, (int)bodySlice.endDepthPoint.x, (int)bodySlice.endDepthPoint.y, Color.red); } } depthImage.Apply(); } if (statusText) { if (bodySlicer.getCalibratedUserId() != 0) { userHeight = !float.IsNaN(userHeight) ? Mathf.Lerp(userHeight, bodySlicer.getUserHeight(), smoothFactor * Time.deltaTime) : bodySlicer.getUserHeight(); string sUserInfo = string.Format("User {0} Height: {1:F2} m", bodySlicer.playerIndex, userHeight); userW1 = !float.IsNaN(userW1) ? Mathf.Lerp(userW1, bodySlicer.getSliceWidth(BodySlice.TORSO_1), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_1); userW2 = !float.IsNaN(userW2) ? Mathf.Lerp(userW2, bodySlicer.getSliceWidth(BodySlice.TORSO_2), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_2); userW3 = !float.IsNaN(userW3) ? Mathf.Lerp(userW3, bodySlicer.getSliceWidth(BodySlice.TORSO_3), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_3); userW4 = !float.IsNaN(userW4) ? Mathf.Lerp(userW4, bodySlicer.getSliceWidth(BodySlice.TORSO_4), smoothFactor * Time.deltaTime) : bodySlicer.getSliceWidth(BodySlice.TORSO_4); sUserInfo += string.Format("\n\nTorso-4: {3:F2} m\nTorso-3: {2:F2} m\nTorso-2: {1:F2} m\nTorso-1: {0:F2} m", userW1, userW2, userW3, userW4); statusText.text = sUserInfo; } else { statusText.text = string.Format("User {0} not found", bodySlicer.playerIndex);; } } } if (backgroundImage) { backgroundImage.texture = depthImage; } } }
private void DrawBodySlice(BodySliceData bodySlice) { if (depthImage && bodySlice.isSliceValid && bodySlice.startDepthPoint != Vector2.zero && bodySlice.endDepthPoint != Vector2.zero) { KinectInterop.DrawLine(depthImage, (int)bodySlice.startDepthPoint.x, (int)bodySlice.startDepthPoint.y, (int)bodySlice.endDepthPoint.x, (int)bodySlice.endDepthPoint.y, Color.red); } }
private void DrawBodySlice(Texture2D imageTex, BodySliceData bodySlice) { if (imageTex && bodySlice.isSliceValid && bodySlice.startDepthPoint != Vector2.zero && bodySlice.endDepthPoint != Vector2.zero) { KinectInterop.DrawLine(imageTex, (int)bodySlice.startDepthPoint.x, (int)bodySlice.startDepthPoint.y, (int)bodySlice.endDepthPoint.x, (int)bodySlice.endDepthPoint.y, Color.red); } }
// draws a body slice line private void DrawBodySlice(BodySliceData bodySlice) { if (bodySlice.isSliceValid && bodySlice.startDepthPoint != Vector2.zero && bodySlice.endDepthPoint != Vector2.zero) { float rectX = foregroundImgRect.xMin; float rectY = foregroundImgRect.yMin; float scaleX = foregroundImgRect.width / depthImageWidth; float scaleY = foregroundImgRect.height / depthImageHeight; float x1 = rectX + (depthScale.x >= 0f ? bodySlice.startDepthPoint.x : depthImageWidth - bodySlice.startDepthPoint.x) * scaleX; float y1 = rectY + (depthScale.y >= 0f ? bodySlice.startDepthPoint.y : depthImageHeight - bodySlice.startDepthPoint.y) * scaleY; float x2 = rectX + (depthScale.x >= 0f ? bodySlice.endDepthPoint.x : depthImageWidth - bodySlice.endDepthPoint.x) * scaleX; float y2 = rectY + (depthScale.y >= 0f ? bodySlice.endDepthPoint.y : depthImageHeight - bodySlice.endDepthPoint.y) * scaleY; KinectInterop.DrawLine((int)x1, (int)y1, (int)x2, (int)y2, 2f, Color.red); } }
private void DrawLine(Texture2D a_Texture, Vector2 ptStart, Vector2 ptEnd, UnityEngine.Color a_Color) { KinectInterop.DrawLine(a_Texture, (int)ptStart.x, (int)ptStart.y, (int)ptEnd.x, (int)ptEnd.y, a_Color); }