Check if point is in region

Started by
2 comments, last by d1corps 22 years, 2 months ago
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
No remorse, No repentWe don''t care, What it meantAnother day, Another deathAnother sorrow, Another breath
Advertisement
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

if (distance > radius)
collision
else
no collision.

Correct me if I am wrong on thet distance formula, but I''m pretty sure thats it.
-------Homepage: http://www.pclx.com
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
No remorse, No repentWe don''t care, What it meantAnother day, Another deathAnother sorrow, Another breath
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
| __ <-|
| / \ | radius
|-> | | <-|
\__/

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

No remorse, No repentWe don''t care, What it meantAnother day, Another deathAnother sorrow, Another breath

This topic is closed to new replies.

Advertisement