/// <summary> /// 射线 /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public IEnumerable <MGFObject> RayCast2D(Fix64Vector2 start, Fix64Vector2 end) { HashSet <MGFObject> ls = new HashSet <MGFObject>(); foreach (var item in m_Objects) { Fix64Vector2 hit; Fix64Vector2[] vertex = item.GetVertex(); Fix64Vector2[] vertexN = new Fix64Vector2[vertex.Length]; for (int j = 0; j < vertexN.Length; j++) { vertexN[j] = vertex[j] + item.GetPos(); } for (int j = 0; j < 4; j++) { int nt = j + 1; if (j == 3) { nt = 0; } if (MGFPhysics.lineIntersection(start, end, vertexN[j], vertexN[nt], out hit)) { Debug.Log(item.name + " line P1" + vertexN[j] + " P2 " + vertexN[nt] + " hit " + hit); ls.Add(item); break; } } } return(ls); }
/// <summary> /// 射线 /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public List <MGFObject> RayCast2D(Fix64Vector2 start, Fix64Vector2 end) { List <MGFObject> ls = new List <MGFObject>(); for (int i = 0; i < m_Objects.Count; i++) { Fix64Vector2 hit; Fix64Vector2[] vertex = m_Objects[i].GetVertex(); Fix64Vector2[] vertexN = new Fix64Vector2[vertex.Length]; for (int j = 0; j < vertexN.Length; j++) { vertexN[j] = vertex[j] + m_Objects[i].GetPos(); } for (int j = 0; j < 4; j++) { int nt = j + 1; if (j == 3) { nt = 0; } if (MGFPhysics.lineIntersection(start, end, vertexN[j], vertexN[nt], out hit)) { Debug.Log(m_Objects[i].name + " line P1" + vertexN[j] + " P2 " + vertexN[nt] + " hit " + hit); ls.Add(m_Objects[i]); break; } } } return(ls); }