private void RayCast() { _rayActor = null; RayCastInput input = _rayCastInput; // Ray cast against the dynamic tree. _tree.RayCast(RayCastCallback, ref input); // Brute force ray cast. Actor bruteActor = null; RayCastOutput bruteOutput = new RayCastOutput(); for (int i = 0; i < ActorCount; ++i) { if (_actors[i].ProxyId == -1) { continue; } RayCastOutput output; bool hit = _actors[i].AABB.RayCast(out output, ref input); if (hit) { bruteActor = _actors[i]; bruteOutput = output; input.MaxFraction = output.Fraction; } } if (bruteActor != null) { Debug.Assert(bruteOutput.Fraction == _rayCastOutput.Fraction); } }
private void RayCast() { _rayActor = null; RayCastInput input = _rayCastInput; // Ray cast against the dynamic tree. _tree.RayCast(RayCastCallback, ref input); // Brute force ray cast. Actor bruteActor = null; RayCastOutput bruteOutput = default; for (int i = 0; i < _actorCount; ++i) { if (_actors[i].proxyId == DynamicTree <Actor> .NullNode) { continue; } RayCastOutput output; bool hit = _actors[i].aabb.RayCast(ref input, out output); if (hit) { bruteActor = _actors[i]; bruteOutput = output; input.MaxFraction = output.Fraction; } } if (bruteActor != null) { Debug.Assert(bruteOutput.Fraction == _rayCastOutput.Fraction); } }
void RayCast() { _rayActor = null; RayCastInput input = _rayCastInput; // Ray cast against the dynamic tree. _tree.RayCast(RayCastCallback, ref input); // Brute force ray cast. //Actor bruteActor = null; //RayCastOutput bruteOutput; for (int i = 0; i < e_actorCount; ++i) { if (_actors[i].proxyId == -1) { continue; } RayCastOutput output; bool hit = _actors[i].aabb.RayCast(out output, ref input); if (hit) { //bruteActor = _actors[i]; //bruteOutput = output; input.maxFraction = output.fraction; } } }
private void RayCast() { _rayActor = null; RayCastInput input = _rayCastInput; // Ray cast against the dynamic tree. _tree.RayCast(RayCastCallback, ref input); // Brute force ray cast. Actor bruteActor = null; RayCastOutput bruteOutput = new RayCastOutput(); for (int i = 0; i < ActorCount; ++i) { if (_actors[i].ProxyId == -1) { continue; } bool hit = _actors[i].AABB.RayCast(ref input, out RayCastOutput output);
// Use this for initialization void Start() { return; func = callBack; //int count = 0; //for (int i = 0; i < 100; i++) //{ // var g = GameObject.CreatePrimitive(PrimitiveType.Cube); // g.transform.position = new Vector3(Random.Range(0, 100), 0, Random.Range(0, 100)); //} System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //sw.Start(); //for (int i = 0; i < 100; i++) //{ // Ray r = new Ray(); // r.origin = new Vector3(Random.Range(0, 50),0, Random.Range(0, 50)); // r.direction = new Vector3(Random.Range(0, 1f), 0, Random.Range(0, 1f)); // r.direction = r.direction.normalized; // var hit = Physics.Raycast(r, 100, -1); // // Debug.DrawLine(r.origin, r.direction*100+r.origin, Color.red, 10); // if (hit) count++; //} // Debug.Log(sw.ElapsedMilliseconds); //return; Vector2d[] vs = new Vector2d[4]; for (int i = 0; i < 100; i++) { var center = new Vector2d(Random.Range(0, 100), Random.Range(0, 100)); var aabb = new AABB(center, FixedMath.One * 2, FixedMath.One * 2); FixtureProxy fp = new FixtureProxy(); long angle = FixedMath.One * (int)(Random.Range(0, 359)); Vector2d a = -aabb.Extents; Vector2d b = a + new Vector2d(0, aabb.Height); Vector2d c = aabb.Extents; Vector2d d = a + new Vector2d(aabb.Width, 0); var halfw = aabb.Width / 2; var halfh = aabb.Height / 2; var radius = FixedMath.Sqrt((halfw).Mul(halfw) + halfh.Mul(halfh)); a = RotatePosi(a, angle); b = RotatePosi(b, angle); c = RotatePosi(c, angle); d = RotatePosi(d, angle); vs[0] = a; vs[1] = b; vs[2] = c; vs[3] = d; Vector2d min = Vector2d.Min(vs) + center; Vector2d max = Vector2d.Max(vs) + center; DLog.Log(radius.ToFloat().ToString()); var outteraabb = new AABB(center, radius * 2, radius * 2); fp.AABB = aabb; fp.Fixture = new Transform2d(ref center, ref angle); int id = tree.AddProxy(ref outteraabb, fp); tree.MoveProxy(id, ref outteraabb, Vector2d.zero); DrawFixtureProxy(fp); DrawAABB(outteraabb); } //var bcs = GameObject.FindObjectsOfType<BoxCollider>(); //for (int i = 0; i < bcs.Length; i++) //{ // var bc = bcs[i]; // var aabb = new AABB(new Vector2d(bc.transform.position), FixedMath.One, FixedMath.One); // FixtureProxy fp = new FixtureProxy(); // fp.AABB = aabb; // long angle = FixedMath.One * (int)(bc.transform.eulerAngles.y); // Vector2d p = new Vector2d(bc.transform.position); // fp.Fixture = new Transform2d(ref p, ref angle); // tree.AddProxy(ref aabb, fp); // DrawFixtureProxy(fp); //} // sw.Reset(); sw.Start(); for (int i = 0; i < 1; i++) { RayCastInput input = new RayCastInput(); input.Point1 = new Vector2d(Random.Range(0, 50) * FixedMath.One, Random.Range(0, 50) * FixedMath.One); input.Point2 = new Vector2d(Random.Range(50, 100) * FixedMath.One, Random.Range(50, 100) * FixedMath.One); NewSphere(input.Point1.ToVector3(), "start"); NewSphere(input.Point2.ToVector3(), "end"); input.MaxFraction = FixedMath.One; DrawLine(input); tree.RayCast(callBack, ref input); } Debug.Log(sw.ElapsedMilliseconds); }
public PhysicsOutput RayCast(RayCastInput input) { output.EndIndex = 0; PhysicsTree.RayCast(RayCastCallback, ref input); return(output); }