public JPoint PopupPoint(JRect rect, JPoint moveDir) { UnityEngine.Debug.Log("x"); if (IsIn(rect) || rect.IsIn(this)) { JPoint tmCenter = rect.center; JPoint p = rect.center - center; float d = p.Mod; JPoint dir = moveDir.Contrary; dir = dir.Normal; float absX = Math.Abs(dir.x); float absY = Math.Abs(dir.y); float heightSum = (rect.height + this.height) / 2f; float widthSum = (rect.width + this.width) / 2f; UnityEngine.Debug.Log(widthSum); //向上下弹-- if (absY >= absX) { float y = rect.center.y + (dir.y >= 0 ? heightSum : -heightSum); tmCenter.y = y; } else //向左右弹-- { float x = rect.center.x + (dir.x >= 0 ? widthSum : -widthSum); tmCenter.x = x; } return tmCenter; } return rect.center; }
private void GetJointLocations(Skeleton skeleton) { canvasWidth = (int)handCanvas.ActualWidth; canvasHeight = (int)handCanvas.ActualHeight; // 这里右手的结点是我左手的位置信息 Joint center = skeleton.Joints[JointType.HipCenter]; Joint left = skeleton.Joints[JointType.HandLeft]; Joint right = skeleton.Joints[JointType.HandRight]; leftHand = JointLocation(right); rightHand = JointLocation(left); //JAngle leftAngle = JointAngle(skeleton.Joints[JointType.HandLeft]); //gestureBlock.Text = "AX:" + leftAngle.X +"JX:"+ left.Position.X; //获取前面的那只手,好像这里的骨架完全相反的样子 //Joint frontHand; JAngle fAHand; if (leftHand.Z < (rightHand.Z + 0.1)) { //frontHand = right; fAHand = JointAngle(right); isLeftHand = true; } else if (isLeftHand) { //frontHand = right; fAHand = JointAngle(right); } else { //frontHand = left; fAHand = JointAngle(left); isLeftHand = false; } //double X = Math.Atan(frontHand.Position.X / frontHand.Position.Z) / 3.14 * 180 + 90; //// 1.5 是程序放大的倍数, +90 是舵机范围0-180, +45 是前面的45度在手势区不可能到达 //double Y = 90 - Math.Atan(frontHand.Position.Y / frontHand.Position.Z) / 3.14 * 180 + 45; //angleX = (int)X; //angleY = (int)Y; //// read hand 仿生手臂操作 //double rX = 90 - Math.Atan(frontHand.Position.X / frontHand.Position.Z) / 3.14 * 180 * 2; //double rY = Math.Atan(frontHand.Position.Y / frontHand.Position.Z) / 3.14 * 180 * 1.5 + 90 + 45; angleX = 180 - fAHand.X; angleY = fAHand.Y + 30; gestureBlock.Text = "AX:" + angleX + " AY:" + angleY; //statusBarText.Text = _debug; debugBlock.Text = _debug; distBlock.Text = "距离摄像头:" + Math.Round(center.Position.Z, 2) + "米"; //positionBlock.Text = "AY" + Y + "JY:" + left.Position.Y; }
void generateOneLine(JPoint p0, JPoint p1, JPoint p2, JPoint p3) { // p0 = new JPoint (336, 392); // p1 = new JPoint (355, 457); // p2 = new JPoint (482, 502); // p3 = new JPoint (501, 567); // Debug.Log("p0 "+p0.x+","+p0.y +" p1 "+p1.x+","+p1.y+" p2 "+p2.x+","+p2.y+" p3 "+p3.x+","+p3.y); drawBezier(p0, p1, p2, p3); }
public JRect(JPoint center, float width, float height) { debugRectList.Add(this); this.center = center; this.width = width; this.height = height; this.point1 = JPoint.Zero; this.point1 = JPoint.Zero; PointUpt(); }
void drawBezier(JPoint p0, JPoint p1, JPoint p2, JPoint p3) { List <JPoint> pList = getBezierPointsList(p0, p1, p2, p3); for (int i = 0; i < pList.Count; i++) { //tempTexture.SetPixels (pList [i].x-1, pList [i].y-1, 3, 3, redColorBrush); tempTexture.SetPixel(pList [i].x, pList [i].y, currColor); } tempTexture.Apply(); }
public bool IsIn(JPoint point) { if (point1.x <= point.x && point.x <= point2.x && point2.y <= point.y && point.y <= point1.y) { return true; } return false; }
// p0 start p1 control1 p2 control2 p3 end List <JPoint> getBezierPointsList(JPoint p0, JPoint p1, JPoint p2, JPoint p3) { List <JPoint> points = new List <JPoint> (); int length = p3.x - p0.x; float rate = 1f / length; for (int i = 0; i < length; i++) { JPoint bezierPoint = pointOnBezier(p0, p1, p2, p3, rate * i); points.Add(bezierPoint); } return(points); }
JPoint pointOnBezier(JPoint p0, JPoint p1, JPoint p2, JPoint p3, float t) { float ax, bx, cx, dx; float ay, by, cy, dy; ax = (1 - t) * (1 - t) * (1 - t) * (float)p0.x; bx = 3 * t * (1 - t) * (1 - t) * (float)p1.x; cx = 3 * t * t * (1 - t) * (float)p2.x; dx = t * t * t * (float)p3.x; ay = (1 - t) * (1 - t) * (1 - t) * (float)p0.y; by = 3 * t * (1 - t) * (1 - t) * (float)p1.y; cy = 3 * t * t * (1 - t) * (float)p2.y; dy = t * t * t * (float)p3.y; JPoint result = new JPoint((int)(ax + bx + cx + dx), (int)(ay + by + cy + dy)); return(result); }
public JPoint[] getPositions() { float x0 = startPoint.transform.position.x; float y0 = startPoint.transform.position.y; JPoint p0 = new JPoint((int)(x0 * 50f), (int)(y0 * 50f)); float x1 = controlA.transform.position.x; float y1 = controlA.transform.position.y; JPoint p1 = new JPoint((int)(x1 * 50f), (int)(y1 * 50f)); float x2 = controlB.transform.position.x; float y2 = controlB.transform.position.y; JPoint p2 = new JPoint((int)(x2 * 50f), (int)(y2 * 50f)); float x3 = endPoint.transform.position.x; float y3 = endPoint.transform.position.y; JPoint p3 = new JPoint((int)(x3 * 50f), (int)(y3 * 50f)); JPoint[] ret = new JPoint[4]; if (x0 < x3) { ret [0] = p0; ret [1] = p1; ret [2] = p2; ret [3] = p3; } else { ret [0] = p3; ret [1] = p2; ret [2] = p1; ret [3] = p0; } return(ret); }
private void SetElementPosition(FrameworkElement element, JPoint jp) { Canvas.SetLeft(element, jp.X - element.Width / 2); Canvas.SetTop(element, jp.Y); //Canvas.SetZIndex(element, 100); }
/// <summary> /// Sets the global tracked vars with needed values /// </summary> private void GetJointLocations(Skeleton thisSkeleton) { head = JointLocation(thisSkeleton.Joints[JointType.Head]); sholderLeft = JointLocation(thisSkeleton.Joints[JointType.ShoulderLeft]); elbowLeft = JointLocation(thisSkeleton.Joints[JointType.ElbowLeft]); handLeft = JointLocation(thisSkeleton.Joints[JointType.HandLeft]); sholderRight = JointLocation(thisSkeleton.Joints[JointType.ShoulderRight]); elbowRight = JointLocation(thisSkeleton.Joints[JointType.ElbowRight]); handRight = JointLocation(thisSkeleton.Joints[JointType.HandRight]); }
/// <summary> /// Moves a framework element from canvas to a given position /// </summary> /// <param name="ellipse"></param> /// <param name="jp"></param> private void SetElementPosition(FrameworkElement element, JPoint jp) { if (element.Equals(smileyHead)) { Canvas.SetTop(element, CanvasWidth - jp.Y + element.Height / 2 - 60); } else { Canvas.SetTop(element, CanvasWidth - jp.Y + element.Height / 2); } Canvas.SetLeft(element, jp.X - element.Width/2); }
/// <summary> /// 设置角度和旋转信息 同时获取primary hand /// </summary> /// <param name="skeleton"></param> private void GetJointLocations(Skeleton skeleton) { canvasWidth = (int)handCanvas.ActualWidth; canvasHeight = (int)handCanvas.ActualHeight; // 这里右手的结点是我左手的位置信息 Joint center = skeleton.Joints[JointType.HipCenter]; Joint left = skeleton.Joints[JointType.HandLeft]; Joint right = skeleton.Joints[JointType.HandRight]; leftHand = JointLocation(right); rightHand = JointLocation(left); //JAngle leftAngle = JointAngle(skeleton.Joints[JointType.HandLeft]); //gestureBlock.Text = "AX:" + leftAngle.X +"JX:"+ left.Position.X; // 获取前面的那只手,好像这里的骨架完全相反的样子 // 如果被追踪的那只手相差0.3米才会切换另外一只手 //Joint frontHand; JAngle fAHand; if (leftHand.Z < (rightHand.Z - 0.3)) { //frontHand = right; fAHand = JointAngle(right); isLeftHand = true; } else if (rightHand.Z < leftHand.Z - 0.3) { //frontHand = left; fAHand = JointAngle(left); isLeftHand = false; } else if (isLeftHand) { fAHand = JointAngle(right); } else { fAHand = JointAngle(left); } //double X = Math.Atan(frontHand.Position.X / frontHand.Position.Z) / 3.14 * 180 + 90; //// 1.5 是程序放大的倍数, +90 是舵机范围0-180, +45 是前面的45度在手势区不可能到达 //double Y = 90 - Math.Atan(frontHand.Position.Y / frontHand.Position.Z) / 3.14 * 180 + 45; //angleX = (int)X; //angleY = (int)Y; //// read hand 模仿手臂操作 //double rX = 90 - Math.Atan(frontHand.Position.X / frontHand.Position.Z) / 3.14 * 180 * 2; //double rY = Math.Atan(frontHand.Position.Y / frontHand.Position.Z) / 3.14 * 180 * 1.5 + 90 + 45; if (isRealHand) { angleX = 150 - fAHand.X + 30; angleY = fAHand.Y + 30; } else { angleX = fAHand.X; angleY = fAHand.Y + 25; } angleBlock.Text = "AX:" + angleX + " AY:" + angleY; //statusBarText.Text = _debug; debugBlock.Text = _debug; distBlock.Text = String.Format("距摄像头{0:N2}米", center.Position.Z); //positionBlock.Text = "AY" + Y + "JY:" + left.Position.Y; }
public static Vector2 JPoint2Vector2(JPoint point) { return new Vector3(point.x, point.y); }
private void SetElementPosition(FrameworkElement element, JPoint jp) { Canvas.SetLeft(element, jp.X - element.Width / 2); Canvas.SetTop(element, jp.Y); }
private void GetJointLocations(Skeleton thisSkeleton) { handLeft = JointLocation(thisSkeleton.Joints[JointType.HandLeft]); }