🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Line-cube collision detection

Started by
7 comments, last by David20321 24 years ago
Given two points and the coordinates and size of a cube how can I check if the line that connects the two points goes through the cube? It doesn''t have to be perfectly accurate, I need this to check line of sight for the AI. Thanx.
Advertisement
is the cube axis aligned? if not, rotate the line segment into the cube's object space, so that you're operating with an axis aligned box. then proceed as you would with frustum clipping.



--
Float like a butterfly, bite like a crocodile.



Edited by - goltrpoat on June 9, 2000 1:44:22 AM
--Float like a butterfly, bite like a crocodile.
hi David20321

let''s take a look at
http://swin.edu.au/astronomy/pbourke/geometry/linefacet/

lunasol
I just used Paul Bourke''s code (mentioned above) to do collision detection, works great, so I highly suggest it. Note: EPS = epsilon.

Morgan
I can''t get to the site. It says that the network connection was refused by the server swin.edu.au. And martyr, what is frustum clipping?
Hi,
ooooops if forgot the www at the beginning...
let''s try
http://www.swin.edu.au/astronomy/pbourke/

then look at the geometry directory

you can see a frustrum as a section of a pyramid viewed from the narrow end to the broad end. The clipping planes are the planes delimiting the frustrum volume.

lunasol
Sorry that I''m not very good with geometry, but i couldn''t figure out how to use Paul Bourke''s tutorials effectively. I''m probably not looking in the right part of his site or maybe I''m just too stupid. Could you please give me an example in C of how if I have a 4-sided square polygon and a line I could check if the line goes through the polygon? I know that might be hard but you seem to know what you''re talking about.
good morning David20321,

sorry i don''t know perfectly what i''m talking about. I''m also working on collision detection these days and it''s a hard subject IMHO . I just give you this link because you and me must know the basis of 3D geometry if we want go on coding with ogl stuff (sorry for my awful english )
For C code you want you are a lucky guy : look at the end of the page .../pbourke/geometry/linefacet/ : there is some source code! ok it''s not a four sided polygon but a triangle. But i think it''s a good beginning.
Let me know how do you progress with that stuff. I think you can also help me!

working lunasol
I too had trouble doing collision detection, but I got it working, I thought of rewriting my engine to only handle triangles, but I ended up just splitting up my quads and triangles ONLY ehrn sending them into the collision detection functions. I figured out Paul Bourke''s code as I wrote the program, but when I ran into a problem he was glad to help, so if you can''t get it to work, I''m sure he''d help out. (My problem was with ''EPS'' I had no idea what it was, turns out it''s epsilon, a tolerance variable... he suggested .01 or .001, but mine only worked at .2)

Morgan

This topic is closed to new replies.

Advertisement