   Calculating perspective
  I know the equations to find the 2d coordinate (position on the screen) of an (x,y,z) point.They are:ScrX = ( Lens*X / Distance ) + CenterXScrY = CenterY - ( Lens*Y / Distance )  However, I only calculate this when the camera position is at (0,0,256) looking straight down the z   axis...  To do that i plug in 256 for the Lens value.  How would i go about positioning the camera at any other position viewing at any angle?Say I wanted the camera to be at (100,100,512) looking toward the left 45 degrees and down 45 degrees?Any help would be great... Thanks 
  if you are using opengl or direct3d then there are functions to do this... if not, then its pretty complicated maths involving matrices ;  Damn, well im not using either of the two.  Im using the standard 2d graphics library package that comes with java.  Anyone have a link which would show me the formulas? ;  You can Translate everything to the invese of your camera so that you are effectively looking down the Z axis again, then use your existing formula ;  Perhaps you should consider using a 3d graphics library if you are wanting to work in 3d... You''re going to create a lot of hard work for yourself if you try to draw things in 3d from a 2d graphics library. Also things will run a lot slower without hardware acceleration. ;quote:Original post by SpaceDude  Perhaps you should consider using a 3d graphics library if you are wanting to work in 3d... ... or learn the math. ;  I''m only doing very basic stuff (rotating a point/Drawing a wireframe box/getting perspectve correct,etc...).  I''m going to teach myself OpenGL all this summer so im trying to put myself in a strong postion to start out.  I want to know as much about 3d calculations as I can before this summer starts (even if it includes methods that OpenGL already does  for you). quote: Perhaps you should consider using a 3d graphics library if you are wanting to work in 3d... You''re going to create a lot of hard work for yourself if you try to draw things in 3d from a 2d graphics library.I''m trying to make this as hard as possible for myself.  ;quote:Original post by MrPoopypants  I know the equations to find the 2d coordinate (position on the screen) of an (x,y,z) point.They are:ScrX = ( Lens*X / Distance ) + CenterXScrY = CenterY - ( Lens*Y / Distance )   However, I only calculate this when the camera position is at (0,0,256) looking straight down the zaxis...  To do that i plug in 256 for the Lens value.  How would i go about positioning the camera at any other position viewing at any angle?Say I wanted the camera to be at (100,100,512) looking toward the left 45 degrees and down 45 degrees?Any help would be great... Thanks   Hello...Where you get this formula?  This is projection of 3d into 2d? what happens with Z? third dimension ;quote:Original post by leo_pardo  Hello...Where you get this formula?  This is projection of 3d into 2d? what happens with Z? third dimension  This is my code directly from my program.  Perhaps this will make it a little more clear for you:int SrcX = ((256*x)/(256-z)) + (size/2);int SrcY = (size/2) - ((256*y)/(256-z)); ;  The trick is to rotate all the coordinates of everything to line up with your camera. Your equation''s X, Y, and distance are really the object''s X, Y, and Z coordinates relative to the camera. The matrix math is the following: each point is represented by a vector that looks like (X Y Z 1). There is a camera matrix that transforms vectors in world space to vectors in camera space (coordinates relative to the camera). The vector in world space is multiplied by the vector in camera space, and the result is a vector in camera space. This vector is then transformed using the equations you posted to get the point in screen space. OpenGL documentation often covers some of this stuff. Also look up how vectors and matrices work (they are just a mathematically concise way to represent lots of multiplications and such). 