Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is there a way to rotate sf::Rects?  (Read 2358 times)

0 Members and 1 Guest are viewing this topic.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Is there a way to rotate sf::Rects?
« on: May 15, 2012, 01:11:22 am »
Hello,
I'm developing a World War II shooter.  Look at this screenshot:

The red line represents where the bullet of the rifle will go.  Due to low FPS when trying an actual bullet approach, I've gone with a hitscan approach.
Here is where the problem comes in: I don't want my bullet to go through solid blocks.  The first step in coding this is to find where the bullet will actually go.  My typical method of collision detection (create rects of the 2 objects that might collide, compare their edges) won't work, since I'm dealing with a line (actually a thin, rotated sf::RectangeShape, but anyways), not a box.  What I need is a way to rotate a sf::Rect so it would fit the profile of the line.
Is there a way to do this?  Other solutions are also appreciated.  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is there a way to rotate sf::Rects?
« Reply #1 on: May 15, 2012, 08:01:29 am »
A line-rect collision test is much simpler than a rect-rect one, so why do you want to make things more complicated?
Laurent Gomila - SFML developer

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: Is there a way to rotate sf::Rects?
« Reply #2 on: May 15, 2012, 04:27:38 pm »
I'm using SFML 2, so would I use a vertex array and the getBounds() function?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Is there a way to rotate sf::Rects?
« Reply #3 on: May 15, 2012, 04:58:44 pm »
Why? You have a line and a rectangle, so just write a line-rect collision detection function. It's very simple.
Laurent Gomila - SFML developer

 

anything