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.

Dark Physics & Dark A.I. & Dark Dynamix / Casting A Ray From Mouse Co-ordinates

Author
Message
Syncaidius
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 9th Dec 2008 21:39 Edited at: 9th Dec 2008 21:41
I've been thinking of a way to do cast a ray (using dark physics ray casting commands) into the screen based on a mouse XY coordinate (the position of the mouse on the screen) and return the 3D coordinates of where the ray hit. So far i've not been able to come up with a way to do this.

If anyone is able to help me on this, i'd appreciate it (a lot).

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 10th Dec 2008 14:12 Edited at: 10th Dec 2008 14:14
You use the pick screen and pick vector commands.

So first you get the mouse coordinates and call the pick screen command:



(The last number there is how far you want to project the ray from the mouse. So in this case you'll be retrieving a point 5000 units infront of the mouse.)

Then store the camera's position as the starting point of the intersection ray:



Then you can use the pick vector commands to get a position based on the camera's position. Like this:


And now you have the two 3D coordinates to project a raycast from. I dont use Dark Physics I use Sparky's collision dll so I dont know the syntax of raycasting in DP so thats all I can do to help.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Dec 2008 16:01
Quote: "So in this case you'll be retrieving a point 5000 units infront of the mouse"


That may be a bit misleading. Maybe you should say "in front of the camera".

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 10th Dec 2008 21:30
Ah correct, sorry. Infront of the camera aiming at the point infront of the camera found with the mouse's coordinates.

Syncaidius
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 11th Dec 2008 12:26
Thanks for that RUCCUS. That helped a lot.

sindore
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 17th Dec 2008 15:32 Edited at: 17th Dec 2008 15:42
DBking is this what your looking for?

I dont know if it works on dp v1.5, but it does on v1.4

here is what I did in one of my programs.


hope this helped

edit

here is a functional version of the code I just posted


I hope this is what your looking for, it tuke me ages to get this work right.

soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!
sindore
20
Years of Service
User Offline
Joined: 2nd Jul 2004
Location: Bedfordshire, UK
Posted: 17th Dec 2008 15:46
here is what I used that code for RUBE GOLDBERG MAKER

have a go and let me know what you think.


soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!
Syncaidius
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 14th Jan 2009 12:54
Thanks for that sindore, works like a charm. I'm a bit late with the reply though.

ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 14th Jan 2009 19:09
I am getting an error:
Could not determine perameter type of "phy ray cast closest shape... at line 309

for the RUBE GOLDBERG MAKER

Login to post a reply

Server time is: 2024-11-24 18:58:43
Your offset time is: 2024-11-24 18:58:43