Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / help with polygon collision

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Jun 2011 22:31 Edited at: 3rd Jun 2011 22:31
I'm working based on this: http://pogopixels.com/blog/2d-polygon-collision-detection/

I've gone of the code 3 times and can't find anything wrong, yet whenever the two shapes get close to intersecting, the shape controlled by the user jumps way off course. For some reason, the value of 'minIntervalDistance#' is way larger than it should be.

The website linked above provides C# code, which I compiled and the example works fine. If anyone has time to comb through this I'd appreciate a push in the right direction.




Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 3rd Jun 2011 23:02
Hi Phaelax,

I don't know if this matters, but the collision detection doesn't work as well:



Unless I changed something wrong there. I removed the second part of the for loop, and added a line with the print statements.

Sven B

tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 4th Jun 2011 03:19 Edited at: 4th Jun 2011 03:19
Is it okay to declare locals within a loop like that? I've never seen that done.



And is the array count() off because of silly DBPro arrays which go 0..(X) instead of 0..(X-1) ? Sorry I can't run the code right now, but I find this interesting.


A 3D marble platformer using Newton physics.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Jun 2011 02:47
The array count actually goes from 1 to X, but you can use the 0 index if you want.

If it was just an array issue, most likely some edges wouldn't be checked for the collision, but that's not the case.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 5th Jun 2011 10:36 Edited at: 5th Jun 2011 10:37
Heheh, I might be mistaken, but doesn't "make vector2(n)" return 0 all the time? It for sure doesn't create a unique handle. I don't know if vector2(0) is a valid vector, but if it is, this is likely the problem.

So I think when you say:
v1 = make vector2(1)

you want to say:
arbitrarynum = make vector2(1)
v1=1

[edit]

yup. Unless it was updated:
Quote: "You may well have spotted that the make vector commands all return an integer but rest assured this does not fulfil the function of a vector exist() command. I've experimented at length with this integer but it never returns anything but a 1. I am, in fact, totally baffled as to the purpose of this integer!"

http://www.neurofuzzydev.com/V/D/22a.htm


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Jun 2011 10:55 Edited at: 5th Jun 2011 10:55
Quote: "Heheh, I might be mistaken, but doesn't "make vector2(n)" return 0 all the time? "


Umm, you know what, you might be right! Doh!

I feel dumb, it's been so long since i used the vector commands. I'll update my code and see what happens.

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 5th Jun 2011 11:06
Quote: "yup. Unless it was updated:"


You have access to the source code if you're in doubt. The vector creation commands is eg for Vector2:


In other words, it will only return a 0 if the vector number is illegal. This is quite useless, since DBP will return an error and stop in that case...

Cheers!
Sven B

Login to post a reply

Server time is: 2026-07-11 02:14:16
Your offset time is: 2026-07-11 02:14:16