public void build <T>(List <T> primitives, GetBounds <T> getBounds, uint leafSize = 3, bool printStats = false) { if (primitives.Count == 0) { init_empty(); return; } buildData dat; dat.maxPrims = (int)leafSize; dat.numPrims = (uint)primitives.Count; dat.indices = new uint[dat.numPrims]; dat.primBound = new AxisAlignedBox[dat.numPrims]; getBounds(primitives[0], out bounds); for (int i = 0; i < dat.numPrims; ++i) { dat.primBound[i] = AxisAlignedBox.NaN; dat.indices[i] = (uint)i; getBounds(primitives[i], out dat.primBound[i]); bounds.merge(dat.primBound[i]); } List <uint> tempTree = new(); BuildStats stats = new(); buildHierarchy(tempTree, dat, stats); for (int i = 0; i < dat.numPrims; ++i) { objects.Add(dat.indices[i]); } tree = tempTree; }
private void FrontCollisionTest() { if (isWallrun_Right || isWallrun_Left) { return; } RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 1 + controller.skinWidth)) { var maxBounds = GetBounds.GetMaxBounds(hit.transform.gameObject); //Debug.Log(maxBounds.max.y - transform.position.y); if (maxBounds.max.y - transform.position.y > 1) { if (Vector3.Dot(hit.normal, Vector3.up) == 0) { isClimbing = true; WallClimb(); // Debug.DrawRay(hit.point, Vector3.up, Color.blue, 10f); } else { isClimbing = false; } } else { isClimbing = false; } } }
private void WallClimb(RaycastHit hit) { if (isClimbing) { var maxBounds = GetBounds.GetMaxBounds(hit.transform.gameObject); Debug.Log(maxBounds.max.y - transform.position.y); if (maxBounds.max.y - transform.position.y > 0.1f) { isClimbing = true; vel = Vector3.up * 5; Debug.DrawRay(hit.point, Vector3.up, Color.blue, 10f); controller.Move((vel) * Time.deltaTime); } else { transform.position = new Vector3(transform.position.x, maxBounds.max.y + 0.1f, transform.position.z) + transform.forward; lastClimbedWall = hit.transform; if (tmpVel.y != jumpVel) { tmpVel.y = jumpVel; } controller.Move((tmpVel) * Time.deltaTime); isClimbing = false; } } animationController.SetBool(anim, AnimationManager.AnimationStates.climbing.ToString(), isClimbing); // controller.Move((vel) * Time.deltaTime); }
void Awake() { s_GetBounds = this; }
static private void GetRealPt(IFeatureLayer conFyr, IFeature pFeature, bool isPeakOrBottom, int fid, int sMark)//true表示山包线,false表示山洼线 { Dictionary <IPoint, IFeature> feaAndCenPt = RaterPtToVectorPt(pFeature); for (int i = 0; i < feaAndCenPt.Count; i++) { IPoint newPeakOrBotPt = feaAndCenPt.Keys.ElementAt(i); IPointCollection ptC = feaAndCenPt.Values.ElementAt(i).Shape as IPointCollection; double Z = Math.Round(ptC.get_Point(0).Z, 0); IPolyline mainLine = GetMainDirection(pFeature); IPolyline sectionPly = GetaSectionPly(mainLine, newPeakOrBotPt); IPoint leftPtOfMouPt = new PointClass(); IPoint rightPtOfMouPt = new PointClass(); ITopologicalOperator sTopo = sectionPly as ITopologicalOperator; IGeometry pGeo = sTopo.Intersect(pFeature.Shape, esriGeometryDimension.esriGeometry0Dimension); IPointCollection ptCol = new MultipointClass(); if (pGeo.IsEmpty == false) { ptCol = pGeo as IPointCollection; IPoint pt1 = ptCol.get_Point(0); IPoint pt2 = ptCol.get_Point(1); if (pt1.X > pt2.X) { rightPtOfMouPt = pt1; leftPtOfMouPt = pt2; } else { rightPtOfMouPt = pt2; leftPtOfMouPt = pt1; } } IPoint leftPtOfAdjPt = new PointClass(); IPoint rightPtOfAdjPt = new PointClass(); IFeature adjacentF = GetAdjacentFea(closedline, Z, newPeakOrBotPt, isPeakOrBottom); if (adjacentF == null) { adjacentF = GetAdjacentFea(openline, Z, newPeakOrBotPt, isPeakOrBottom); } pGeo = sTopo.Intersect(adjacentF.Shape, esriGeometryDimension.esriGeometry0Dimension); if (pGeo.IsEmpty == false) { ptCol = pGeo as IPointCollection; if (ptCol.PointCount == 2) { IPoint pt1 = ptCol.get_Point(0); IPoint pt2 = ptCol.get_Point(1); if (pt1.X > pt2.X) { rightPtOfAdjPt = pt1; leftPtOfAdjPt = pt2; } else { rightPtOfAdjPt = pt2; leftPtOfAdjPt = pt1; } } else if (ptCol.PointCount > 2) { Dictionary <IPoint, double> dic = new Dictionary <IPoint, double>(); for (int i_1 = 0; i_1 < ptCol.PointCount; i_1++) { IPoint pt = ptCol.get_Point(i_1); double dis = Math.Pow(newPeakOrBotPt.X - pt.X, 2) + Math.Pow(newPeakOrBotPt.Y - pt.Y, 2); dic.Add(pt, dis); } var disCd = from objDic in dic orderby objDic.Value ascending select objDic; List <IPoint> ptList = new List <IPoint>(); foreach (KeyValuePair <IPoint, double> key in disCd) { ptList.Add(key.Key); if (ptList.Count == 2) { break; } } IPoint pt1 = ptList[0]; IPoint pt2 = ptList[1]; if (pt1.X > pt2.X) { rightPtOfAdjPt = pt1; leftPtOfAdjPt = pt2; } else { rightPtOfAdjPt = pt2; leftPtOfAdjPt = pt1; } } else if (ptCol.PointCount == 1) { IPoint pt1 = ptCol.get_Point(0); IPoint pt2 = new PointClass(); Dictionary <IPolyline, int> boundD = GetBounds.GetNewBoundAndPtsDataFun(conFyr); for (int j = 0; j < boundD.Count; j++) { IPolyline ply = boundD.Keys.ElementAt(j); IGeometry pg = sTopo.Intersect(ply, esriGeometryDimension.esriGeometry0Dimension); if (pg.IsEmpty == false) { IPointCollection otherPtc = pg as IPointCollection; pt2 = otherPtc.get_Point(0); break; } } if (pt1.X > pt2.X) { rightPtOfAdjPt = pt1; leftPtOfAdjPt = pt2; } else { rightPtOfAdjPt = pt2; leftPtOfAdjPt = pt1; } } } ILine newLine = new LineClass(); newLine.FromPoint = sectionPly.FromPoint; newLine.ToPoint = sectionPly.ToPoint; IPoint newPt1 = new PointClass(); IPoint newPt2 = new PointClass(); newPt1 = RotateCoordinate(leftPtOfMouPt, newLine.Angle); newPt2 = RotateCoordinate(rightPtOfMouPt, newLine.Angle); double angle1 = 0; double angle2 = 0; double rightDis = Math.Sqrt(Math.Pow(rightPtOfMouPt.X - rightPtOfAdjPt.X, 2) + Math.Pow(rightPtOfMouPt.Y - Math.Abs(rightPtOfAdjPt.Y), 2)); //右边 double leftDis = Math.Sqrt(Math.Pow(leftPtOfAdjPt.X - leftPtOfMouPt.X, 2) + Math.Pow(leftPtOfAdjPt.Y - Math.Abs(leftPtOfMouPt.Y), 2)); //左边 if (isPeakOrBottom == true) { if (leftDis < rightDis) { angle1 = Math.Atan(intervalValue / leftDis); angle2 = 2 * Math.PI - Math.Atan(intervalValue / rightDis); } else if (leftDis > rightDis) { angle1 = Math.PI - Math.Atan(intervalValue / rightDis); angle2 = Math.PI + Math.Atan(intervalValue / leftDis); } } else { if (leftDis < rightDis) { angle1 = 2 * Math.PI - Math.Atan(intervalValue / leftDis); angle2 = Math.Atan(intervalValue / rightDis); } else if (leftDis > rightDis) { angle1 = Math.PI + Math.Atan(intervalValue / rightDis); angle2 = Math.PI - Math.Atan(intervalValue / leftDis); } } Dictionary <double, double> ptXZDic = new Dictionary <double, double>(); GetCalculatedPoints.dTightness = 2.5; for (int j = 0; j < 1; j++) { ptXZDic = GetCalculatedPoints.CreateNewPoint(newPt1.X, Z, newPt2.X, Z, angle1, angle2, 20); ptXZDic = SortedByZValue(ptXZDic, isPeakOrBottom); double diffZ = ptXZDic.Values.ElementAt(0); IPoint ppts = RotateCoordinate(newPeakOrBotPt, newLine.Angle); if ((diffZ < Z + intervalValue && diffZ > Z) || (diffZ > Z - intervalValue && diffZ < Z)) { IPoint pt = new PointClass(); if (ptXZDic.Keys.ElementAt(0) > ppts.X) { pt.X = ppts.X + Math.Abs(ptXZDic.Keys.ElementAt(0) - ppts.X); } else { pt.X = ppts.X - Math.Abs(ptXZDic.Keys.ElementAt(0) - ppts.X); } pt.Y = ((pt.X - newPt2.X) * (newPt1.Y - newPt2.Y) / (newPt1.X - newPt2.X)) + newPt2.Y; IPoint nPt = RotateCoordinate(pt, -newLine.Angle); nPt.Z = ptXZDic.Values.ElementAt(0); mounTPtList.Add(nPt, feaAndCenPt.Values.ElementAt(i)); break; } else { GetCalculatedPoints.dTightness -= 0.1; j = -1; } } } }