C# / XNA - Bounding Circle Collision (Micro) Optimization? -


i've been working on simple space shooter, , have gotten point in project terribly written code slowing things down. after running eqatec, can see majority of problem in icky check on collision detection. considering putting in quadtree, majority of collisions on asteroids, move around lot (would require lot of updating). next alternative micro-optimizing collision check itself. here is:

    public bool iscirclecolliding(gameobject obj) //simple bounding circle collision detection check     {         float distance = vector2.distance(this.worldcenter, obj.worldcenter);         int totalradii = collisionradius + obj.collisionradius;          if (distance < totalradii)             return true;         return false;     } 

i've heard vector2.distance involves costly sqrt, there way avoid that? or there way approximate distance using fancy calculation? more speed, essentially.

also, unrelated actual question, there method (other quadtrees) spatial partitioning of fast-moving objects?

compute square of distance instead of actual distance, , compare square of collision threshold. should bit faster. if asteroids same size, can reuse same value collision threshold without recomputing it.

another useful trick first simple check based on bounding boxes, , compute distance if bounding boxes intersect. if don't, know (for cheap) 2 objects aren't colliding.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -