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 / Ray (3d vector) and sphere intersection test

Author
Message
Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 19th Mar 2007 22:56
You can rely on things like NGC or Sparky's collision plugins to deal with intersection tests.

However, as I like maths, I like writing my own simple tests. Here is my test for the intersection between a ray and a sphere.



Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Mar 2007 10:46
This is a nice one, very handy for bullet collision against characters once you work out a radius for each limb, I mean if anyone fancies adding some cool headshot gib code to their FPS.

Never seen it done with vectors before, I was using 2 line/circle intersection function calls, which I'm glad to be shot of .


Good guy, Good guy, Wan...
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 22nd Mar 2007 18:23
Nice! Having just done vectors at college I knocked up some code the other day which had functions for finding the point on a vector line closest to another point and the intersection of 2 vector lines. I then added some functions so I can use it all as the basis of a 2D, or with some adaptation 3D, collision system. Like you, I know it has all been done before but I love challenging myself to do it anyway!

Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 24th Mar 2007 19:03
Quote: "I was using 2 line/circle intersection function calls"


Ouch. Nasty.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)

Login to post a reply

Server time is: 2024-11-22 18:53:44
Your offset time is: 2024-11-22 18:53:44