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.

3 Dimensional Chat / 2D screen coord to 3D location problems

Fluffy Paul
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 16th Dec 2002 19:25
Hi there.
I was just wondering what the best way to translate a 2D mouse click into a 3D location on a matrix or a BSP terrain object is.

This is for an RTS type control system where you have to "click" on the scenery in order to describe a position you want a unit to move to, or build something at. I've searched previous posts but the only other person to ask about this was told that the problem had been solved already elsewhere - but they weren't told where to look.
The only time I did find something that vaguely resembled the sort of thing I'm looking for I realised that it wasn't very good. I mean it's better than nothing but it relied on moving a 3D object around until it's screen x() and screen y() were within a few pixels of the mouse. My program has an almost completely free camera which ptches up past the horizon - so having that code example perform a loop that moves an object across 3D terrain until it's under the mouse would result in an infinite loop if I'm pointing at the sky.

What I initially did was program a "3D cursor" based on the camera angle. When you click a small 3D object would be fired off using the camera's orientation, but tweaked for how far away from the middle of the screen you clicked. It only travelled until it hit something or until it went beyond the fog/camera draw range (wichever was smaller).
Unfortunately this system isn't very accurate despite the fact that I've mathematically proved it on paper. I can only conlude that the perspective in Dark Basic is knobbling it.

Short of asking the Dark Basic developers to make an array the same dimensions of the screen, storing 3D coordinates of the locations used to render the 2D pixels and shipping it as a patch, I'm not sure what to do next.

Would posting my maths help anyone?
Would posting my code help, too?

Please note that this isn't the same problem as trying to use the object screen x() and object screen y() to "click" on a unit.

Login to post a reply

Server time is: 2020-08-12 02:22:44
Your offset time is: 2020-08-12 02:22:44