static void Check(Tree4 tree) { if (!tree.collisonInfo.active) { return; } int count = tree.objs.Count; var objs = tree.objs; for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (objs[i] != objs[j] && (objs[i].rigibody.useCheck || objs[j].rigibody.useCheck)) { if (ShapPhysics.Check(objs[i].Shap, objs[j].Shap)) { objs[i].rigibody.AddCollistionData(objs[j]); objs[j].rigibody.AddCollistionData(objs[i]); } } } } //lastCheckTime = InputCenter.Time; tree.collisonInfo.active = false; }
public void Init() { if (shaps == null && tree == null) { shaps = new List <NetData>(); tree = new Tree4(); } }
public Tree4Brother(Tree4 left, Tree4 right, Tree4 up, Tree4 down) { brothers = new Tree4[4]; brothers[(int)Dir.Left] = left; brothers[(int)Dir.Right] = right; brothers[(int)Dir.Up] = up; brothers[(int)Dir.Down] = down; }
public Tree4() { objs = new List <NetData>(SplitSize + 1); root = this; //size = MaxSize; border = new Tree4Border(new Fixed2(0, 0), new FixedNumber(MaxSize)); brother = new Tree4Brother(); collisonInfo = new CollisonInfo(); depth = 0; }
/// <summary> /// 初始化节点信息 /// </summary> /// <param name="depth">当前深度</param> /// <param name="border">边界类对象</param> /// <param name="brother">邻居类对象</param> public Tree4Child(int depth, Tree4Border border, Tree4Brother brother) { trees = new Tree4[4]; Tree4Border[] borders = border.Split(); for (int i = 0; i < 4; i++) { trees[i] = new Tree4(depth, borders[i]); } trees[(int)Pos.LeftUp].brother = new Tree4Brother(brother.Left, RightUp, brother.Up, LeftDown); trees[(int)Pos.LeftDown].brother = new Tree4Brother(brother.Left, RightDown, LeftUp, brother.Down); trees[(int)Pos.RightUp].brother = new Tree4Brother(LeftUp, brother.Right, brother.Up, RightDown); trees[(int)Pos.RightDown].brother = new Tree4Brother(LeftDown, brother.Right, RightUp, brother.Down); }
/// <summary> /// 碰撞检测 /// </summary> /// <param name="tree">检测的节点</param> /// <returns>碰撞的对象</returns> public Dictionary <NetData, List <NetData> > Check(Tree4 tree) { if (!active && InputCenter.Time <= lastCheckTime) { return(checkList); } checkList.Clear(); int count = tree.objs.Count; var objs = tree.objs; for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (objs[i] != objs[j] && ShapPhysics.Check(objs[i], objs[j])) { if (checkList.ContainsKey(objs[i])) { checkList[objs[i]].Add(objs[j]); } else { checkList.Add(objs[i], new List <NetData>()); checkList[objs[i]].Add(objs[j]); } if (checkList.ContainsKey(objs[j])) { checkList[objs[j]].Add(objs[i]); } else { checkList.Add(objs[j], new List <NetData>()); checkList[objs[j]].Add(objs[i]); } } } } lastCheckTime = InputCenter.Time; active = false; return(checkList); }
public void PhysicsEffect() { if (data.Shap == null) { return; } if (data.isTrigger || !data.rigibody.CheckCollision(data)) { if (_position != _lastPos || _rotation != _lastRota) { _lastPos = _position; _lastRota = _rotation; data.Shap.ResetSize(); Tree4.Move(data); } } else { _rotation = _lastRota; _position = _lastPos; } }
public static void Check(Tree4 tree) { if (!tree.collisonInfo.active) { return; } int count = tree.objs.Count; var objs = tree.objs; for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (objs[i] != objs[j] && ShapPhysics.Check(objs[i], objs[j])) { objs[i].physics.collisonDatas.Add(objs[j]); objs[j].physics.collisonDatas.Add(objs[i]); } } } //lastCheckTime = InputCenter.Time; tree.collisonInfo.active = false; }
/// <summary> /// 移除对象 /// </summary> /// <param name="obj">游戏对象</param> public void Remove(NetData obj) { shaps.Remove(obj); Tree4.Remove(obj); }
//GJK算法原理 //两个物体进行明可夫斯基差操作 得到的新图形形状包含原点则这两个图形的是相交的 /// <summary> /// 立即检测两个物体是否发生细节碰撞 /// 先包围盒检测(粗略) 后GJK碰撞检测(细节) /// </summary> /// <param name="a">检测对象a</param> /// <param name="b">检测对象b</param> /// <returns>是否碰撞</returns> public static bool Check(NetData a, NetData b) { return(Tree4.BoxCheck(a, b) && GJKCheck(a.Shap, b.Shap));//;// xB&&yB; }