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.

Code Snippets / Math Collision - Rotated Rectangle [DBPro & DBC ( With Slight Modification ) ]

Author
Message
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 23rd Apr 2004 22:49 Edited at: 24th Apr 2004 04:31
Hey all

Here's a function I just worked on...
It is acurate, FAST, rotated rectangle/box collision.

Here's the actuall, uncommented function:


And here is a Fully commented, working Example:


And here is the same example with a bit of debug info:


I hope this helps some people out ( I know it sure helped me )

Any comments and or suggestions would be extremely welcome

Thanks.
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 23rd Apr 2004 23:20
Fix the examples first

Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
Arkheii
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 24th Apr 2004 04:06
Fixed your second example (the commented one). No problem really, just some DBC float variables and crude type casting. I had to fix the _random(x) function though because you were accessing the objwidth# and objheight# variables from within a function. Instead of making them global, I just passed it on to the function. Only the _rot_box() func is important anyway

DBC version:




"Story in a game is like story in a porn movie. It's expected to be there, but it's not that important." - John Carmack
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 24th Apr 2004 04:28
Ok, first things first, I made a mistake in the _random() function, the paramaters should be (x,objwidth,objheight) and the calls need to be changed accordingly. ( i edited my above post to reflect this. )

@Emperor Baal;
Um... the examples work fine...

Maybe you tried to compile them in DBC?
Well, it needs a slight modification for it to run in there...

The problem between DBP and DBC is that DBP automatically converts types whereas DBC doesn't, so It has unrecognised paramater errors.

To fix it, Simply change the call to the collision function so that all the values are floats.

For the first call, change the line from:

to:


Then, For the second call, you'll have to modify the function a little bit.

Sipmly change it from:

to:


The only difference between the functions is the types of the object position variables. and I times the Object Angle Y(1) by 1.0 to give it a floating point.

And the full code ( with debug info ) for DBC users is:


Thanks for the imput though Emperor Baal

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 24th Apr 2004 04:33
lol, thanks for that r_kabouter

I must have still been typing when you posted.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 25th Apr 2004 17:12
Come ON!

There's gotta be at least some people out there ( other than Emperor Baal and r_kabouter ) that need/want/have been looking for ACCURATE, FAST rotated Rectangle collision!!

I mean, it's one of the major Math collisions that are sort after...

Or maybe because it's not sliding collision?
Either way, A bit of credit for this snippet would be nice... I stayed up untill 4am fixing a damend example so that you people could be impressed with my hard work...

Oh well..

Still, any comments/remarks/critizism/gossip/anything would be much apreciated

Thanks
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Arkheii
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 25th Apr 2004 20:00
Ack, never thought JessTicular would ever act that pathetically Only 90+ views so far... Maybe it's because everyone else is using NG's dll already.

It's actually kinda stupid because there are lots of noobs out there looking for stuff when they're already in the code snippets forum.

*durn fool kid noobs* haha lol


"Story in a game is like story in a porn movie. It's expected to be there, but it's not that important." - John Carmack
PoHa!84
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 26th Apr 2004 18:46
Pretty nifty, Jess. All those little red balls flying into the box looks pretty cool, IMO. Too bad that so few people are giving you comments...
Grismald
21
Years of Service
User Offline
Joined: 4th Mar 2003
Location: France
Posted: 26th Apr 2004 20:52 Edited at: 26th Apr 2004 22:28
EXCELLENT stuff here, probably the best collision snippet i've ever seen! In fact it's just what i needed for my current project.
Your function is at the same time fast and accurate, good job i must say
It would be great if you could make a set of collision commands of a larger scale based on this


yeah... hurry up!
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Apr 2004 21:17
Hey, some input Yay!

@PoHa!84;
lol, I'm glad you liked the way I represented the collision

@Grismald;
Thanks for the compliment And I'm glad you can find a use for it
Oh, and I'm one step ahead of you!
I'm already working on setting this up for 3D collision, and am in the process of creating a set of functions that you can use to create/destroy Static rotated box/rectangular prism collision areas, check for collision of a point and a static AND dynamic box/prism, and and if I can figure it out, checking for collision with another rotated box/rectangular prism.

Hopefully I'll be finished with these functions by weeks end
Also, I'm planing to provide full documentation ( in PDF format ) so that I can graphically demonstrate how the collision system works, and also explain the code, and tell you how to expand/modify the functions.

Anyhoo, that's enough rambling for me now...

Keep those posts coming people

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 26th Apr 2004 23:46 Edited at: 26th Apr 2004 23:47
JessTicular, I'm one step ahead of you!

Im working on a full working collision system. It's really easy, just use the included tool to place the collision data in your scene and save the data to file.
Open the file in your project and look what happens:




The following shapes are supported:
1 = box collision
2 = sphere collision
3 = stair/slope - x
4 = stair/slope - z
5 = ellipsoid
6 = x-cylinder
7 = y-cylinder
8 = z-cylinder
9 = cone
10 = pyramid

and im still adding stuff
They are calculated using the data from my MathCollTool:




This is the basic code that you will need to run my system:



This is what update_world does, and what parameters are necessary:




Do you still want to code Math Collision

Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 27th Apr 2004 03:21 Edited at: 27th Apr 2004 03:22
I think that for the rotated rectangle collision, the following function will be a bit faster and more compact. You might not understand it without some linear algebra knowledge, but at least it's straight to the point.



Btw buffer isn't needed now. Why do you need something like that in the first place?

Kevil
Arkheii
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 27th Apr 2004 09:00
I'm surprised that NG still hasn't hijacked these collision threads with one of his advertisements lol.

@Grismald: That your sig? lol

@Emperor Baal: Preset collision data? Sounds cool, and it'd be great if you could document it as well as your last one. BTW, think it's possible to expect xz rotated box collision soon?


"I am nobody's bitch. You are mine. I don't need to know you. You only need to know me."
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 27th Apr 2004 09:57
Boxes can be rotated on every axis (x/y/z) and it will still detect collision.

It works like this (not the real code though):

function update_world(a,b,speed#,ymov,grav,gravspeed#,camgrav,hgt#)
-get positions and angles, store them in variables
-check for gravity, if grav is set to 1 pull the objects down.
if a object is colliding, calculate new height.

-Get positions and angles
-move cameras/objects on x-angle
-calculate collision and reposition if necessary

-move on z-angle
-calculate

-move on y-angle (if ymov = 1)
-calculate

endfunction

Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 27th Apr 2004 11:41
Omg... You just HiJacked my thread Emperor Baal...

Oh well, a bit of friendly competition is always a nice motivation to get people started... lol

@r_kabouter;
Yeah, I'm surprise NG hasn't jumped in yet too, lol..

@kevil;
I'm not too sure about your code, what is the >>1?? Maybe I've just missed something, but I can't remeber seeing any DarkBASIC code like that before...
And, the Buffer# variable was so that if, for any reason ( which I have ) you wanted the collision to be detected slightly on the outside of the box/prism, ie, you wanted the dimensions of the box/prism to be slightly larger or smaller than it actually was ( eg for a cube object ) then you punch it into the buffer value.

@Emperor Baal;
Yea, you're code looks like you're ahead of things...

I'm making my collision code purely for my slowly developing RTS, but I wanted to create it as a function set that can be used by any and all programs.
The main area I want to work on is Static collision for rotated box/prism and dynamic ( ie, moving/rotating ) collision between two box/prism's...

The system I hope to impliment will be something like yours is too, except, you do all mine in game.
For example, you use the _init_static_col() command to setup a static collision box, then in the loop you would check it with the _check_static_col() command, where you would simply pass it two "object" numbers and it determines if collision has occured...

Oh, and btw, if for any reason you get stuck, or want some help, give me a buzz, cos I definatly don't want us to be enemies, and the only other alternative is to work together

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Arkheii
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 27th Apr 2004 14:05
Quote: "@kevil;
I'm not too sure about your code, what is the >>1?? Maybe I've just missed something, but I can't remeber seeing any DarkBASIC code like that before...
And, the Buffer# variable was so that if, for any reason ( which I have ) you wanted the collision to be detected slightly on the outside of the box/prism, ie, you wanted the dimensions of the box/prism to be slightly larger or smaller than it actually was ( eg for a cube object ) then you punch it into the buffer value.
"


Was wondering about that too (I'm DBCE). Is that bitwise shifting?


"I am nobody's bitch. You are mine. I don't need to know you. You only need to know me."
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 27th Apr 2004 14:13
Yeah..

The way it works is like this. I transform the point coordinates to the rectangle object orientation. Then I just do a check to see if it's inside a rectangle. You can test it with your own code.

Kevil
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 27th Apr 2004 19:21
Quote: "
For example, you use the _init_static_col() command to setup a static collision box, then in the loop you would check it with the _check_static_col() command, where you would simply pass it two "object" numbers and it determines if collision has occured...
"


What are you talking about? Static collision box? "object" numbers?

btw, I didnt mean to hijack your thread, im just "replying" to it

Quote: "
UPDATED

Amd 2800+ 1024mb pc3200 A7N8X - Deluxe Ati Radeon 9800PRO 256mb
"
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 28th Apr 2004 05:01
Well, the current method I am using for Static Collision box, is you use my _init_static_col() function with a bunch of parameters ( 10 in fact, one of these includes a user defined "object" number, or if you prefer, instead of an "object" number, it could be a "collision" number etc. ) to set up a static rotated colision box/prism. This is done by creating a MemBlock that stores all the values needed for the 3D collision check.

Then, when you call the _check_static_col() function, with one of the parameters being the "object/collision" number that you specified previously, it checks if collision is occuring with that box/prism.

This is mainly set up for use in my RTS, as I will have alot of static areas that need collision checks ( ie, buildings and certain land masses )...

Hopefully that explains it a bit more for you

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Jess T
Retired Moderator
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 1st May 2004 09:50
Unfortunatly, my codeing has come to a stand still since wednesday as my new PC parts arrived, so I had to build it, then get it working, and now it's my birthday on Sunday, with a party tonight, thus I probably wont have the functions finished by the week's end, lol.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy

Login to post a reply

Server time is: 2024-05-13 11:51:09
Your offset time is: 2024-05-13 11:51:09