Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: 2D and Collision Detection

  1. #1
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    2D and Collision Detection

    This is a follow on from here

    http://community.thinbasic.com/index.php?topic=947.0

    I use a simple technique for collision at the moment, tile based.

    think of it like this say I have a tile map of a screen 10x10 tiles

    [code=ini]
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 1 3 0 0 0 0
    0 0 0 1 2 2 3 0 0 0
    0 1 2 2 2 2 2 2 3 0
    [/code]

    I then make a collision map

    [code=ini]
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0
    0 0 0 0 1 1 0 0 0 0
    0 0 0 1 1 1 1 0 0 0
    0 1 1 1 1 1 1 1 1 0
    [/code]

    I use a collision map because I might want to have invisable platforms or graphics that are not platforms (sneaky).

    So I know my player x and y positions using that I find my position on the collision map and test up, down, left, right and do whats required.

    I am thinking about doubling up on my collision map that will improve detection.

    This method is quicker than pixel perfect collision and most time you will get away with it.

    Good luck


    Mike


    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: 2D and Collision Detection

    Thanks for sharing,

    Pixel perfect collision is ... pixel perfect but also can be quite slow.
    Your approach looks good.

    Numbers in tile map mean textures?


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: 2D and Collision Detection

    If there is some new functionality you need let me know.
    For example, some matrix compare or array scan or whatever, even strange one but can be enough general to be a keyword.
    This can speed up such data compare a lot.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: 2D and Collision Detection

    That's a cool technique. Clever idea for sure!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: 2D and Collision Detection

    Such a collision maps could be useful in generall way,
    for labyrinths and similar.

    And it would be a bit too much to use ODE for it, as it would be like using tank to kill a mosquito.

    TBGL collision arsenal is kind of poor now , so I am open to any general purpose additions there.


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: 2D and Collision Detection

    @Petr. I keep it simple and use the texture number and tile numbering the same.

    Tile based collision is an old idea that has been around since early games so I can't take credit for it.

    I dont know if opengl can perform anything like collision.

    I remember on the amiga you could do collision using the blitter chip.

    First you make a mask of your character which is 1 bitplane(2 colour) and do the same for the level graphics then do the blit operation with a logical "AND" with the 2 channels and checking the ZERO FLAG for collision.

    I dont know if the blitter function of modern video cards have this feature??

    something to read

    http://www.geocities.com/SiliconVall...520/tutor.html
    http://people.ifm.liu.se/ulfek/bitmask/
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  7. #7

    Re: 2D and Collision Detection

    There was a tutorial on the 'bitmask' method of collision detection in an early edition of the Amiga Magazine 'Amiga Format'.

    You can download the full tutorial here. (5.72 MB)

    The collision detection section is in part 6.
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  8. #8
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: 2D and Collision Detection

    Ive been reviewing the opengl commands available and was wondering if something like this might work.

    start with a clear frame

    using a bitmask of the player and level gfx.
    set glLogicOP to GL_AND
    now only draw the quad directly below the player
    now draw the player

    this is where I dont see a way to check

    If its worked when the player has overlapped the level gfx it should only set the those bits so you have a collision.

    thats a rough idea what does everyone think?

    I was wondering glFeedbackBuffer could be used but I dont really understand its use.
    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: 2D and Collision Detection

    Hi Abraxas,

    OpenGL is just graphic library, so I doubt so. But I will check.
    Thanks to both you and Abraxas for provided sources, I will study them very soon and report back.

    There is a way to check how many pixels are on screen after the logical op, for example using glReadPixels, but this is sadly performance killer, and higher the resolution, bigger problem...

    That one for VisualBASIC seems to be GDI oriented, so not usable for TBGL/OpenGL, but as I said, will check.
    You gave me really interesting ideas


    Thanks a lot,
    Petr


    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #10
    thinBasic MVPs
    Join Date
    May 2007
    Location
    UK
    Posts
    1,427
    Rep Power
    159

    Re: 2D and Collision Detection

    Petr I found this http://graphics.stanford.edu/~tolis/...are/asteroids/

    read the section on collision detection I didnt think about using the depth buffer. I will look at that when I get time.

    Home Desktop : Windows 7 - Intel Pentium (D) - 3.0 Ghz - 2GB - Geforce 6800GS
    Home Laptop : WinXP Pro SP3 - Intel Centrino Duo - 1.73 Ghz - 2 GB - Intel GMA 950
    Home Laptop : Windows 10 - Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz, 2401 Mhz, 2 Core(s), 4 Logical Processor(s) - 4 GB - Intel HD 4400
    Work Desktop : Windows 10 - Intel I7 - 4 Ghz - 8GB - Quadro Fx 370

Page 1 of 2 12 LastLast

Similar Threads

  1. TBGL sprite collision; I want to tune the box2circle collision a bit
    By Michael Hartlef in forum TBGL module by Petr Schreiber
    Replies: 3
    Last Post: 31-07-2009, 23:36

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •