/// <summary> /// 根据旋转计算新的包围盒大小 与 点的位置 /// </summary> public void ResetSize() { left = _points[0].Rotate(rotation).x; right = _points[0].Rotate(rotation).x; up = _points[0].Rotate(rotation).y; down = _points[0].Rotate(rotation).y; for (int i = 0; i < _points.Length; i++) { if (_points[i].Rotate(rotation).x < left) { left = _points[i].Rotate(rotation).x; } if (_points[i].Rotate(rotation).x > right) { right = _points[i].Rotate(rotation).x; } if (_points[i].Rotate(rotation).y < down) { down = _points[i].Rotate(rotation).y; } if (_points[i].Rotate(rotation).y > up) { up = _points[i].Rotate(rotation).y; } } width = FixedNumber.Max(FixedNumber.Abs(left), FixedNumber.Abs(right)) * 2; height = FixedNumber.Max(FixedNumber.Abs(up), FixedNumber.Abs(down)) * 2; }
public override FixedNumber getRatio() { FixedNumber r = new FixedNumber(); r.SetValue(getInt64()); return(r); }
public static RayShap GetRay(Fixed2 origin, Fixed2 direction, FixedNumber length) { var shap = new RayShap(direction.normalized * length); shap._position = origin; return(shap); }
public static FixedNumber Abs(FixedNumber P1) { FixedNumber tmp; tmp.m_Bits = Math.Abs(P1.m_Bits); return(tmp); }
public RayShap ResetDirection(Fixed2 origin, Fixed2 direction, FixedNumber length) { position = origin; _points[1] = direction * length; ResetSize(); return(this); }
public static FixedNumber Sqrt(FixedNumber p1) { FixedNumber tmp; Int64 ltmp = p1.m_Bits * (1 << Fix_Fracbits); tmp.m_Bits = (Int64)Math.Sqrt(ltmp); return(tmp); }
public bool Equals(FixedNumber right) { if (m_Bits == right.m_Bits) { return(true); } return(false); }
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 Fixed2 Rotate(FixedNumber value) { FixedNumber tx, ty; tx = MathFixed.CosAngle(value) * x - y * MathFixed.SinAngle(value); ty = MathFixed.CosAngle(value) * y + x * MathFixed.SinAngle(value); // Debug.Log("f:" + f + "sin90" + Mathf.Sin(90) + "cos90" + (Math.Cos(90))); //1,0 tx=1*0-0 ty return(new Fixed2(tx, ty)); }
public static bool BoxCheck(ShapBase objA, ShapBase objB) { if (FixedNumber.Abs((objA.position.x - objB.position.x)) < (objA.width + objB.width) / 2 && FixedNumber.Abs((objA.position.y - objB.position.y)) < (objA.height + objB.height) / 2 ) { return(true); } return(false); }
public static bool BoxCheck(NetData objA, NetData objB) { if (FixedNumber.Abs((objA.transform.Position.x - objB.transform.Position.x)) < (objA.Width + objB.Width) / 2 && FixedNumber.Abs((objA.transform.Position.y - objB.transform.Position.y)) < (objA.Height + objB.Height) / 2 ) { return(true); } return(false); }
protected static FixedNumber GetSinTab(FixedNumber r) { FixedNumber i = new FixedNumber(r.ToInt()); //UnityEngine.Debug.Log(i.ToInt()); if (i.ToInt() == _m_SinTab.Count - 1) { return(_m_SinTab[(int)i.ToInt()]); } else { // UnityEngine.Debug.Log(i.ToInt()+":"+ _m_SinTab[i.ToInt()]+":"+ Ratio.Lerp(_m_SinTab[i.ToInt()], _m_SinTab[(i + 1).ToInt()], r - i)); return(FixedNumber.Lerp(_m_SinTab[(int)i.ToInt()], _m_SinTab[(int)(i + 1).ToInt()], r - i)); } }
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; }
public static FixedNumber Asin(FixedNumber sin) { if (sin < -1 || sin > 1) { return(new FixedNumber()); } if (sin >= 0) { return(GetAsinTab(sin)); } else { return(-GetAsinTab(-sin)); } }
public FixedNumber ToRotation() { if (x == 0 && y == 0) { return(new FixedNumber()); } FixedNumber sin = this.normalized.y; if (this.x >= 0) { return(MathFixed.Asin(sin) / MathFixed.PI * 180); } else { return(MathFixed.Asin(-sin) / MathFixed.PI * 180 + 180); } }
/// <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 static FixedNumber GetAsinTab(FixedNumber sin) { MathFixed math = Instance; //UnityEngine.Debug.Log("GetAsinTab"); for (int i = _m_SinTab.Count - 1; i >= 0; i--) { if (sin > _m_SinTab[i]) { if (i == _m_SinTab.Count - 1) { return(new FixedNumber(i) / (tabCount / 4) * (PI / 2)); } else { //return new Ratio(i); return(FixedNumber.Lerp(new FixedNumber(i), new FixedNumber(i + 1), (sin - _m_SinTab[i]) / (_m_SinTab[i + 1] - _m_SinTab[i])) / (tabCount / 4) * (PI / 2)); } } } return(new FixedNumber()); }
public static FixedNumber Sin(FixedNumber r) { MathFixed math = Instance; //int tabCount = SinTab.Count*4; FixedNumber result = new FixedNumber(); r = (r * tabCount / 2 / PI); //int n = r.ToInt(); while (r < 0) { r += tabCount; } while (r > tabCount) { r -= tabCount; } if (r >= 0 && r <= tabCount / 4) // 0 ~ PI/2 { result = GetSinTab(r); } else if (r > tabCount / 4 && r < tabCount / 2) // PI/2 ~ PI { r -= new FixedNumber(tabCount / 4); result = GetSinTab(new FixedNumber(tabCount / 4) - r); } else if (r >= tabCount / 2 && r < 3 * tabCount / 4) // PI ~ 3/4*PI { r -= new FixedNumber(tabCount / 2); result = -GetSinTab(r); } else if (r >= 3 * tabCount / 4 && r < tabCount) // 3/4*PI ~ 2*PI { r = new FixedNumber(tabCount) - r; result = -GetSinTab(r); } return(result); }
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 Fixed2 Parse(FixedNumber ratio) { return(new Fixed2(MathFixed.CosAngle(ratio), MathFixed.SinAngle(ratio))); }
public static FixedNumber operator +(float p1, FixedNumber p2) { FixedNumber tmp = p2 + p1; return(tmp); }
public Fixed3(float x, float y, float z) { this.x = new FixedNumber(x); this.y = new FixedNumber(y); this.z = new FixedNumber(z); }
public Fixed3(FixedNumber x, FixedNumber y, FixedNumber z) { this.x = x; this.y = y; this.z = z; }
public FixedNumber Sqrt() { return(FixedNumber.Sqrt(this)); }
//public V3() //{ // this.x = new Ratio(0); // this.y = new Ratio(0); // this.z = new Ratio(0); //} public Fixed3(int x = 0, int y = 0, int z = 0) { this.x = new FixedNumber(x); this.y = new FixedNumber(y); this.z = new FixedNumber(z); }
public FixedNumber Abs() { return(FixedNumber.Abs(this)); }
public static FixedNumber Lerp(FixedNumber a, FixedNumber b, FixedNumber t) { return(a + (b - a) * t); }
public void Reset(Fixed2 position, FixedNumber rotation) { _position = position; _rotation = rotation; }
public static FixedNumber Min(FixedNumber p1, FixedNumber p2) { return(p1.m_Bits < p2.m_Bits ? p1 : p2); }
public static bool Equals(FixedNumber p1, FixedNumber p2) { return((p1.m_Bits == p2.m_Bits) ? true : false); }