Jump to content
  • Advertisement
Sign in to follow this  
pat_a_dog

Polygon collision C++

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

I am quite new to game development, however I couldn't find the answer by googling, so I decided to ask you.

I am making my first demo project. I'm writing it in C++ with DirectX9 libraries. It's sort of like a Diablo or Fallout style view game. The map is drawn, the characters are drawn onto the map, everything moves, the characters interact with the use of rectangle collision detection. All works fine here. However then I decided to add buildings. And the buildings I've decided to add are at an irregular angle (see attached file). Now in order to detect when I need overlapping to occur, and when I need the characters to bump into the buildings I figure I should use polygons that will define the area of the building that needs to be in front of the character. Sort of an invisible irregular rectangle. And as the building itself will be drawn in front of the character I won't need to worry about the rest.

The problem is that I can't for the life of me figure out how to detect polygon to rectangle collisions. To be completely honest I can't even figure out how to draw a polygon in a nice clean easy way (like with rectangles).
I was hoping you could help me out. Or alternatively provide a hint for a different solution of my problem. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
If your game is isometric, as the attached image suggests, then you can treat everything internally as rectangles anyway, because that's really what you're representing. Then just work out a transformation from your 'internal' X-Y grid to the isometric view. This works out to be a simple scaling on the Screen axes for each of your World axes.


ie
screen_x = world_x * world_x_to_screen_x + world_y * world_y_to_screen_x
etc.

[edited for clarity]

Share this post


Link to post
Share on other sites
Why didn't I think of that? Thanks, I'll try it.

If your game is isometric, as the attached image suggests, then you can treat everything internally as rectangles anyway, because that's really what you're representing. Then just work out a transformation from your 'internal' X-Y grid to the isometric view. This works out to be a simple scaling on the Screen axes for each of your World axes.


ie
screen_x = world_x * world_to_screen_x + world_y + world_to_screen_y
etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!