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

Author Topic: Physics/Colission  (Read 4321 times)

0 Members and 1 Guest are viewing this topic.

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Physics/Colission
« on: August 21, 2012, 06:16:50 pm »
Hi everyone, I'm hoping to write a 2D game in the near future, using SFML. I almost have rendering down, but now the problem I'm facing is learning how to get collision working. I can't find anything under the SFML 2.0 tutorials and was wondering if SFML even supports it. If anyone could point me in the right direction, I would be very grateful.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Physics/Colission
« Reply #1 on: August 21, 2012, 06:24:33 pm »
SFML is a Simple and Fast Multimedia Library, thus it can handle all the stuff you can find on the feature list. For all the other stuff you'll have to program things on your own or use a diffrent library. You can find some tutorials about collision in the wiki section of SFML or just use google since the topic is generic and not bound to any library nor programming language.

If you need complex physics you can check out Box2D but the itegration with SFML isn't trivial for a beginner.

Btw. It's collision and not colission... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Physics/Colission
« Reply #2 on: August 21, 2012, 06:30:32 pm »
SFML is a Simple and Fast Multimedia Library, thus it can handle all the stuff you can find on the feature list. For all the other stuff you'll have to program things on your own or use a diffrent library. You can find some tutorials about collision in the wiki section of SFML or just use google since the topic is generic and not bound to any library nor programming language.

If you need complex physics you can check out Box2D but the itegration with SFML isn't trivial for a beginner.

Btw. It's collision and not colission... ;)

Ah, stupid typo, my bad haha.

Thank you for the links, I'll look into them.

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Physics/Colission
« Reply #3 on: August 22, 2012, 06:59:04 am »
Sorry for the double post, but I looked into the Wiki and found this:

https://github.com/SFML/SFML/wiki/SourceSimpleCollisionDetection

I included it into my project, but I get a ton of errors, most likely because it was written for a previous SFML. So I need help converting this old code from 1.x to 2.0, if that's in fact, what I need to do.

The source I'm getting errors in are at the bottom of the linked page above.

Also the errors I'm getting....:

   63   IntelliSense: class "sf::Sprite" has no member "TransformToLocal"   c:\users\nick\desktop\rendering\rendering\collision.cpp   118
   64   IntelliSense: class "sf::Sprite" has no member "TransformToLocal"   c:\users\nick\desktop\rendering\rendering\collision.cpp   119
   53   IntelliSense: class "sf::Sprite" has no member "GetSubRect"   c:\users\nick\desktop\rendering\rendering\collision.cpp   106
   54   IntelliSense: class "sf::Sprite" has no member "GetSubRect"   c:\users\nick\desktop\rendering\rendering\collision.cpp   107
   65   IntelliSense: class "sf::Sprite" has no member "GetPixel"   c:\users\nick\desktop\rendering\rendering\collision.cpp   127
   66   IntelliSense: class "sf::Sprite" has no member "GetPixel"   c:\users\nick\desktop\rendering\rendering\collision.cpp   128
   61   IntelliSense: class "sf::Rect<int>" has no member "Top"   c:\users\nick\desktop\rendering\rendering\collision.cpp   116
   60   IntelliSense: class "sf::Rect<int>" has no member "Right"   c:\users\nick\desktop\rendering\rendering\collision.cpp   115
   59   IntelliSense: class "sf::Rect<int>" has no member "Left"   c:\users\nick\desktop\rendering\rendering\collision.cpp   115
   52   IntelliSense: class "sf::Rect<int>" has no member "Intersects"   c:\users\nick\desktop\rendering\rendering\collision.cpp   94
   55   IntelliSense: class "sf::Rect<int>" has no member "GetWidth"   c:\users\nick\desktop\rendering\rendering\collision.cpp   109
   57   IntelliSense: class "sf::Rect<int>" has no member "GetWidth"   c:\users\nick\desktop\rendering\rendering\collision.cpp   110
   56   IntelliSense: class "sf::Rect<int>" has no member "GetHeight"   c:\users\nick\desktop\rendering\rendering\collision.cpp   109
   58   IntelliSense: class "sf::Rect<int>" has no member "GetHeight"   c:\users\nick\desktop\rendering\rendering\collision.cpp   110
   62   IntelliSense: class "sf::Rect<int>" has no member "Bottom"   c:\users\nick\desktop\rendering\rendering\collision.cpp   116
Error   30   error C2228: left of '.y' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   143
Error   34   error C2228: left of '.y' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   144
Error   40   error C2228: left of '.y' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   146
Error   42   error C2228: left of '.y' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   146
Error   28   error C2228: left of '.x' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   143
Error   32   error C2228: left of '.x' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   144
Error   36   error C2228: left of '.x' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   145
Error   38   error C2228: left of '.x' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   145
Error   24   error C2228: left of '.a' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   127
Error   26   error C2228: left of '.a' must have class/struct/union   c:\users\nick\desktop\rendering\rendering\collision.cpp   128
Error   17   error C2039: 'TransformToLocal' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   118
Error   20   error C2039: 'TransformToLocal' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   119
Error   1   error C2039: 'TransformToGlobal' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   20
Error   15   error C2039: 'Top' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   116
Error   14   error C2039: 'Right' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   115
Error   4   error C2039: 'Offset' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   55
Error   13   error C2039: 'Left' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   115
Error   6   error C2039: 'Intersects' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   94
Error   9   error C2039: 'GetWidth' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   109
Error   11   error C2039: 'GetWidth' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   110
Error   7   error C2039: 'GetSubRect' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   106
Error   8   error C2039: 'GetSubRect' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   107
Error   2   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   23
Error   27   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   143
Error   29   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   143
Error   31   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   144
Error   33   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   144
Error   43   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   156
Error   44   error C2039: 'GetSize' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   157
Error   3   error C2039: 'GetRotation' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   25
Error   45   error C2039: 'GetRotation' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   167
Error   46   error C2039: 'GetRotation' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   167
Error   51   error C2039: 'GetRotation' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   179
Error   35   error C2039: 'GetPosition' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   145
Error   37   error C2039: 'GetPosition' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   145
Error   39   error C2039: 'GetPosition' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   146
Error   41   error C2039: 'GetPosition' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   146
Error   49   error C2039: 'GetPosition' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   175
Error   50   error C2039: 'GetPosition' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   177
Error   23   error C2039: 'GetPixel' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   127
Error   25   error C2039: 'GetPixel' : is not a member of 'sf::Sprite'   c:\users\nick\desktop\rendering\rendering\collision.cpp   128
Error   10   error C2039: 'GetHeight' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   109
Error   12   error C2039: 'GetHeight' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   110
Error   16   error C2039: 'Bottom' : is not a member of 'sf::Rect<T>'   c:\users\nick\desktop\rendering\rendering\collision.cpp   116

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Physics/Colission
« Reply #4 on: August 22, 2012, 09:18:05 am »
I don't get your question... ???
If you want to use SFML 1.6 code in your SFML 2 project it's obviouse that it won't work and that you have to convert it. ;)
« Last Edit: August 22, 2012, 08:44:17 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TheVirtualDragon

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Control + Alt + Delete!
Re: Physics/Colission
« Reply #5 on: August 22, 2012, 09:40:35 am »
Converting can get tricky sometimes. I mean, I tried to convert one sfml based file into 2.0 and even after it compiled the program didn't respond properly.

But at a first glance, alot of those errors seem to be because of thr new casing system.
e.g

Code: [Select]
sf::Sprite::GetSize -> sf::Sprite::getSize
//1.6                             2.0

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Physics/Colission
« Reply #6 on: August 22, 2012, 06:50:13 pm »
I don't get your queszmtion... ???
If you want to use SFML 1.6 code in your SFML 2 project it's obviouse that it won't work and that you have to convert it. ;)

Basically I need help with converting to 2.0.

Converting can get tricky sometimes. I mean, I tried to convert one sfml based file into 2.0 and even after it compiled the program didn't respond properly.

But at a first glance, alot of those errors seem to be because of thr new casing system.
e.g

Code: [Select]
sf::Sprite::GetSize -> sf::Sprite::getSize
//1.6                             2.0

I'll try that, see if it works.


EDIT: Well I did what you said, and now I'm down to 25 errors. Here's the source that I edited:

http://pastebin.com/gkMnPEpY

And here are the remaining errors:

   4   IntelliSense: no instance of overloaded function "sf::Rect<T>::intersects [with T=int]" matches the argument list   c:\users\nick\desktop\rendering\rendering\collision.cpp   94
   13   IntelliSense: class "sf::Sprite" has no member "transformToLocal"   c:\users\nick\desktop\rendering\rendering\collision.cpp   118
   14   IntelliSense: class "sf::Sprite" has no member "transformToLocal"   c:\users\nick\desktop\rendering\rendering\collision.cpp   119
   1   IntelliSense: class "sf::Sprite" has no member "transformToGlobal"   c:\users\nick\desktop\rendering\rendering\collision.cpp   20
   5   IntelliSense: class "sf::Sprite" has no member "getSubRect"   c:\users\nick\desktop\rendering\rendering\collision.cpp   106
   6   IntelliSense: class "sf::Sprite" has no member "getSubRect"   c:\users\nick\desktop\rendering\rendering\collision.cpp   107
   2   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   23
   17   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   143
   18   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   143
   19   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   144
   20   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   144
   21   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   156
   22   IntelliSense: class "sf::Sprite" has no member "getSize"   c:\users\nick\desktop\rendering\rendering\collision.cpp   157
   15   IntelliSense: class "sf::Sprite" has no member "getPixel"   c:\users\nick\desktop\rendering\rendering\collision.cpp   127
   16   IntelliSense: class "sf::Sprite" has no member "getPixel"   c:\users\nick\desktop\rendering\rendering\collision.cpp   128
   11   IntelliSense: class "sf::Rect<int>" has no member "right"   c:\users\nick\desktop\rendering\rendering\collision.cpp   115
   3   IntelliSense: class "sf::Rect<int>" has no member "Offset"   c:\users\nick\desktop\rendering\rendering\collision.cpp   55
   7   IntelliSense: class "sf::Rect<int>" has no member "getWidth"   c:\users\nick\desktop\rendering\rendering\collision.cpp   109
   9   IntelliSense: class "sf::Rect<int>" has no member "getWidth"   c:\users\nick\desktop\rendering\rendering\collision.cpp   110
   8   IntelliSense: class "sf::Rect<int>" has no member "getHeight"   c:\users\nick\desktop\rendering\rendering\collision.cpp   109
   10   IntelliSense: class "sf::Rect<int>" has no member "getHeight"   c:\users\nick\desktop\rendering\rendering\collision.cpp   110
   12   IntelliSense: class "sf::Rect<int>" has no member "bottom"   c:\users\nick\desktop\rendering\rendering\collision.cpp   116
« Last Edit: August 22, 2012, 07:00:28 pm by rush905 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Physics/Colission
« Reply #7 on: August 22, 2012, 07:11:47 pm »
For this case there's a documentation which shows you which functions exist and which don't...
i.e. all classes, sf::Rect, sf::Sprite, ...

getSubRect -> getTextureRect
getSize -> getLocalBounds or getGlobalBounds
...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rush905

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: Physics/Colission
« Reply #8 on: August 22, 2012, 07:26:53 pm »
For this case there's a documentation which shows you which functions exist and which don't...
i.e. all classes, sf::Rect, sf::Sprite, ...

getSubRect -> getTextureRect
getSize -> getLocalBounds or getGlobalBounds
...

I'm aware of the documentation, but I don't see anything on what function names have changed to.

EDIT: Alright, I figured out a way to do what I needed. Thank you for all your help.
« Last Edit: August 23, 2012, 06:55:26 am by rush905 »