dcsimg
Results 1 to 7 of 7

Thread: Math: how combine the Z with X and Y?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,171

    Math: how combine the Z with X and Y?

    ok. we have a dot X,Y: 10,20.
    the screen uses X and Y.
    maybe the Z it's just like the zoom.. i don't know.
    but how can i combine the Z with X and Y?
    i can read several books, but if i don't understand these, i can't continue
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,288

    Re: Math: how combine the Z with X and Y?

    I have no idea what you're actually asking. Are you asking what type you use to represent a point in 3D space? You need top provide much more context for the problem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,171

    Re: Math: how combine the Z with X and Y?

    "Are you asking what type you use to represent a point in 3D space?"
    yes, but using math. i think you call it Fake 3D
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,225

    Re: Math: how combine the Z with X and Y?

    The math behind it is simple. You start off with 3D Local Coordinates which are the vertices of your polygons but in your case its a dot. But you are going to need more than just that because you also need the Local Coordinates to turn into Camera Coordinates, the Camera Coordinates to turn into Perspective Coordinates (which is where the Z Coord comes into play for the X and Y), and the Perspective Coordinates to turn into Screen Coordinates. You will also need a Viewplane Width, an FOV (Field of View, usually 45 degrees), as well as the Screenwidth and Screenheight.

    So now you know that, lets do some math:

    Code:
    'This assumes camera position is greater than zero
    
    cameraCoordinates(i).x = vertexList(i).x + cameraPosition.x
    cameraCoordinates(i).y = vertexList(i).y + cameraPosition.y
    cameraCoordinates(i).z = vertexList(i).z + cameraPosition.z
    
    fov = 45
    aspectRatio = 16 / 9
    viewPlaneWidth = 2
    distance = 0.5 * viewPlaneWidth * tan(pi * (FOV / 2) / 180)
    perspectiveCoordinates(i).x = distance * cameraCoordinates(i).x / cameraCoordinates(i).z
    perspectiveCoordinates(i).y = distance * aspectRatio * cameraCoordinates(i).y / cameraCoordinates(i).z
    
    alpha = screenWidth * 0.5
    beta = screenHeight * 0.5
    screenCoordinates(i).x = alpha + alpha * perspectiveCoordinates(i).x
    screenCoordinates(i).y = beta - beta * perspectiveCoordinates(i).y
    And thats it! You can see it in action in my 3D Engine in Pure VB in my sig.

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,171

    Re: Math: how combine the Z with X and Y?

    Jacob: i'm sorry but what you think about these simple\very simple formula:
    ScreenX = ObjectX / ObjectZ
    ScreenY = ObjectY / ObjectZ
    ?????
    (yes without zoom and more)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,225

    Re: Math: how combine the Z with X and Y?

    3d is more than simply dividing x and y by z. Just like reallife, you need a camera to move around, a field of view, and it needs to be converted to screen coordinates. The 3d needs to be projected. What I done is give you the simplest method in doing so.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,171

    Re: Math: how combine the Z with X and Y?

    thank you so much for all... thank you
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width