Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> Useful Algorithms for Game Design
United States
OniLink10
Posted: Oct 23 2009, 06:58 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


This thread will be for posting useful algorithms and techniques that can help improve your games in many ways. If you have anything you would like to add, please post it here.

Quadtrees: An algorithm to split up an area into quadrants. It allows collision detection to only check for collisions with objects in the same quadrant, and reduces the number of objects the collision detection algorithm needs to check. There are many uses for it, many listed on this Wikipedia page. Quadrants can also be subdivided into sub-quadrants.
Quadtrees work like this:
-Split the Screen into 4 Quadrants.
-Split each Quadrant into 4 more Quadrants.
-Continue splitting until the Quadrants are small enough for you.
-Determine which objects are in which quadrants.
-When doing collision detection(or whatever), only check for collisions(or whatever) with objects in the same quadrants.
This reduces the numbers of objects that you need to check for collisions with significantly. Especially if there are lots of tiles that need to be checked.

Bounding Box Collisions: Checking for collisions between two or more objects based on a Rectangular outline. They are very simple, but not very accurate. Here's how they work.
-For every object of the first type...
--For every object of the second type...
---Create a Rectangle around the border of object 1
---Create a Rectangle around the border of object 2
---If bottom of Rect1 < top of Rect2
---Or if top of Rect1 > bottom of Rect2
---Or if right of Rect1 < bottom of Rect2
---Or if left of Rect1 > right of Rect2
----There is no collision
---Otherwise, there is a collision
This will reduce time used to check for collisions by only checking boxes, instead of Pixel-by-Pixel. A 3D version can be created by adding more checks.

Circular Collisions: Checking for Collisions between two objects based on their distance from each other. This will be simple. We'll just check if the distance between the two "circles" is less than the sum of their radii.
-For every object of the first type...
--For every object of the second type...
---Set a maxdistance variable to the sum the the radii of objects 1 and 2.
---Find the true distance between the objects by using the Pythagorean theorem(distance = sqrt((y2-y1)^2 + (x2-x1)^2)).
---If the true distance is less than the maxdistance, there is a collision.
---Otherwise, there is no collision.
This reduces the need for expensive pixel-perfect algorithms by giving you a quick and easy pixel-perfect circular formula. A 3D version can be made by extending the Pythagorean theorem.

This post has been edited by OniLink10 on Oct 25 2009, 06:21 PM


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
YoManRuLz
Posted: Oct 23 2009, 07:46 PM
Quote Post


sit down, it's just me


Group Icon
Group: Members
Posts: 152
Member No.: 6502
Joined: 6-September 09

Status: (0d) [--]


If you can post an example for us average people, that would be fine


--------------------
PMEmail Poster
Top
United States
Xgoff
Posted: Oct 25 2009, 04:15 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


maybe you should post a couple you know about so people get ideas of what's useful for games


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Bacteriophage
Posted: Oct 25 2009, 04:30 PM
Quote Post


injustice anywhere is a threat to justice everywhere
[*][*][*][*][*]
[*][*][*][*][*]
[*][*][KFC]

Group Icon
Group: Members
Posts: 10716
Member No.: 2411
Joined: 31-July 06

Status: (0d) [--]


i doubt quadtrees and processor-conserving algorithms are useful to your run-of-the-mill m***, tbh


--------------------
PMEmail PosterUsers WebsiteAOLMSN
Top
India
Char
Posted: Oct 25 2009, 04:32 PM
Quote Post


fad was bad
[M][*][*]

Group Icon
Group: Admins
Posts: 2123
Member No.: 2856
Joined: 25-October 06

Status: (0d) [--]


sigh

i still don't get it


--------------------
aa this broke


Make your own | If a level is breaking the rules, note the ID and PM me.
Reference (thanks Frogjester!)
PMEmail PosterUsers WebsiteAOLYahooMSN
Top
United States
Xgoff
Posted: Oct 25 2009, 04:39 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


QUOTE (Bacteriophage @ Oct 25 2009, 03:30 PM)
i doubt quadtrees and processor-conserving algorithms are useful to your run-of-the-mill m***, tbh

they are when you have to write your own collisions ****!


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
OniLink10
Posted: Oct 25 2009, 06:00 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


Added Bounding Box Collisions. A simplified Pixel-by-Pixel(Pixel-Perfect) collision algorithm is coming soon.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
OniLink10
Posted: Oct 25 2009, 06:22 PM
Quote Post


C++ Programmer, Unofficial Physicist, and Unofficial Chemist
[*][*]

Group Icon
Group: Members
Posts: 3920
Member No.: 4907
Joined: 19-February 08

Status: (0d) [--]


Circular collisions have been added.


--------------------
QUOTE (Xgoff @ Sep 10 2009 @ 06:11 PM)
did you try hello's engine

make sure to not ****ing change anything before using it!
PMEmail PosterUsers WebsiteYahoo
Top
United States
Bacteriophage
Posted: Oct 25 2009, 06:28 PM
Quote Post


injustice anywhere is a threat to justice everywhere
[*][*][*][*][*]
[*][*][*][*][*]
[*][*][KFC]

Group Icon
Group: Members
Posts: 10716
Member No.: 2411
Joined: 31-July 06

Status: (0d) [--]


QUOTE (Xgoff @ Oct 25 2009, 02:39 PM)
they are when you have to write your own collisions ****!

Run-of-the-mill m***s write their own collisions ****?

I'm proud of you guys!


--------------------
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Xgoff
Posted: Oct 25 2009, 06:31 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


how about non-axis-aligned bounding box collisions, and extending your circular collision example to handle potentially rotated ellipses

This post has been edited by Xgoff on Oct 25 2009, 06:31 PM


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth:
DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message
DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it
DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep
DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot
this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence
NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above

QUOTE
(5:25:58 PM) Mikau: xgoff
(5:26:00 PM) Mikau: guess what
(5:26:04 PM) Xgoff: chicken butt
(5:26:09 PM) Mikau: **** you
PMEmail PosterUsers WebsiteAOLMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0665 ]   [ 15 queries used ]   [ GZIP Enabled ]   [ Server Load: 1.67 ]