Results 1 to 6 of 6

Thread: 3d Mapping

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Unhappy 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:
    1. Public Function Translate3D2D(ByVal X As Single, ByVal Y As Single, ByVal Z As Single) As POINTAPI
    2.  
    3. 'POINTAPI is just a UDT with X and Y (both single) members
    4.  
    5. Dim Ret As POINTAPI
    6. Dim dx As Single, dy As Single, dz As Single
    7. Dim Ax As Single, Ay As Single, Dist As Single
    8.  
    9. dx = X - mcamCamera.X
    10. dy = Y - mcamCamera.Y
    11. dz = Z - mcamCamera.Z
    12.  
    13. 'Ax is the horizontal angle between the cam heading and the point
    14. Ax = mcamCamera.Heading - (Atn(dx / dz) + 180) 'probably wrong
    15.  
    16. 'dist is the horizontal distance (xy plane)
    17. Dist = Sqr((dx * dx) + (dy * dy))
    18. 'Ay is the vertical angle between the cam elevation and the point
    19. Ay = mcamCamera.Elev - Atn(dy / Dist) 'probably wrong
    20.  
    21. 'convert these angles into screen coordinates
    22. Ret.X = (mcamCamera.ZDist * Tan(Ax))'probably wrong
    23. Ret.Y = (mcamCamera.ZDist * Tan(Ay))'probably wrong
    24.  
    25. Translate3D2D = Ret 'pass results back to the calling procedure
    26.  
    27. End Function

    Where am I going wrong?

    Please help.

    Regards, Adam
    I don't live here any more.

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    This I've found browsing through my old notes. I remember it used to work but haven't tried it recently.

    (Refer to the drawing):

    R: distance from origin O to origin sO
    D: distance from origin sO to observer
    Theta: azimuthal angle
    Phi: polar angle
    (x, y, z): 3D coordinates of a point that we want to represent in 2D
    (cx, cy): coordinates of origin sO relative to the screen's lower left corner
    (sx, sy): the sought 2D coordinates

    Let,

    xe = -x sin(Phi) + y cos(Phi)
    ye = -x cos(Phi) cos(Theta) - y sin(Phi) cos(Theta) + z sin(Theta)
    ze = -x cos(Phi) sin(Theta) - y sin(Phi) sin(Theta) - z cos(Theta) + R + D

    Then:

    sx = cx + D * xe / ze
    sy = cy + D * ye / ze
    Attached Images Attached Images  
    Last edited by krtxmrtz; Aug 22nd, 2003 at 10:13 AM.

  3. #3
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Here's a demo project. Looks like once you've set up the approppriate scale to the picturebox, cx and cy are irrelevant...

    Btw, what I've called "Rho" in this project corresponds actually to R + D (see drawing in the previous post).
    Attached Files Attached Files
    Last edited by krtxmrtz; Aug 19th, 2003 at 06:12 AM.

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Great, this looks promising. I'll give it a try tonight.

    Thanks.
    I don't live here any more.

  5. #5
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    i would also really like to know how to do this!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  6. #6
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573
    Originally posted by cyborg
    i would also really like to know how to do this!
    If you mean the derivation I don't have it, I transfered the equations directly from some photocopies I made from a book a few years ago.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width