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 / 2d to 3d coordinates

Author
Message
davidt
23
Years of Service
User Offline
Joined: 29th Apr 2003
Location: United Kingdom
Posted: 20th May 2003 22:53
How would I be able to work out the 3d coordinates using the mouse? I know I could have the y coordinate on a flat plain, so it could always be 0, but how would I get the 3d coordinates from 2d mouse coordinates?

If it helps to know, I am using this to dertimine where an object should move in a 3d rts game. For example, when the user right-clicks, an object will move to that position in 3d space.

Thanks, David
Spec - Abit NF7-S nForce 2, AMD Athlon 2100+, 256Mb PC2700, ATI Radeon 9000Pro, 20Gb Seagate U6, DVD-ROM, Zip 100, 15" TFT monitor
Firesea
23
Years of Service
User Offline
Joined: 7th Apr 2003
Location:
Posted: 21st May 2003 00:31 Edited at: 21st May 2003 00:34
Do a search for 3D mouse coords, such .. lots of topics on this and a great 3dto 2d algorithm (I know thats opposite but.., comes in handy.

1)Some folks use a 3D mouse (made from an object). Move the object with your mouse in 3D space then just use the Object screen x() command to find the coords.

2) Search your 3D world objects and compare their XY screen coords to your mouse

Search Site:http://www.mywestsomerset.com/forumsearch.html
kevil
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 21st May 2003 10:55
There is a way to do it with a view matrix and vectors. I have an example of that, but it's on another computer and I haven't got the time right now to get it. Maybe I could post it tonight, or you can make something like that yourself. Try looking for documents on the internet for this.

Kevil

kevil
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 21st May 2003 21:52
Here it is .

Kevil

davidt
23
Years of Service
User Offline
Joined: 29th Apr 2003
Location: United Kingdom
Posted: 21st May 2003 23:12
OK, this is great, it works really well on it's own, thanks.

However, when I try to integrate it into my own program, it gives me an error message from the first line of the function - 'Vector does not exist' (this is the line of 'view matrix4 matrix'). I basically copied the code from your example, taking out the make matrix commands (as I already have one), and replacing the get ground height commands with 0 to start with (0 as the y coordinate), but it doesn't work.

As I don't understand any of the 3d math commands (I'm only 14!), I can't really debug it properly. Do you think you could put all of the commands into one function that would work in any program, so I would just need to call the function each loop? If you could do this that would be great.

Thanks, David

Spec - Abit NF7-S nForce 2, AMD Athlon 2100+, 256Mb PC2700, ATI Radeon 9000Pro, 20Gb Seagate U6, DVD-ROM, Zip 100, 15" TFT monitor
kevil
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 22nd May 2003 00:23
Well, I think your problem is that you forgot to make the vectors.

To fix this you must put this on top of your program:

rem create vectors+matrix
q=make vector3(1)
q=make matrix4(2)
q=make vector3(3)
q=make vector3(4)

Then it should work.

Kevil

UberTuba
23
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Brittania
Posted: 22nd May 2003 00:56
You can't work out 3d from 2d. Its imposs. All youcan do is have a vector coming fom the camera. the vector is the leftover dimension.
3d - 2d = 1d

Life is a terminal disease.
You never survive it.

Login to post a reply

Server time is: 2026-07-11 22:25:20
Your offset time is: 2026-07-11 22:25:20