|
-
Aug 16th, 2003, 11:53 AM
#1
3d Mapping
How can I show a 3d point on a 2d screen (picturebox)?
Given the following...
* The 'camera' position as (X,Y,Z)
* The direction that the camera is pointing in, as heading (from 0 degrees) and elevation (upwards is 0 degrees)
* The 3d coordinates of the point in question as (X,Y,Z)
I've been busting my ass for days over the trigonometry but I can't get it working...
VB Code:
Public Function Translate3D2D(ByVal X As Single, ByVal Y As Single, ByVal Z As Single) As POINTAPI
'POINTAPI is just a UDT with X and Y (both single) members
Dim Ret As POINTAPI
Dim dx As Single, dy As Single, dz As Single
Dim Ax As Single, Ay As Single, Dist As Single
dx = X - mcamCamera.X
dy = Y - mcamCamera.Y
dz = Z - mcamCamera.Z
'Ax is the horizontal angle between the cam heading and the point
Ax = mcamCamera.Heading - (Atn(dx / dz) + 180) 'probably wrong
'dist is the horizontal distance (xy plane)
Dist = Sqr((dx * dx) + (dy * dy))
'Ay is the vertical angle between the cam elevation and the point
Ay = mcamCamera.Elev - Atn(dy / Dist) 'probably wrong
'convert these angles into screen coordinates
Ret.X = (mcamCamera.ZDist * Tan(Ax))'probably wrong
Ret.Y = (mcamCamera.ZDist * Tan(Ay))'probably wrong
Translate3D2D = Ret 'pass results back to the calling procedure
End Function
Where am I going wrong?
Please help.
Regards, Adam
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|