Archived

This topic is now archived and is closed to further replies.

Check if point is in region

This topic is 5983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I''ve got a fairly simple question : I''m in the process of writing my first game. ( and consequently my first window''s API program ) It''s a Pong Clone, and i have an algorithm that will invariably calculate the angle of deflection of a ball, with respect to an absolute origin located in the middle of the screen. My Question, is how do i determine if the point, representing the middle of the ball, is located in any of the regions , representing the different objects on the game-screen that the ball can bounce off of( which are made by inflating the exhisting shapes ). Note, i will have an array of HRGN objects which i will check via loop every game render. No remorse, No repent We don''''t care, What it meant Another day, Another death Another sorrow, Another breath

Share on other sites
Cecking the middle will not be percice unless your pong is a perfect square, I assume that it is a sphere. Meaning that this middle point will have a radius, hence the closest location that it can be to a wall is

if distance(wall, point) > radius = collision.

You can find the distance by:

float distance = sqrtf(pow(wall.x-point.x,2) + pow(wall.y-point.y,2));

so

collision
else
no collision.

Correct me if I am wrong on thet distance formula, but I''m pretty sure thats it.

Share on other sites
I''ll try to clear things up. I''ve setup a pong game surface where every bouncable object has an inflated region paired with it. these regions are inflated to form regions around each object that are the width of the radius of the ball, so if the center point of the ball falls within these regions, there is a collision. the problem that i''m having, is some of the bounce regions are elliptical, meaning i can''t just use a simple agorithm like :
if( ball.x > rgn.x && ball.y > rgn.y )
I need an algorithm that will check any type of region for a collision. keeping in mind that i probably can''t just check every single unit therein, which would cause a performance problem.

No remorse, No repent
We don''''t care, What it meant
Another day, Another death
Another sorrow, Another breath

Share on other sites
Quick note :
you said that if the distance between the center of the ball and a point on the wall parallel to the radius is greater than the radius itself, there is a collision, or :

|->____________
|
| Distance
| __ <-|
|-> | | <-|
\__/

I think the formula should be :
collision
else....
or :
if ( ! ( distance - radius >= 0 ) )
collision
else.....( a little extraneous )

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 14
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631423
• Total Posts
3000005
×