Collision detection

Monkey Forums/Monkey Programming/Collision detection

Leon Brown(Posted 2012) [#1]
I'm currently working on some code that requires some collision detection - primarily where the mouse can click on an object and the code detects that the object is clicked on. I'm currently detecting this based on the x,y location of the mouse, but this isn't good where the object is rotated. Does anyone have a better suggestion for this?


DruggedBunny(Posted 2012) [#2]
Have a look at this NoOdle code...


Jesse(Posted 2012) [#3]
At my age and still don't know how to do matrixes. :(

If it helps, here is one with just a couple of trig functions. Not as good as Noodles but works for simple rotating unscaled images.

[monkeycode]
Function collidedpoint:Int(px:Float,py:Float,imagex:Float,imagey:Float,image:Image,angle:Float)

Local x1:Float = -image.HandleX()
Local y1:Float = -image.HandleY()
Local x3:Float = image.Width() - image.HandleX()
Local y3:Float = image.Height() - image.HandleY()
px = px - imagex
py = py - imagey
Local tx:Float = px*Cos(-angle) - py*Sin(-angle)
Local ty:Float = py*Cos(-angle) + px*Sin(-angle)
If tx > x1
If ty >y1
If tx < x3
If ty < y3
Return True
Endif
Endif
Endif
Endif
Return False
End Function
[/monkeycode]


[edited for errors]


Sledge(Posted 2012) [#4]
At my age and still don't know how to do matrixes. :(


http://blog.wolfire.com/2010/07/Linear-algebra-for-game-developers-part-3


Jesse(Posted 2012) [#5]
LOL! thanks Sledge.

I am almost there just need to look in the more advanced topics.


Gerry Quinn(Posted 2012) [#6]
PointInPolygon() might help, if your object is not a rectangle. There are a couple of variations on it in the code forum.


golomp(Posted 2012) [#7]
[Maths Mode On]
@Jesse : Frank Ayres Jr. Schaum's Theory & Problems of Matrices
is IMHO definitively the best book i ever read on Matrices
[Maths Mode Off]
;)


Samah(Posted 2012) [#8]
Noooo don't talk about matrices! My head exploded fixing MonkeyMax..


Jesse(Posted 2012) [#9]
Thanks golomp but I think that book is too much for me right now.

I did a quick search for the book and found this:

http://archive.org/details/SchaumsTheoryProblemsOfMatrices


golomp(Posted 2012) [#10]
Matrices are useful to modelise an environment.
Fe, you analyze a natural environment X. This environment X is represented in a sheet of number representing data, as much data as you can collect with a precise value.(place of data must be the same before and after peturbation) Then there is a perturbation on this environment.(earthquake, time, dynamic forces, magnetism, etc...)You obtain a new environment Y with new data inside.Any natural environment is ruled by a affine function Y=AX+B. If you are able to determinate A and B (fe with special 0 conditions)you can determinate the future of a same kind of environment changed by the same kind of perturbation. Fe in Asia, houses are build with this kind of analyse to determinate the level earthquake resistance. Matrices save lives! You can apply the same principe in a lot of domain (meteo, biology, mecanic, politic, mass effect, gaz, water, electricity, human society,...)Matrices are just a very usefull tool to manipulate a big collection of data. Giant Matrices exist with millions of values...


gekkonier(Posted 2012) [#11]
Giant Matrices exist with millions of values...

And this is then the so called Matrix, Neo ;)