Posted: 22nd Apr 2003 21:42
Hi all. This function convert world 3D coordinates into screen 2D position. Please don't ask me explain this math because English not my first language. It's too difficultly for me.

+ Code Snippet
`*******************************************************************************
`*                           Created: 22/04/2003                               *
`*                    By: DMiTR0S   dmitr0s@newmail.ru                         *
`*******************************************************************************

`*******************************************************************************
`*                            Free License Agreement.                          *
`*                                                                             *
`*   The user/developer agrees to include a visible credit to "Dmitry Kuschev" *
`*   within your programs documentation and or web site.                       *
`*                                                                             *
`*   The user/developer agrees to NOT offer the this source code for Sale.     *
`*                                                                             *
`*   Providing the user/Developer agrees in full to the previous Free          *
`*   License Agreement clauses, the user/developer may use this source         *
`*   code FREELY in all their products, commercial or otherwise.               *
`*                                                                             *
`*******************************************************************************


Make Object Sphere 1, 5
Position Object 1, Rnd(10), Rnd(10), Rnd(10)
r=Make Vector3(1)
r=Make Vector2(2)
r=Make Matrix4(3)
FOV# = 61.962
Aspectratio#=((Screen Width()*1.0)/(Screen Height()*1.0))
Sync Rate 0
Sync On
Do
   Control Camera Using ArrowKeys 0, 10, 5

   Set Vector3 1, Object Position X(1), Object Position Y(1), Object Position Z(1)

   World3DToScreen2D(1, 2, 3, FOV#, Aspectratio#)

   Text 10, 10, "Code by DMiTR0S"
   Text 10, 30, "Object Screen X(1) = "+Str$(Object Screen X(1))+" Object Screen Y(1) = "+Str$(Object Screen Y(1))
   Text 10, 50, "World3DToScreen2D X = "+Str$(X Vector2(2))+" World3DToScreen2D Y = "+Str$(Y Vector2(2))
   Sync
Loop

Function World3DToScreen2D(Vec3D, Vec2D, MatrixTemp, FOV As Float, Aspectratio As Float)
   View Matrix4 MatrixTemp
   Transform Coords Vector3 Vec3D, Vec3D, MatrixTemp
   Normalize Vector3 Vec3D, Vec3D
   Multiply Vector3 Vec3D, 1.0/Z Vector3(Vec3D)
   Set Vector2 Vec2D, Int(((1.0-(-1.0*((X Vector3(Vec3D)/Tan(FOV/2.0))/Aspectratio)))/2.0)*(Screen Width())), Int(((1.0-(Y Vector3(Vec3D)/Tan(FOV/2.0)))/2.0)*(Screen Height()))
EndFunction
Posted: 22nd Apr 2003 22:24
Good work!