Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-25-2008, 03:09 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Rep Power: 3
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Question Geometry, Projectiles, efficency

It is rather difficult to put it short. But I will try:

In my game, I use geometry to decide collision between objects, as it is the fastest method. So, if I want to check, if a pistol shot hits ball, I just make a few tests to see if the line intersects with circle (The pistol shot is 1 pixel big). But if I want to have bigger projectile, say plasma ball, I have to do at least two tests, but three should be actually. Why? Wel, look at the picture.

Here we have a plasma ball (The red circle) flying left. There is a black ball, and black rectangle too. Now we can clearly see, that the plasma DO hits the ball and the rectangle. Now, if I only make one test, ie. geometry check LineVSCircle where line is the middle path of plasma, it won't hit. So that's why I have to do more checks. But if I'll make only two checks (the Top and the bottom path, the green lines), then LineVSRectangle won't detect, that plasma hits the rectangle. So I have to do three checks. But that's not the only problem.
Every time I do detection if projectile hits enemies I have to check which LINES hit the enemy, then determine the closest one, and then check if the Hit enemy is the closest enemy lying on the projectile path. The whole code looks basically like this:
Code:
line1[]=Hit Check against the enemy and top line (Upper green)
line1[]=Hit Check against the enemy and middle line (Middle white)
line1[]=Hit Check against the enemy and bottom line (Lower green)
//Here I note distance if the hit occured
if line1Hit then line1Dist=distance(startPosition,intersectionPosition)
if line2Hit then line2Dist=distance(startPosition,intersectionPosition)
if line3Hit then line3Dist=distance(startPosition,intersectionPosition)

//Here I have to check which was the closest, which is quite crumped thing
if line1Hit and (!line2Hit or line1Dist<line2Dist){
 if line1Hit and (!line3Hit or line1Dist<line3Dist){
  intersectionPoint=line1Intersection
 }
} elseif line2Hit and (!line3Hit or line2Dist<line3Dist){
 intersectionPoint=line2Intersection
} else {
 if line3Hit{intersectionPoint=line3Intersection}
}
/If there is intersection point, then check if this hit is the closest
if intersectionPoint{
 tempDistance=distance(startPoint,intesectionPoint)
 if tempDistance<closestHitEnemyDistance{
  closestHitEnemyDistance=tempDistance
  hitEnemyID=ID
 }
}
Tha would be something like this. It ain't no pretty I'm afraid, and it is slow. So What I wanted to ask, if there is a faster way to do something like this?

Thanks in advance and thanks for reading. If something is unclear just ask, I'll appreciate all help ^^

Last edited by Maurice_Z; 03-25-2008 at 03:13 PM. Reason: Typo in title
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-25-2008, 04:22 PM
2stamlers's Avatar   
2stamlers 2stamlers is offline
Learning Programmer
 
Join Date: Jul 2007
Posts: 36
Rep Power: 4
2stamlers will become famous soon enough
Default Re: Geometry, Projectiles, efficency

You need to read a little bit more about collision detection as I am sure there is better way to do it then your way. I am sure that there are developed algorithms and you just pick the one that suits your needs. Just google it.

Cheers and good luck with the code.
__________________
Are you bored? Play dirt bike game online now!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-26-2008, 02:14 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Rep Power: 3
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default Re: Geometry, Projectiles, efficency

Easy to say. I've been crawling google many times, quite often without a result. This time too. Or it might be, that I've just missed a link, but I don't think so.
Well, I'll try to look some more on Google, but if anyone can help me here I'd be mostly glad .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Geometry Circle-Line Inters. Maurice_Z Programming Theory 0 11-28-2007 01:30 PM


All times are GMT -5. The time now is 05:18 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads