# 3D Projection

This topic is 3560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have two objects in the 3D graphics portion of my GDI Game Engine... // TDPointPair Is An Object Containing Two TDPoints // The Camera Is A TDPointPair // TDPoint Is A Point In 3D Space // Conversion from 3D to 2D // X, Y, Z are the objects 3D Location // DX, DY, DZ copied from wikipedia // CX, CY Are the screen x, y coords Dim CX, CY, DX, DY, DZ As Double DX = Math.Cos(Camera.PointTwo.Y) * (Math.Sin(Camera.PointTwo.Z) * (Y -Camera.PointOne.Y) _ + Math.Cos(Camera.PointTwo.Z) * (X - Camera.PointOne.X)) - Math.Sin(Camera.PointTwo.Y) * (Z - Camera.PointOne.Z) DY = Math.Sin(Camera.PointTwo.X) * (Math.Cos(Camera.PointTwo.Y) * (Z - Camera.PointOne.Z) _ + Math.Sin(Camera.PointTwo.Y) * (Math.Sin(Camera.PointTwo.Z) * (Y - Camera.PointOne.Y) + Math.Cos(Camera.PointTwo.Z) _ * (X - Camera.PointOne.X))) + Math.Cos(Camera.PointTwo.X) * (Math.Cos(Camera.PointTwo.Z) * (Y - Camera.PointOne.Y) _ - Math.Sin(Camera.PointTwo.Z) * (X - Camera.PointOne.X)) DZ = Math.Cos(Camera.PointTwo.X) * (Math.Cos(Camera.PointTwo.Y) * (Z - Camera.PointOne.Z) _ + Math.Sin(Camera.PointTwo.Y) * (Math.Sin(Camera.PointTwo.Z) * (Y - Camera.PointOne.Y) + Math.Cos(Camera.PointTwo.Z) _ * (X - Camera.PointOne.X))) + Math.Sin(Camera.PointTwo.X) * (Math.Cos(Camera.PointTwo.Z) * (Y - Camera.PointOne.Y) _ - Math.Sin(Camera.PointTwo.Z) * (X - Camera.PointOne.X)) CX = (DX - 0) * (0 / DZ) CY = (DY - 0) * (0 / DZ) Return New PointF(CX, CY) Can someone please fix this so that is gets the appropriate perspective drawing point!

##### Share on other sites
Quote:
 Original post by Robert ColtonCX = (DX - 0) * (0 / DZ)CY = (DY - 0) * (0 / DZ)Return New PointF(CX, CY)

What are you trying to accomplish with this? Your function will always return the point (0 | 0).

##### Share on other sites
Wikipedia says thats what the conversion is from the world coords to the screen coords?

##### Share on other sites
Quote:
 Original post by Robert ColtonWikipedia says thats what the conversion is from the world coords to the screen coords?

Well just look at the equations. 0/anything is always going to be 0. then you multiply 0 and your other variables, which will always be 0, so you are always going to return 0,0. Doesn't make much sense.

##### Share on other sites
You can derive a simple projection easily enough.

(Oh, hmm, bbcode img tags don't work here, ok.)

Take a look at this image:
http://img.photobucket.com/albums/v256/cmscdj/art/3dprojection.jpg

ez == the distance from you eye to screen in whatever units you're using (make something up, experiment.)

z is the z coordinate relative to the screen plane of the object you want to project,

y is the y coordinate relative to the screen plane of the ojbect you want to project.

We want to find sy, the y coord of the projection on the screen.

We know by similar triangles that

sy/ez == y/(ez + z)

So sy = ez * y/(ez + z);

Change out x for y everywhere in the above, and you get the projected x coordinate.

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632941
• Total Posts
3009333
• ### Who's Online (See full list)

There are no registered users currently online

×