Game Programming and Development Tools

3D points to 2D points – luke

luke

Member

Posts: 311
From: I use your computer as my second Linux box
Registered: 10-30-2005
Ok, the title basically says it all. What is the equation to convert a 3d point (x,y,z) to a 2d point (x,y)? I've asked this and I didn't get much.

------------------
If you can see Chuck Norris, He can see You.
If you Can't see Chuck Norris, you may be seconds away from death.

guategeek

Member

Posts: 107
From: Guatemala
Registered: 11-08-2005
Not sure exactly what you are asking. In 3D there are usualy 5 numerical values. U, V, X, Y, Z for each verticy (point). The first two U and V refer to a 2D position that is used for texture mapping. The next three refer to the 3D cordinate plane. X and Y are the same as what you learn in school (width and height) and Z is depth. Maybe if you explained what exactly your tring to do I could be more help, good luck on your projects Jeff

------------------

penny

Member

Posts: 101
From:
Registered: 08-15-2006
(Digging deep into the math side of my brain) I believe what you are asking for is 3d projection. As in mapping a set of 3d coordinates on a 2d plane. If that is what you want, check this link http://en.wikipedia.org/wiki/3D_projection

Unless you like matrix math (ugh) check out the simple formulae at the bottom of the page.

------------------
penny --Is. 64

luke

Member

Posts: 311
From: I use your computer as my second Linux box
Registered: 10-30-2005
Thanks penny!
Well, my project idea so far is this:
I have a 3d galaxy which is made up entirely of points(planet systems) and your fleets(something similar to a point) fly around fighting for control of planets. (for an example, check out www.spacetrace.com) Now as you can imagine, there shouldn't ever be more than 2,000 planets/ships in the galaxy at any one time. So I figure that I can get away with using something like SDL for rendering purposes. And the closest thing to a transformation would just be a rotation around the origin.

------------------
If you can see Chuck Norris, He can see You.
If you Can't see Chuck Norris, you may be seconds away from death.

ArchAngel

Member

Posts: 3450
From: SV, CA, USA
Registered: 01-29-2002
sounds like Master of Orion.
man, I love that game. favorite 4X game.

my interest has been peaked. anything to show?

could you explain what exactly you want by converting 3d points to 2d points (besides just erasing the Z-coordinate)

------------------
"Patience, my good citizen, patience. It's bad enough to rob a man of his dream"
-Sydney Carton, Tale of Two Cities
Soterion Studios

luke

Member

Posts: 311
From: I use your computer as my second Linux box
Registered: 10-30-2005
Well, I've never played M of Orion, but Isn't that 2d?

No not yet, Im only designing/thinking about it.

What I want is a '3d' galaxy that I can rotate, and maybe zoom in out on like in www.spacetrace.com

Now that I think about it, I must confess that when I first ran into SDL a couple of years ago, shortly after I found out C++ had no drawimage command, all the tutorials I looked at displayed images to the screen by way of that arcane pointer thing... It was really hard (but I did learn alot about pointer rimatic) and now I find out about the whole blit thing....

------------------
If you can see Chuck Norris, He can see You.
If you Can't see Chuck Norris, you may be seconds away from death.

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
whoa, sounds like a cool game idea. hope you figure it out. i know nothing about it whatsoever, just wanted to give encouragement and say it sounds cool.

------------------

ArchAngel

Member

Posts: 3450
From: SV, CA, USA
Registered: 01-29-2002
I honestly can't find a single screenshot of spacetrace, just a abunch of pictures taken from shows like Babylon 5 and Battlestar Galactica (found one from star wars, too).

are you talking something like in www.swordofthestars.com ?
another Master of Orion clone. and yes, Master of Orion is 2d and spacetrace seems to copy off of it. I wouldn't blame them... I want to, also.

------------------
"Patience, my good citizen, patience. It's bad enough to rob a man of his dream"
-Sydney Carton, Tale of Two Cities
Soterion Studios

luke

Member

Posts: 311
From: I use your computer as my second Linux box
Registered: 10-30-2005
Well, I can't find any image of spacetrace either, and I don't want to register again...

Ok so heres a synopsis of spacetrace:
You have 1 planet and 5000 manpower

The objective is to build a good fleet with that 5000 men and gain points in battle

The map is a 3d representation of some galaxy (kinda like the milky way)
You order your ships around by coords (you tell to go to coord x,y,z)

Now my game idea is this:
You start with 1 planet and 1000 manpower
You can capture planets and expand, also gaining manpower and factories(the more factories you have, the more ships you can build simultaneously)

The tactic is to keep your homeworlds coords secret from the enemy, while getting theirs too. You can use various actions to find out the enemy home world (watching their fleet movement for example) Ships can only be built on the homeworld.

Finally, instead of giving each race/player cookiecutter units Ill give them cookiecutter technologies (rail guns, ray guns etc) to make their own non cookie cutter ships out of. So the game will also be a arms race/tech race.

Practically, the graphics in this don't need to be that great =D
Networking doesn't really need any splines =D
input can be as simple or complex as I please =D
Time can be dialated, and it *can* in theory be a semi MMOG depending on if someone wants to run a server on their comp long enough =DDD

------------------
If you can see Chuck Norris, He can see You.
If you Can't see Chuck Norris, you may be seconds away from death.

JeTSpice
Member

Posts: 433
From: La Crosse, Wisconsin, USA
Registered: 06-10-2006
I saw the wiki thing, but DX/DY---isn't that a derivative? How would one program that? I think that there is a way to do it using atan, tan, sin, cos, etc.

Luke, does the player control the angle of perspective in the game, like in a FPS? Meaning, if you move the mouse, do you rotate and see the galaxies scrolling by? Or is the perspective stationary, like an RTS?

Do they move throughout the planets, or do they remain stationary? If no movement is involved, converting from 3D to 2D might not be necessary.

Can the player rotate up and down?

If the player is confined to travel in one plane along the galaxy's belt, kind of like Wolfenstein, or Doom I only using planets, then I have some code that might help you.

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
quote:
Originally posted by guategeek:
Not sure exactly what you are asking. In 3D there are usualy 5 numerical values. U, V, X, Y, Z for each verticy (point). The first two U and V refer to a 2D position that is used for texture mapping. The next three refer to the 3D cordinate plane. X and Y are the same as what you learn in school (width and height) and Z is depth. Maybe if you explained what exactly your tring to do I could be more help, good luck on your projects Jeff

"In 3D there are usualy 5 numerical values"... theres only really the Vector/Point component (x,y,z) for 3d points, but yes, for vertices they could have the UV. So UV are more for the rendering, and not for a '3D Point'.

I think your wanting to know how to covert from a 3D point (Vector3 or the like (x,y,z)) to a 2D point. As in projecting the 3D point to screen space, or to a specific plane.

(following was taken from 3D Math Primer for Graphics and Game Developers)
V2 = n ((v . n) / ||n||);

in other words:
V2 = n ((v.DotProduct(n)) / n.magnitude());

where n is the vector to be projected onto by v
v is the vector/point (your point you want to project onto n)
V2 is the resulting vector/point (v projected onto n)

The magnitude is same as the length of the vector/point.

The below article should help:
http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64461

Another technique would be to just zero out the z component (or the one you wish to be your 'flat plane').

------------------
Programmer - Team KAIZEN

luke

Member

Posts: 311
From: I use your computer as my second Linux box
Registered: 10-30-2005
Thanks guys, I'm pretty sure that these equations will be more than enough =D

As for cam movement, the camera will not move, but the galaxy can be rotated around by the player. The player basically has a God's eyeview of the galaxy

------------------
If you can see Chuck Norris, He can see You.
If you Can't see Chuck Norris, you may be seconds away from death.

steveth45

Member

Posts: 536
From: Eugene, OR, USA
Registered: 08-10-2005
Well, sure you could get away with SDL, but you can save yourself a lot of headache by using a 3D engine that will take care of all that business for you. I must sound like a broken record, but I think the Irrlicht engine would suit your needs perfectly. It handles the 2D stuff as easily as SDL, and then you can also do the 3D stuff with ease. It handles all the matrices and view frustrum transformations for you. You can mix and match 2D and 3D at the same time. For the 3D view, all you have to do is set the 3D position of the camera and the spot you want the camera facing, like 0,0,0 for the center of the galaxy. The 2D stuff is easy, there is a draw2DImage() function that works with pixel coordinates. That's what I used for the map mode in RevX. Like SDL, Irrlicht also handles keyboard and mouse input. For the stars of the galaxy, you could use billboards, which are like images attached to certain points in space that always face the viewer/camera. The engine comes with examples for everything I just mentioned.

------------------
+---------+
|steveth45|
+---------+

TwoBrothersSoftware

Member

Posts: 141
From: Janesville, Wi USA`
Registered: 08-05-2006
quote:
Originally posted by steveth45:
W, but I think the Irrlicht engine would suit your needs perfectly. It handles the 2D stuff as easily as SDL,

What about Gui's or third party Gui's (file requestors - and buttons) How is support for that with it (I looked and I am impressed - using SDL now and like that but always looking)

luke

Member

Posts: 311
From: I use your computer as my second Linux box
Registered: 10-30-2005
Irrlichit isn't a bad Idea, but my school's gamedev club has decided to go with SDL, and so what the heck conformity is uh...prized in our society isnt it

------------------
If you can see Chuck Norris, He can see You.
If you Can't see Chuck Norris, you may be seconds away from death.

JeTSpice
Member

Posts: 433
From: La Crosse, Wisconsin, USA
Registered: 06-10-2006
Luke, if you are only going to rotate and zoom, you might not need to convert 3D to 2D. Perspective never changes when rotating or zooming, only when the camera's coordinates are changed (like moving forward or strafing, etc.)

The code that I have for a simple FPS is in BASIC. If you can convert it, this might be a solution for you.