public ArrayList SearchBattleUnit(Vector2f center, float radius) { Rectanglef rect = new Rectanglef(new Vector2f(center.x - radius, center.y - radius), new Vector2f(center.x + radius, center.y + radius)); ArrayList objs = new ArrayList(); PoolSlot slot = mObjPool.UsedList(); while (slot != null) { BattleUnit unit = slot.Content as BattleUnit; if (unit == null) { slot = slot.NextSlot; continue; } Vector3f pos = unit.GetPosition3f(); if (Geometryalgorithm2d.point_in_rectangle(new Vector2f(pos.x, pos.z), rect)) { objs.Add(unit); } slot = slot.NextSlot; } return(objs); }
static public bool overlap(SceneShapeLine shape1, SceneShapeRound shape2) { LineSegf line = new LineSegf(new Vector2f(shape1.mVertex1.x, shape1.mVertex1.y), new Vector2f(shape1.mVertex2.x, shape1.mVertex2.y)); Vector2f tarPos = Geometryalgorithm2d.point_line_intersect(new Vector2f(shape2.mCenter.x, shape2.mCenter.y), line); return((tarPos.Subtract(new Vector2f(shape2.mCenter.x, shape2.mCenter.y))).length() <= shape2.mRadius); }
static public bool overlap(SceneShapeLine shape1, SceneShapePolygon shape2) { LineSegf line = new LineSegf(new Vector2f(shape1.mVertex1.x, shape1.mVertex1.y), new Vector2f(shape1.mVertex2.x, shape1.mVertex2.y)); for (int i = 1; i < shape2.mPts.Count; i++) { Vector2f p1 = new Vector2f(shape2.mPts[i - 1].x, shape2.mPts[i - 1].y); Vector2f p2 = new Vector2f(shape2.mPts[i].x, shape2.mPts[i].y); if (Geometryalgorithm2d.lineseg_intersect_lineseg(line, new LineSegf(p1, p2))) { return(true); } } return(false); }
static public bool circle_intersect_triangle(Vector2f center, float radius, Trianglef triangle) { if (Geometryalgorithm2d.point_in_triangle(center, triangle)) { return(true); } for (uint i = 0; i < 3; i++) { LineSegf line = triangle.side(i); Vector2f pt = Geometryalgorithm2d.point_line_intersect(center, line); float distance = pt.Subtract(center).length(); if (distance < radius) { return(true); } } return(false); }
// 包含点 override public bool contains(Vector2 pt) { return(Geometryalgorithm2d.IsPointInPolygon(mPts, pt)); //float angle = 0; //bool inside = false; //for (int i = 0, j = mPts.Count - 1; i < mPts.Count; j = i++) //{ // if (mPts[i].x == pt.x && mPts[i].y == pt.y) // 是否在顶点上 // { // inside = true; // break; // } // else if (Utility.isPointInSegment(pt, mPts[i], mPts[j])) // 是否在边界线上 // { // inside = true; // break; // } // float x1, y1, x2, y2; // x1 = mPts[i].x - pt.x; // y1 = mPts[i].y - pt.y; // x2 = mPts[j].x - pt.x; // y2 = mPts[j].y - pt.y; // // 计算角度和 // float radian = Mathf.Atan2(y1, x1) - Mathf.Atan2(y2, x2); // radian = Mathf.Abs(radian); // if (radian > Mathf.PI) // radian = Mathf.PI * 2 - radian; // angle += radian; //} //if (Mathf.Abs((float)(6.28318530717958647692 - angle)) < 1e-6) // inside = true; //return inside; }
private UpdateRetCode UpdateMovePos(uint elapsed) { if (mPathNodes == null) { return(UpdateRetCode.Aborted); } float movDist = elapsed * mOwner.GetSpeed() / 1000f; if (movDist < 0.001f) { return(UpdateRetCode.Continue); } Vector3f toPos = mOwner.GetPosition3f(); Vector3f curPos = mOwner.GetPosition3f(); while (movDist > 0 && mCurrentIndex < mPathNodes.Count) { Vector3f nodePos = mPathNodes[mCurrentIndex]; Vector3f len3d = nodePos.Subtract(curPos); len3d.y = 0; float distToNode = len3d.Length(); if (movDist >= distToNode) { movDist -= distToNode; toPos = nodePos; ++mCurrentIndex; if (mCurrentIndex < mPathNodes.Count) { Vector3f nodePosNext = mPathNodes[mCurrentIndex]; Vector3f posOwner = mOwner.GetPosition3f(); if (Math.Abs(posOwner.x - nodePosNext.x) > 0.01f || Math.Abs(posOwner.z - nodePosNext.z) > 0.01f) { float dir = Utility.Angle2D(new UnityEngine.Vector3(nodePosNext.x, nodePosNext.y, nodePosNext.z), new UnityEngine.Vector3(posOwner.x, posOwner.y, posOwner.z)) * UnityEngine.Mathf.Deg2Rad; mOwner.SetDirection(dir); mOwner.SetMoveDirection(dir); } } else { movDist = 0; } } else { if (mCurrentIndex > 0) { Vector3f dir = mPathNodes[mCurrentIndex].Subtract(mPathNodes[mCurrentIndex - 1]); dir.y = 0; dir.Normalize(); dir.MultiplyBy(movDist); toPos = curPos.Add(dir); LineSegf line = new LineSegf(new Vector2f(mPathNodes[mCurrentIndex - 1].x, mPathNodes[mCurrentIndex - 1].z), new Vector2f(mPathNodes[mCurrentIndex].x, mPathNodes[mCurrentIndex].z)); Vector2f tarPos = Geometryalgorithm2d.point_line_intersect(new Vector2f(toPos.x, toPos.z), line); toPos.x = tarPos.x; toPos.z = tarPos.y; movDist = 0; } else { len3d.y = 0; len3d.Normalize(); toPos = curPos.Add(len3d.MultiplyBy(movDist)); movDist = 0; } } } if (!mOwner.Scene.IsInWalkableRegion(toPos.x, toPos.z)) { return(UpdateRetCode.Finished); } //if (mOwner.Scene.IsBarrierRegion(mOwner, toPos.x, toPos.z)) //{ // return UpdateRetCode.Finished; //} toPos.y = mOwner.Scene.GetHeight(toPos.x, toPos.z); mOwner.SetPosition3f(toPos); return(mCurrentIndex >= mPathNodes.Count ? UpdateRetCode.Finished : UpdateRetCode.Continue); }
static public bool overlap(SceneShapeLine shape1, SceneShapeRect shape2) { return(Geometryalgorithm2d.lineseg_intersect_rectangle( new LineSegf(new Vector2f(shape1.mVertex1.x, shape1.mVertex1.y), new Vector2f(shape1.mVertex2.x, shape1.mVertex2.y)), new Rectanglef(new Vector2f(shape2.leftBottom().x, shape2.leftBottom().y), new Vector2f(shape2.rightTop().x, shape2.rightTop().y)))); }
static public bool overlap(SceneShapeLine shape1, SceneShapeLine shape2) { return(Geometryalgorithm2d.lineseg_intersect_lineseg( new LineSegf(new Vector2f(shape1.mVertex1.x, shape1.mVertex1.y), new Vector2f(shape1.mVertex2.x, shape1.mVertex2.y)), new LineSegf(new Vector2f(shape2.mVertex1.x, shape2.mVertex1.y), new Vector2f(shape2.mVertex2.x, shape2.mVertex2.y)))); }