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 / 2d to 3d conversion for point and click, drag and drop, etc.

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 18th Mar 2005 02:58 Edited at: 18th Mar 2005 02:59
I've seen this question asked a number of times before - how can you convert a 2d coordinate (say, the mouse position) into an object's coordinate in 3d space, given the object's z-position? Well, I had the need to figure it out for myself, so here is my basic solution ..... no pick object stuff - just a pure maths conversion.



Use the up and down keys to change the object's z-position. Should work for all screen sizes, fields of view and camera positions, but if you want to mess with camera rotations, then you'll need something more complex than this.


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Mar 2005 11:27
UWDesign's website has a snippet that does just that.

"eureka" - Archimedes
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 22nd Mar 2005 00:08
I remember something about one of these in Philip's vector tutorial...

Good work on figuring that out though, Ric

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 22nd Mar 2005 00:44
Ah - looks like I reinvented the wheel! Hey ho.


RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 22nd Mar 2005 02:42 Edited at: 22nd Mar 2005 02:44
Ric, talk about reinventing the wheel (lol); this was from my Adventure Bot game in your challenges thread. The targeting cursor was a 3d object that moved following the mouse. Here's the function:


Basically, I had the object "chase" the mouse around until it caught up with it. This meathod also eats up a bit of time between syncs, so it's not great for high-end graphics heavy stuff.

"Droids don't rip your arms off when they lose." -H. Solo

REALITY II

Login to post a reply

Server time is: 2024-11-23 14:03:08
Your offset time is: 2024-11-23 14:03:08