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 Professional Discussion / Position of mouse

Author
Message
Dimension
22
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 30th May 2010 13:11
Does anybody know how to get the (x, z) position of the mouse where y = 0?
ShaunRW
DBPro Developer
18
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 30th May 2010 13:40
Umm... MouseX() and MouseZ().

Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 30th May 2010 15:25
MouseZ() is the scroll wheel.

The mouse has no Z position as it uses a 2D scale, not a 3D scale. Perhaps you want to use the pick screen command but without knowing your reasons for wanting this, I'm only guessing wildly.

My signature is NOT a moderator plaything! Stop changing it!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th May 2010 20:49
pick screen


Dimension
22
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 30th May 2010 22:55
I'm actually referring to the 3D coordinates in space on a plane where x is any number and z is any number and y is 0. I was thinking I could use the pick screen command and repeatedly increment the distance and y is in proximity to 0 but for some reason it doesn't work, see bellow.



Is there a way to project the 3d coordinates using some kind of vector math.
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 31st May 2010 02:28
I had a similar problem once

>here< is the thread, hope it helps

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 31st May 2010 05:36 Edited at: 31st May 2010 05:37
Quote: "I'm actually referring to the 3D coordinates in space on a plane where x is any number and z is any number and y is 0."

Cool way to do this I learned from the tutorial "vectors don't bite!"


lots of math, but it's really quite simple (well, dot product is a little hard to "get"). Basically, you have a right triangle in 3d space: From the camera's position, to the point of intersection with the plane, to the point at (camera x,0,camera z). We know the height of one side (camera y), and we know the direction from the camera's position to the point of intersection (this is the value returned by "get pick vector x/y/z". One can see that this direction multiplied by the hypotenuse of the triangle (which is the distance between the camera and the point of intersection), plus the camera's position is the point of intersection, so all we need to do is find the hypotenuse.

This is where dot product vector comes in. the pick vector is a unit vector pointing downwards. Since the side from the camera's position to (camera x,0,camera z) has a direction of (0,-1,0), we can find the cosine of the angle at the camera's position by taking the dot product of the pick vector and (0,-1,0). cosine=adjacent/hypotenuse, and adjacent=camera y, so hypotenuse=camera y/dot product(pick vector, (0,-1,0))
hypotenuse*pick vector + camera position = point of intersection.
Easy!


Login to post a reply

Server time is: 2026-07-25 08:28:09
Your offset time is: 2026-07-25 08:28:09