public RayShap ResetDirection(Fixed2 origin, Fixed2 direction, FixedNumber length) { position = origin; _points[1] = direction * length; ResetSize(); return(this); }
public static RayShap GetRay(Fixed2 origin, Fixed2 direction, FixedNumber length) { var shap = new RayShap(direction.normalized * length); shap._position = origin; return(shap); }
public ShapBase(Fixed2[] points, Fixed2 position, Fixed rotation) { _points = points; this._position = position; this._rotation = rotation; ResetSize(); }
public RayShap(Fixed2 direction) { Fixed2[] v2s = new Fixed2[2]; v2s[0] = Fixed2.zero; v2s[1] = direction; Points = v2s; }
public static bool DistanceLess(Fixed2 a, Fixed2 b, Fixed len) { var xLen = a.x - b.x; var yLen = a.y - b.y; return((xLen * xLen + yLen * yLen) < len * len); }
/// <summary> /// GJK算法的多边形碰撞检测 /// </summary> /// <param name="a">形状a</param> /// <param name="b">形状b</param> /// <returns>是否碰撞</returns> public static bool GJKCheck(ShapBase a, ShapBase b) { Fixed2 direction = a.position - b.position; Simplex s = new Simplex(); s.Push(ShapBase.Support(a, b, direction)); direction = -direction; while (true) //迭代 { s.Push(ShapBase.Support(a, b, direction)); if (s.GetA().Dot(direction) < 0) { return(false); } else { if (s.ContainsOrigin()) { return(true); } else { direction = s.GetDirection(); } } } }
public RayShap(Fixed2 origin, Fixed2 direction, Fixed length) { Fixed2[] v2s = new Fixed2[2]; v2s[0] = Fixed2.zero; v2s[1] = direction.normalized * length; Points = v2s; _position = origin; }
/// <summary> /// 给定方向 给定两个凸体 该函数返回这两个凸体明可夫斯基差形状中的一个点 /// </summary> /// <param name="a">形状a</param> /// <param name="b">形状b</param> /// <param name="direction">迭代方向</param> /// <returns>指定方向内的一点</returns> public static Fixed2 Support(ShapBase a, ShapBase b, Fixed2 direction) { Fixed2 p1 = a.Support(direction); Fixed2 p2 = b.Support(-direction); //Debug.Log("Support{ p1:" + p1 + "p2:" + p2 + "p3:" + (p1 - p2)); return(p1 - p2); }
public BoxShap(FixedNumber x, FixedNumber y) { Fixed2[] v2s = new Fixed2[4]; v2s[0] = new Fixed2(x / 2, y / 2); v2s[1] = new Fixed2(-x / 2, y / 2); v2s[2] = new Fixed2(x / 2, -y / 2); v2s[3] = new Fixed2(-x / 2, -y / 2); Points = v2s; }
public void SetShap(Vector2[] points) { var ps = new Fixed2[points.Length]; for (int i = 0; i < ps.Length; i++) { ps[i] = points[i].ToFixed2(); } Shap = new ShapBase(ps); }
private Fixed2 SetScale(Fixed2 point) { if (data != null) { return(new Fixed2(point.x * data.transform.Scale.x, point.y * data.transform.Scale.y)); } else { return(point); } }
public BoxShap(Fixed x, Fixed y, Fixed2 pos, Fixed rot) { Fixed2[] v2s = new Fixed2[4]; v2s[0] = new Fixed2(x / 2, y / 2); v2s[1] = new Fixed2(-x / 2, y / 2); v2s[2] = new Fixed2(-x / 2, -y / 2); v2s[3] = new Fixed2(x / 2, -y / 2); Points = v2s; _position = pos; _rotation = rot; }
public void SetJoyStickDirection(KeyNum key, Fixed2 direction) { if (joySticks.ContainsKey(key)) { joySticks[key].direction = direction; } else { joySticks.Add(key, new JoyStickKey(key, direction)); } Key.SetKey(true, key); }
public CircleShap(FixedNumber r, int num) { FixedNumber t360 = new FixedNumber(360); FixedNumber tmp = t360 / num; Fixed2[] v2s = new Fixed2[num]; int i = 0; for (FixedNumber tr = new FixedNumber(0); tr < t360 && i < num; tr += tmp, i++) { v2s[i] = Fixed2.Parse(tr) * r; } Points = v2s; }
/// <summary> /// 给定两个凸体 给定迭代方向 该函数返回这两个凸体明可夫斯基差形状中的一个点 /// </summary> /// <param name="direction">迭代方向</param> /// <returns>点</returns> public Fixed2 Support(Fixed2 direction) { int index = 0; FixedNumber maxDot, t; Fixed2 p; p = GetPoint(index); maxDot = Fixed2.Dot(p, direction); for (; index < PointsCount; index++) { t = Fixed2.Dot(GetPoint(index), direction); //Debug.Log(_points[index] + "dot" + direction + "=" + t); if (t > maxDot) { maxDot = t; p = GetPoint(index); } } return(p + position); }
/// <summary> /// 检测是否包含原点 包含原点就发生了碰撞 /// </summary> /// <returns>是否包含原点</returns> public bool ContainsOrigin() { Fixed2 A = GetA(); Fixed2 AO = -A; Fixed2 B = GetB(); Fixed2 AB = B - A; if (points.Count == 3) { Fixed2 C = GetC(); Fixed2 AC = C - A; Fixed2 ABnormal = AC * AB * AB; Fixed2 ACnormal = AB * AC * AC; if (ABnormal.Dot(AO) > 0) { points.Remove(C); d = ABnormal; } else { if (ACnormal.Dot(AO) > 0) { points.Remove(B); d = ACnormal; } else { return(true); } } } else { d = AB * AO * AB; } return(false); }
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 void Push(Fixed2 point) { points.Add(point); }
public List <NetData> OverlapShap(ShapBase shap, Fixed2 position) { shap.position = position; return(OverlapShap(shap)); }
public static Fixed Dot(Fixed2 a, Fixed2 b) { return(a.x * b.x + b.y * a.y); }
//public static V3 operator +(V3 v3,Ratio ratio) //{ //} public Fixed Dot(Fixed2 b) { return(Dot(this, b)); }
//public static V3 operator +(V3 v3,Ratio ratio) //{ //} public FixedNumber Dot(Fixed2 b) { return(Dot(this, b)); }
public void LookAt(Fixed2 target) { Rotation = (target - Position).ToRotation(); }
public void Reset(Fixed2 position, Fixed rotation) { _position = position; _lastPos = position; _rotation = rotation; }
public abstract void push(Fixed2 v2);
public override void push(Fixed2 v2) { push(v2.x.GetValue()); push(v2.y.GetValue()); }
public Tree4Border(Fixed2 center, Fixed size) { this.center = center; this.size = size; }
public void Reset(Fixed2 position, Fixed rotation) { transform.Reset(position, rotation); }
public JoyStickKey(KeyNum key, Fixed2 direction) { this.key = key; this.direction = direction; }
public void Reset(Fixed2 position, FixedNumber rotation) { _position = position; _rotation = rotation; }