Cube to Polygon collision

BlitzMax Forums/MiniB3D Module/Cube to Polygon collision

Hezkore(Posted 2016) [#1]
Many years ago I asked the same question.
I'm hoping that this time there will be a solution.
Does anyone know how to get Cube to Plygon collision?
Or even just a cube shaped LinePick?


angros47(Posted 2016) [#2]
You could do it using 8 pivots with sphere-to-polygon collision on cube vertices, and using constraints. There are some examples on how to implement it in Blitz3D by using Verlet formula, but in OpenB3D constraints are now part of the library


markcw(Posted 2016) [#3]
Ok! Here is an example of what Angros described, adapted from the Minib3d balls_collision.bmx example. I made it rotate the cubes parallel to the camera so they're not always at 0,0,0 rotation.

At the moment it crashes after a while but hopefully that can be fixed [EDIT: sometimes I get the error "double free or corruption" EDIT2: fixed the crashes it was due to freeing entities attached to constraints without also using FreeConstraint - example updated]. I still need to add FreeConstraint and other free functions to the wrapper yet. Collisions aren't perfect but they're not too bad.

I made 8 pivots for each cube corner and constraints applied to all edges and then to the cube itself so it is held in position while collisions occur for each pivot.




Kryzon(Posted 2016) [#4]
The cube is made of triangles, and so is your polygon.
The solution becomes doing a triangle-triangle collision test, which is fast. I think this is called doing it "analytically".


angros47(Posted 2016) [#5]
The command MeshesIntersect can do that test, but is slow, and does not provide a "response " (slide, stop...)


Hezkore(Posted 2016) [#6]
I've been using LinePicks to get my collisions the way I want, but LinePick uses a radius and is round.
A square LinePick with width and height would be awesome.


Kryzon(Posted 2016) [#7]
If you have a cuboid (a box) in space, you can simply test if it contains any of the three vertices of a triangle.

If you describe that box with a pivot for its position, rotation and size (treating its scale as a size in 3D units), a simple intersection test would be to transform each vertex of the triangle to the space of the pivot and see if the coordinates of the vertex, in that space, are less than 1.0. You use TFormPoint for that.

In the local space of the box its width, height and depth are always 1.0, but in world space it can be any size that you ScaleEntity it to.


Hezkore(Posted 2016) [#8]
@munch the cubes are very wobbly and twitchy for some reason.