Spatial Partition Sliding Collision (Tech Demo)

Started by kevin, June 10, 2005, 01:32:56 PM

Previous topic - Next topic

kevin

 Here's some test sliding collision code running in PlayBASIC.  In this example the user controls the circle which will slide off any of the textured surfaces in the scene.  The sliding isn't currently built into PB, but that's the objective..


Notes About Sliding Collision:

A) Sliding collision is based upon the assumption that the player is
   never positioned inside a solid region. As the sliding works via
   keeping the player on one side of the wall segments (the outside).
   If the player is on the inside of a region, the walls that define the
   solid region are ignored as their back facing the player.

B) When the player leaves then screen and is repositioned on the other
  side, it's likely that they will be position inside another
  a region and thus appear to walk through it. See (A)


C) Since the scene is created randomly It's entirely possible the player
  can get stuck between some regions.



Demo Controls:
==============


        F1 Key = Lock FPS Rate to 85
        F2 Key = Unlock FPS rate
        F3 Key = Toggle Display Region Walls & normals

     Space Key = Randomly Reposition the boxes

     Arrow Keys= To Control the player (the circle thing :) ),

                     UP    = Forward
                     Down  = Back
                     Left  = Turn Left
                     right = Turn Right
 
       Esc Key = Exit Demo



Download

Download PlayBasic Sliding Collision Test) (login required)


kevin

#1
Sliding Collision/ Ray Collision With Spatial Partitioning

 The following picture (less pretty this time :) ) is of another collision tech demo, the focus in this version over the previous one, has been the inclusion of the partition system to minimized collision overhead.   Previously the sliding routines would check all the lines in the world for intersections.  This is obviously going to be slow and tedious process, as the majority of the time the lines your checking are too far away, so their not relevant for this test.   Thus the partitioning allows me to easy calc a short list of walls that the object might collide with. Then run sliding upon that.  

 To extend upon that, i've built in specially some optimized ray intersection routines for the spatial buffer.  These intersections can calc the nearest intersection point from a shortlist of possibles, while totally ignoring regions the ray doesn't pass through! , rather than the brute force (check everything) method.   Resulting in much faster ray intersections  

 Currently the system is a hybrid of native PB code and some new built in intersection functions, since i'm just testing out the implementation at this point.  But this is what worlds will be used for.  How that's done is still being worked out.. :(



kevin

#2
Spatial Partition Sliding Collision Tech Demo


Demo Controls:
==============


        F1 Key = Hide Instructions
        F2 Key = decrease the fire delay
        F3 Key = decrease bullet speed
        F4 Key = Add more regions to the scene.

     Space Key = Randomly Reposition the boxes

     Arrow Keys= To Control the player (the circle thing :) ),

                     UP    = Forward
                     Down  = Back
                     Left  = Turn Left
                     right = Turn Right
 
     CTRL Key = FIRE

       Esc Key = Exit Demo


Download

  Download PlayBasic Sliding Collision Test (login required)


kevin

#3
Spatial Partition Sliding Collision Tech Demo (Update)

 Fixes a bullet firing bug, includes screen mode selection and the user can select the type of bullets it displays (line, Dot & None)


Demo Controls:
==============


        F1 Key = Hide Instructions
        F2 Key = decrease the fire delay
        F3 Key = decrease bullet speed
        F4 Key = Add more regions to the scene.
        F5 Key = Select Bullet draw Mode

     Space Key = Randomly Reposition the boxes

     Arrow Keys= To Control the player (the circle thing :) ),

                     UP    = Forward
                     Down  = Back
                     Left  = Turn Left
                     right = Turn Right
 
     CTRL Key = FIRE

       Esc Key = Exit Demo


Download

  Download PlayBasic Sliding Collision Test) (login required)  

Note:  Due to a line clipping error, this Demo can be a bit buggy when runing in full screen mode.. Best run it in windowed mode.
)

kevin

#4
Native World Buffer Partitions

 This picture shows the previous Sliding collision demo running with half of the world buffer partitioning build in. The partition allows PB to calc a min list of objects for the drawing process.  So it works much like a short list.  Even in a small world like the above the speed up is pretty handy.  Previously with just wall rendering it was running at 75fps on my system, and now with the partitions it's kick back up 115-120fps.  Even with the PB native bullet routines (their not part of the engine yet) it's running in the 50/60fps region (pictured bellow).   Which is about 35/45% faster than the previous version.

Also, In the screen shot you'll notice a cluster of 1000 pixels in the top left section of the world these are so i can validate the partition buffer.

kevin

#5
Here's another piccy

kevin

#6
Built In Sliding Collision For Sprites To Worlds
 
 This picture shows the previous demo, but this time the sprite engine has sliding collision completely built into it.   The speed up is pretty handy again..  Even on my old duron 800..

  The bullets are still running in native PB code though.  Although even once the ray/partition intersection is built in, it prolly won't push the rate up much more.  As pushing a few 1000 bullets is a huge bottle neck..  Although with a full screen of bullets (2000 plus) in line mode, it's still running a 27/28fps here.  
 
 To set up sliding collision couldn't be simpler :)

 You first draw the 'rays' into a world buffer.  These rays define the bounds of an area that is solid.    These bounds will be overlayed over another world space (which you draw to the screen).  Allowing you to run sliding collision  on maps/images/shapes/polygons.  Etc Etc..  What you define as hard, will be hard..

To do native top/down styled sliding you just create a sprite with Sliding Mode, assign it a world it should check for collisions.  Then each time the sprite is moved (regardless of rotation), the sliding collision just happens...

Or, once ray instection is built in, you could do it manually but casting a rays from your sprite.. thus  finding the intersection point(s), then position and align the sprite to the last impact.  This will allow sprites to walk on anything you care to define.   :)

kevin

#7
Spatial Partition Sliding Collision Tech Demo (PLayBasic V1.078 Update)

 This updates shows the bulk the previous Partition/Sliding collision engine built into PB..  The result is a much faster sliding sprite collision to world buffers.  The bullets (ray intersection) is yet to built into PB..

 Plus the previous Line clipping issue has been fixed.


Demo Controls:
==============


        F1 Key = Hide Instructions
        F2 Key = Toggle FPS CAP (75 is the default)
        F3 Key = decrease the fire delay
        F4 Key = decrease bullet speed
        F5 Key = Add more regions to the scene.
        F6 Key = Select Bullet draw Mode

     Space Key = Randomly Reposition the boxes

     Arrow Keys= To Control the player (the circle thing :) ),

                     UP    = Forward
                     Down  = Back
                     Left  = Turn Left
                     right = Turn Right
 
     CTRL Key = FIRE

       Esc Key = Exit Demo


Download

  Download PlayBasic Sliding Collision Test) (login required)



kevin

#8
Ray To World Intersection

 This picture shows the now built in (but still buggy) ray to world intersection.  In the picture it's casting 128 rays and clipping to them the scene. When it's running it sorta looks like a touch effect.. sorta :)

kevin

#9
Spatial Partition Ray Intersection & Sliding Collision Tech Demo (PLayBasic V1.078 update)

 This final tech demo (update) shows the new  Partition/Sliding collision engine totally built into PB..  The result is a much faster sliding sprite collision, with  faster ray intersection to worlds.      

 This demo has sliding collsion on the player.  The player can not only detect when impacts occur, but it also return what object (index) in the world you hit.  If you look closely you'lll notice a wall gets a 'red' shadow on the right when you walk into them.  

 Also, The player is constantly casting 128 rays (300 units long) against the world.  While the intersection is much quicker than it was previously, it's still far from optimal.  The focus ATM is to get the features up and running then tweak them up over time..


Demo Controls:
==============


        F1 Key = Hide Instructions
        F2 Key = Toggle FPS CAP (75 is the default)
        F3 Key = decrease the fire delay
        F4 Key = decrease bullet speed
        F5 Key = Add more regions to the scene.
        F6 Key = Select Bullet draw Mode

     Space Key = Randomly Reposition the boxes

     Arrow Keys= To Control the player (the circle thing :) ),

                     UP    = Forward
                     Down  = Back
                     Left  = Turn Left
                     right = Turn Right
 
     CTRL Key = FIRE

       Esc Key = Exit Demo


Download

Download PlayBasic Sliding Collision & Ray Test (with src)) (login required)


kevin

#10
Been working on the World buffers/camera system.  Mostly fixing stuff that's been broken with the recent world buffer changes..

 This example sorta combines all the new work together.  It uses two world buffers, one for collision and now one for drawing.  In this case, its drawing a world of textured/gouraud shading polygons.   Since their supported now in worlds and cameras too.

kevin

#11
World/Camera updates continue

This picture shows the new world and camera format running.   The backdrop is Map level and the foreground stuff are textured and gouraud shaded polygons.   The poly stuff is pretty expensive when used like this, but it makes for a good test.  Of course in normal situations the user would use worlds created from maps and static images mostly.  

The collision is running on a second world buffer  So you just draw the hard edges you want collisions/ray intersection with and that's about it.

Calypson

eek! my eyes!

its looking good in all, but im not a 60's child.  I think im blind.

I'm actually really glad your making these new features - it could help out alot in some future games.  like maybe a racing game or a cool top down shooter.  fun stuff - good work.

kevin

Yeah well partitioned world with sliding is part of the original design doc.  Their been partly in place for some time now, It's just taken us a long time be able clear other jobs out of that way to be able focus on them.  Although it's been implemented slightly differently to my original plan.  it's flexible enough to allow those creative people the scope to  produce some impressive results.