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.

Geek Culture / Vectors

Author
Message
Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 27th Mar 2008 04:52 Edited at: 27th Mar 2008 05:06
What is the mathimatical equation to convert a 3D vector to a 2D vector (and vice versa if possible)?

Thanks.

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th Mar 2008 04:59 Edited at: 27th Mar 2008 05:00
In what way? A 3D vector is merely 3 floats, commonly used in game programming at least to specify positions of things or rotations, 2D vectors are similar, but 2 floats, commonly used to store 2D positions of items such as images. You'd use them like this in C++(using D3dx9math.h):



So tell us what you need to do, you can't convert 3 floats into 2 without losing some data.

Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 27th Mar 2008 05:06
Sorry I wasn't more clear. What I meant was, say you have an object 5000 units in front of the camera. I want to convert its 3D position vector to a 2D position vector on the screen (not DB of course).

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th Mar 2008 05:26
To find the position of a 3D point in 2D space using a perspective camera THIS page should be of use.

Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 27th Mar 2008 08:52
Thanks Dark Coder! I got it all in my program now, only it doesn't work because I'm not sure what the viewer point variable is. Isn't the camera position the viewer point (they have both a viewer point AND a camera position in the equation)?

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 27th Mar 2008 09:42
Where? In that equation I see, a which is the 3D point in space, c being the camera position, theta being the camera rotation and e being the 3D point in camera space, i.e. a - c, as done in the latter part of the first equation.

Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 27th Mar 2008 21:06
It's actually quite simple and can be done from Dark Basic Pro.


There's a command called something like "Project Vector3" or something like that. Like for all "Project" and "Unproject" commands. Then simply use matrices and you can get all your 2D/3D transformations.

OR I can make a DLL for you if you like.

Cheers,

-naota

My email actually IS "nocannedmeat@gmail.com". Why? I don't know.
Aex.Uni forums
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Mar 2008 22:28
It isn't difficult at all in DBPro:


The projection matrix needs to be reset if you change resolution, FOV or aspect ratio, the view matrix needs to be reset if you move or rotate the camera, and I haven't figured out yet what affects the world matrix which after minor experimentation some time ago, seems to be the identity matrix (but I'm perfectly happy to be show to be wrong there).

Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 28th Mar 2008 09:35
Ahem.

Quote: "I want to convert its 3D position vector to a 2D position vector on the screen (not DB of course)."


Appreciate the attempted help, but I think what I have will work. I just need to know what the viewer point is.

Quote: "Where? In that equation I see, a which is the 3D point in space, c being the camera position, theta being the camera rotation and e being the 3D point in camera space, i.e. a - c, as done in the latter part of the first equation."


I don't get that e part. I set it to a -c and it didn't work. What do you mean the 3D point in camera space? Shouldn't all I need to know be the point I want to convert, the camera position, and angle. What is this 3D point in camera space?

RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 28th Mar 2008 21:32 Edited at: 28th Mar 2008 21:35
You have the 3D coordinates of the point you want to convert to a screen position in world space. Before you can get the 2D position on screen you need to convert it to camera space, the 3D position of the object in relation to the camera. From this you can get the position of the point in screen space, the 2D vector of the point on the screen.

Oh boy! Sleep! That's when I'm a Viking! | Super Nintendo Chalmers!
Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 28th Mar 2008 22:19 Edited at: 28th Mar 2008 22:20
Thanks Ralph, I get it.

Problem is it doesn't work.

Here's my code from XNA (sorry it's so long). I checked it through....I got everything right:



Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 30th Mar 2008 09:14
Helpz us!

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 30th Mar 2008 10:02
If you're using XNA as your post indicates then you can do exactly what IanM did in his post, the vector projection functions aren't unique to DBPro.

Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 31st Mar 2008 02:32 Edited at: 31st Mar 2008 02:33
Unfortunately I'm not familiar with matrices, that's why I was hoping the other way would work. What may seem simple to you isn't so simple to me.

dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 31st Mar 2008 03:42
Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 4th Apr 2008 01:34
Thanks Dark Coder. I think I can go from here.

Login to post a reply

Server time is: 2024-11-20 02:37:37
Your offset time is: 2024-11-20 02:37:37