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 Discussion / *NEEDS*Ray-Segment intersection, OR Ray-Plain intersection algorithm.

Author
Message
CaseyK
23
Years of Service
User Offline
Joined: 27th Jun 2003
Location:
Posted: 1st May 2005 08:06
First of all I am not new to DBC/DBPRO or Forums. This may STILL sadly mean depending on how intellectual and experianced the user's are on this Forum, that I am still a noob to be gasolined and flamed like the rest.I am a long time programmer gone under the aliases of Cakey, Cakes, Kake, KC, and possibly Dameus if you knew me right. I have developed the dredful Monkey Maze games , and the not quite decent Ships VS Aliens(and of course many other not too well known things).

The goal of the script I am stuck on is for my First person RPG in-which works well so far, I would just like to incorporate a *MATHEMATICAL* (NO DLL'S OR OBJECT HIDING PLEASE) way to see if I have a ray[.->] intersecting with a plain[<->]. I have my objects stored inside of an Array for user sliding collision's purpose. The For/Next sliding of points across a slope or on an angle is far too many loops per loop for my Game to run smoothly.

I have found the equation although don't understand it all:
t = - (a*x1 + b*y1 + c*z1 + d)/(a*i + b*j + c*k)

I could endure a valid ray intersection with segment equation. I forgot this from my Algebra class, any input on this would be appreciated as well. I don't need code unless it would better demonstrate the cause or you're bored.

I haven't seen this out anywere(maybe I'm not looking far enough) so this would be a very appreciated bit of script.

Thank you for reading my novel or a post, Casey K.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd May 2005 03:40 Edited at: 2nd May 2005 03:41
Hmmm, you're using DBC. So no vector commands. Grrr. Ok, gimme a few minutes and i'll post back here.

lol, they changed my avatar to a spoon this time!

PETA - People for the Eating of Tasty Animals
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd May 2005 04:37 Edited at: 2nd May 2005 04:38
"And moses did as the lord ask of him,
he beateth the rock with his
stick until he flaketh out on the sand ...
and LO, vectors pour forth onto the sands
This is the Gospel of the Lord"


Yeah so here are the vector routines...well the basic ones anyway,
Dmitry K attached some more advanced ones aswell if you need them !
http://forum.thegamecreators.com/?m=forum_view&t=50609&b=10

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd May 2005 04:44 Edited at: 3rd May 2005 10:46
Ok, wrote this with DB 5.8, but it should work in classic. I didn't use anything specific to Pro. I tested it with some simple numbers that I could easily calculate in my head, and as far as I can tell it works.

Just to clarify on the plane equation for you:
Ax + By + Cz + D = 0

A,B,C would be the normal of the plane.
D is the distance from the origin(0,0,0) to the plane.

I put in a few comments to let you know what each chunk of code is doing. You check the value of t# because if its not within [0,1] then the intersection happens beyond the length of your ray.

You really only need 3 points to define your plane. Once you have an intersection point, check to see if that point is within the boundaries of your actual plane object. I'm sure you already know this tests an infinite plane. To check for intersection within your plane's boundaries, project the plane and intersection point onto the axis with the greatest component value.

lets say your plane's normal is (0.24,0.45,0.78)
We can turn this into a 2d problem by projecting it onto the X plane because it has the smallest component. So basically, just ignore the X-component. Assuming your plane's point are in a clockwise order, you can check to see if the intersection point is to the right of all 4 lines.

The picture I just attached shows the direction the lines should be in along with the direction of their normals. The normals point to the right of the line.





Here's a function I wrote in Pro awhile ago that might help you out with the final intersection check.




gee thx baggers, now you tell me.

PETA - People for the Eating of Tasty Animals
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 2nd May 2005 05:27
Hehe I typed as fast as I could !
Nice code though...ill have to have a learn of that myself !

CaseyK
23
Years of Service
User Offline
Joined: 27th Jun 2003
Location:
Posted: 2nd May 2005 07:27
Ahhhhh, I see how this works now(Plane equation). Thank you both very much. You seem to be the Vector "guru's", and I appreciate it all. Vectors are a headache, I don't know much about them[DBC user]. They are like 3-Dimensional Ray's that go in a direction depending on some value?I just remember seeing alot about them in my mother's calculus book while looking for this equation. The Point and Line function looks very handy , but too use it I'd need to use the for next method which is what I wanted to avoid . Although, I guess you have to deal with what you can get . I checked the dmitry K attachment looks promising, thank you all for these in depth responses. AIM: HelloCakey if you have time to describe any mor eof this stuff too me. It would be excellent.

And the sun sets on our oblivion.
CaseyK
23
Years of Service
User Offline
Joined: 27th Jun 2003
Location:
Posted: 2nd May 2005 08:03
I found this at a math/programming site and put it into a function... can anyone make sense out of it?
http://www.exaflop.org/docs/cgafaq/cga5.html

And the sun sets on our oblivion.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd May 2005 10:10
There's like 10 functions on that site, which one were you referring to?

PETA - People for the Eating of Tasty Animals
Baggers
22
Years of Service
User Offline
Joined: 31st May 2004
Location: Yonder over dem dere hills
Posted: 3rd May 2005 10:23
Yeah i can help with some of them...im good with vectors and such but when i hit matrices i get stuck...i havnt read up on them yet, though ill have a bash when i can find some good tutorials.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd May 2005 10:47
Ok, made a small update to the code above. I made a slight error. Ok, a huge mistake, don't know how I did that.

Changed:


To:


PETA - People for the Eating of Tasty Animals

Login to post a reply

Server time is: 2026-07-10 18:11:05
Your offset time is: 2026-07-10 18:11:05