Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Coding effective Geometry wars Pacifism collision help.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tyuo9980




PostPosted: Mon May 09, 2011 10:01 pm   Post subject: Coding effective Geometry wars Pacifism collision help.

how would i be able to make something very efficient and similar to the collision of the blue diamond pieces in the game geometry wars pacifism?

i am currently experimenting with calculating the distance between each object but it just slows down the computer too much.

video of the game:
http://www.youtube.com/watch?v=baMmw29xtEw
Sponsor
Sponsor
Sponsor
sponsor
mirhagk




PostPosted: Tue May 10, 2011 7:31 am   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

The distnace between each object can actually be one of the fastest algorithms available. it's circular collision detection, which is one of the best.

If your having difficulty I'll give you a couple tips
1. The distance between two circles must be less than the radius, and how do you find the distance between 2 points?
2. Since one side of the equation needs to be square rooted (which is very costly), you could instead just square the other side (which is alot cheaper)
tyuo9980




PostPosted: Tue May 10, 2011 8:29 am   Post subject: Re: RE:Coding effective Geometry wars Pacifism collision help.

mirhagk @ Tue May 10, 2011 7:31 am wrote:
The distnace between each object can actually be one of the fastest algorithms available. it's circular collision detection, which is one of the best.

If your having difficulty I'll give you a couple tips
1. The distance between two circles must be less than the radius, and how do you find the distance between 2 points?
2. Since one side of the equation needs to be square rooted (which is very costly), you could instead just square the other side (which is alot cheaper)


1. using distance equation.
2. i have to use square root. you cant square a variable that you don't know the variable of.

im looking for a similar detection to the actual game.
mirhagk




PostPosted: Tue May 10, 2011 8:33 am   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

No you don't have to square root it. the distance equation is basically

c^2=a^2+b^2
simply equate c^2 to radius^2 and you have
if (a^2+b^2<radius^2) then
no square roots are neccassary.
tyuo9980




PostPosted: Tue May 10, 2011 9:21 am   Post subject: Re: RE:Coding effective Geometry wars Pacifism collision help.

mirhagk @ Tue May 10, 2011 8:33 am wrote:
No you don't have to square root it. the distance equation is basically

c^2=a^2+b^2 <---- Wont work.
simply equate c^2 to radius^2 and you have
if (a^2+b^2<radius^2) then
no square roots are neccassary.


yea ok that gives me a better understanding. thanks. i thought you had to find the distance and compare that. i didnt think about my predifined distance.
Raknarg




PostPosted: Tue May 10, 2011 6:00 pm   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

You know that there's a predefined function for this, right?

Math.Distance (x1, y1, x2, y2) : real

You replace x1, y1 with the coordinates of one object, x2, y2 with the other and it gives you the total distance in real.
mirhagk




PostPosted: Tue May 10, 2011 6:52 pm   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

yeah, the distance function does square root though, which takes up more CPU time, which generally won't matter, but for tight collision detection it will for sure.
XZNZ




PostPosted: Sun May 15, 2011 8:48 pm   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

hey
without using sqrt function multiply by 0.5
and
x * x instead of x^2 will save a lot of time
Sponsor
Sponsor
Sponsor
sponsor
HRI




PostPosted: Mon May 16, 2011 10:00 am   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

I think you mean raise it to the power of 0.5 (i.e. x^0.5 = sqrt (x))
Tony




PostPosted: Mon May 16, 2011 11:52 am   Post subject: RE:Coding effective Geometry wars Pacifism collision help.

floating point powers are still computationally intensive; and as mentioned above, unnecessary. Good point on x*x part -- it is sufficient to go with
code:

if (a*a + b*b < radius*radius) then

If the radius of an object is constant, the radius^2 value could be stored as well.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: