• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Collision Detection - A Jeff Thompson web book

dawlane

Well-known member
CX Code Contributor
Tutorial Author
Joined
Jun 21, 2017
Messages
1,146
Both Cerberus and MonkeyX do not support any built in collision detection. It's up to the programmer to have to write their own.
For those that are having trouble, here's a web book/tutorial by Jeff Thompson. The code is pretty straight forward and should be easy enough for someone with a bit of understanding to port to Cerberus.

The only issue would be the licence. Which if I understand, could be a bit of a problem converting the code into a module for distribution, but not if you write your own module for personal use. I've done my own port of this with addition classes representing the shape objects. If it wasn't for the licence I would have uploaded it.
 
Last edited:
Thanks. This looks like a really good summary of different collision solutions well explained.
And it is also an example that licencing can really be a pain in the neck.
You can only licence/ have copyright on stuff that has a certain level of creativity in it and this tutorial goes all the way from a nearly no brainer to an advanced level (which still has been invented and used somewhere else before) The problem is, where to draw the line between trivial/widely known stuff including its straight forward implementation and his undoubtably usefull and easy to grasp way of summing it up.

To me it is like: You can make and sell your homemade tomato soup as long as you didn't reallize it is the same recipe as of one of the widely known cooking chefs out there...
 
Interesting. Ive had a quick glance... can you really copyright maths?

My implementation for BOX rectangle/point to rectangle/point collision which Ive used since forever is as follows .
Is it more optimised as it fails faster or is it just the same and doesnt use ANDs?

Cerberus:
Method Collide:Bool(x1:float, y1:float, w1:float, h1:float, x2:float, y2:float, w2:float, h2:float)
    If x1+w1 < x2 Then Return False
    If x1> x2+w2 Then Return False
    If y1+h1 < y2 Then Return False
    If y1> y2+h2 Then Return False
    
    Return True
End

' 2 rects colliding
If Collide(50,50,100,100,75,75,200,200)

' mouse collision
If Collide(MouseX(),MouseY(),1,1,100,100,200,200)
PS you can have that for free ;-)
 
I think it would depend of how the back-end compiler optimises conditional expressions.
The version in the book can be compressed to
Cerberus:
Function Rect2Rect:Bool(rectangle1X:Float, rectangle1Y:Float, rectangle1Width:Float, rectangle1Height:Float, rectangle2X:Float, rectangle2Y:Float, rectangle2Widht:Float, rectangle2Height:Float)
    Return (rectangle1X+rectangle1Width >= rectangle2X And rectangle1X <= rectangle2X+rectangle2Widht And rectangle1Y+rectangle1Height >= rectangle2Y And rectangle1Y <= rectangle2Y+rectangle2Height)
End Function
You would have to compiler the code to C++ and then to Assembly for a comparison and then count the number of clock-cycles each instruction takes.
 
You would have to compiler the code to C++ and then to Assembly for a comparison and then count the number of clock-cycles each instruction takes
Not sure i have the time for that ;-) Maybe one day......
 
I think optimisation can be done later. More important IMHO seems to be the naming and the parameters for calling.
When I have some time I will come up with some suggestions. Somewhere in the forums there was a discussion about that.
 
More important IMHO seems to be the naming and the parameters for calling.
Are you suggesting creating some built in functions for collision into CX?
That'd be nice.
 
Absolutely. I would even prefer to have a built in framework/engine, but that has to be the last one.
For now I'd like to have the building blocks for a framework like collisions, tweening etc.
What do you think could be helpful, without limiting your way of setting things up.
Because that is one issue that comes up when having a built in framework with animations, transitions, scenes ....
 
Back
Top Bottom