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 / Projecting 2d into a 3d coordinate.

Author
Message
Rohfl
14
Years of Service
User Offline
Joined: 3rd Jan 2012
Location:
Posted: 19th Jan 2012 08:24
I need to project the 2d screen grid onto the 3d world and be able to rotate it and manipulate the grid somehow. The goal is to place an object somewhere in the 3d world based on the mouse x and y coordinates. Does anyone know how to do that?

Wo!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jan 2012 10:14
Well, if you just make a plain and stick it in front of the camera, you can guage any 2D location using PICK OBJECT. That takes a range of objects (might just be the plain object), and a 2D pixel location, and returns the object number at that location, and also the 3D location.

You should look up PICK OBJECT in the help files, but if memory serves, it works something like this:

Pobj=PICK OBJECT(mousex(),mousey(),10,10)
`Assuming object 10 is your plain object
HitX#=get pick vector x()+camera position x()
HitY#=get pick vector y()+camera position y()
HitZ#=get pick vector z()+camera position z()

So once an object has been 'picked', the pick vectors contain the 3D location in relation to the camera.

It's a very useful command, it would work on a terrain object for example, but for any type of object viewer, where you want to know which object your clicking on, and where, it's invaluable.

Health, Ammo, and bacon and eggs!
Rohfl
14
Years of Service
User Offline
Joined: 3rd Jan 2012
Location:
Posted: 19th Jan 2012 11:02
I just tried that, and it works in it's basic form to where it will give me a 3d point based on the mouse position, but I can't rotate the grid, it is fixed to the camera position and rotation. Lets say this is the screen below... divided into four sections:
_____
| | |
|--0--|
|__|__|

I want to take this grid and place it in the 3d world with the character in the center so that I can point the character in the direction that the mouse is in in relation to the object's x and z positions. Without the grid being affected by the camera position or angle.

Can this be done?

Wo!
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 19th Jan 2012 11:30
Van B ace!

Will give this a shot soon!

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Jan 2012 12:01
I'm sure it can be done, but I'm not sure what you need exactly.

If you want a grid that you can click on, you could just position it at the players feet, then check the PICK OBJECT on that - it would of course relate to the camera rotation etc. You could work out the angle from the player, rotate towards that etc. This technique might be good for an RTS game, but remember that you could use PICK OBJECT on a terrain as well, instead of clicking on a grid, you just click where you want the character to go, if you know what I mean.

If you need a grid that is fixed to the camera, well there is LOCK OBJECT, which locks an object to the camera rotation and position - however I'm not sure how good that would work with PICK OBJECT. What might be an idea if this is what you want, is to position a plain at the camera position, rotate the plain according to the camera...

Position object 1,camera position x(),camera position y(),camera position z()
Rotate object 1,camera angle x(),camera angle y(),camera angle z()

Then move the object forward with MOVE OBJECT, then it will be floating in front of the camera, and would allow for PICK OBJECT etc.

Health, Ammo, and bacon and eggs!
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 25th Jan 2012 23:45
I wasn't aware of the GET PICK VECTOR commands before but I had a bit of a play and I think this is the approach I would take to this problem.



So rather than moving the board around, I would move the camera around the board and then move the player object relative to the board. I didn't include a way of changing the zoom but this is is easy.

Hope someone finds this helpful.

Login to post a reply

Server time is: 2026-07-10 08:26:51
Your offset time is: 2026-07-10 08:26:51