I'm new to 3D graphics & need help

Discussion in 'Computer Science & Culture' started by martinev.co.uk, May 28, 2002.

Thread Status:
Not open for further replies.
  1. martinev.co.uk Registered Member

    Messages:
    9
    i've been writing VB5 programs for a while now and I'm ok at the simple graphics things. I can draw to the screen, use lines, etc. I have been trying for ages to write some sort of algorithm that turns 3D co-ordinates into 2D screen co-ordinates. Once i've got those, I'll write a program to make polygons at those positions on the form and take it from there.
    but i simply can't get anywhere with getting a 3D view. What's the easiest algorithm to use? I have an array of 3D co-ords to convert to perspective 2D co-ords. Thanks

    Martin
     
    Last edited: Jun 4, 2002
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Stryder Keeper of "good" ideas. Valued Senior Member

    Messages:
    13,105
    I can't help you with the Algorythm but what I can put forwards is what I've observed in particular games.

    Notibly Diablo II. When you look at the characters they have been three dimensional at one point, but the actual character for speed of sprite loading has been converted into directions and frames.

    I mean if you walk towards the current view you have one direction and away another.

    This means that a system that is turning those images to 2 dimensions has to have a corresponding perspective already intergrated. (Some games with the wrong perspective do look really bad)

    I know how every you probably want the graphic to stay three dimensional within the machine but just veiw from a singular perspective. It's truly a pity that I haven't the intention to cover this problem myself.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. Success_Machine Impossible? I can do that Registered Senior Member

    Messages:
    365
    Converting 3D to 2D

    If you have coordinates in 3-dimensions (x,y,z) just drop the z-coordinate, and that will give you the 2-D coordinates (x,y)projected onto the screen. Remember that the (0,0) coordinate is located at the top-left of the screen, so for the points to be visible all y-coordinates have to be negative, and x-coordinates positive (+x,-y).

    Using points, lines, and polygons to generate 3D graphics is called mesh programming. Most professional artists use software such as 3D Studio Max to create complicated shapes and objects in 3D that are based on mesh programming. It is much easier to create these objects using software than to manually enter thousands of point coordinates to represent the object. Using 3D Studio Max these objects can be manipulated via drag-and-drop, as can the mesh points representing them. You can click-and-drag mesh points to modify the shape and create something extraordinarily complicated and artistic. You can even paint the surface with colors and patterns.

    If you want to create animations, you don't necessarily use the 3D object. You take snapshots of the object rotated into dozens or hundreds of orientations. These snapshots (bitmaps) contain less information and require far less time for the computer to access and display on the screen, compared to the original 3D object. You then program the computer to call a sequence of images to create the illusion of action on the screen -- just like an old-fashioned filmstrip. However unlike a filmstrip, these images can be programmed to move around on the screen in response to mouse or keyboard commands, and to interact with other objects (collisions). To test for collisions, simply create a "bounding box", or rectangle, around the objects with a program that tests for overlapping. There is even a windows function you can use (similar to bitblitting) that can test for collisions of bitmaps without any bounding box, but that is beyond my programming experience. Mesh programming is great for artistic programming such as video games, promotional animations, movie-making, and other gimmicks.

    Another type of 3D computing is called Parametric. Parametric geometry uses pure math to represent the 3D object. You can create objects with exact sizes and proportions, that can be tested analytically for volumes, intersections, cut-outs, protrusions, etc. Parametric geometry is often used for engineering because of this analytical capability, and accurate representation. It is HARD to program however, requiring both very serious math and programming skill. I have tried to program simple 2D parametric geometry and given up, even though I have successfully programmed mesh geometry in the past. Parametric software such as Mechanical Desktop are intended to be realistic, not creative. You cannot easily create video games or animations using engineering software, however you can very slowly create a very accurate representation of a car engine.
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. itchy Registered Senior Member

    Messages:
    47
    the algorithm to transform 3d to 2d is:

    screenx = (xres/2) * x / (z + zoffset) + xoffset
    screeny = (yres/2) * y / (z + zoffset) + yoffset

    if the origin of your coordinate system is at the center of the screen then xoffset = xres/2 and yoffset = yres/2. zoffset is the distance from your "eye" to the screen.
     
  8. Brett Bellmore Registered Senior Member

    Messages:
    68
    Success, if he did that, just dumped the depth coord, he wouldn't get any perspective.

    What you want to do is establish a viewpoint in 3d space, and a 2d "window" between the viewpoint and the "eye". Then you draw a line between each of your 3d points, and the "eye", and find it's intersection with the window. What makes this complicated is if you want to be able to place the "eye" at any arbitrary location, looking in any arbitrary direction. The math gets moderately complicated, but it's not calculus. Here, check this site out:

    http://infoweb.magi.com/~dlai/realworld.html

    I remember I had to do exactly what you're talking about for a programming course in college. Problem is, that was 25 years ago, so I don't remember all the details!
     
  9. martinev.co.uk Registered Member

    Messages:
    9
    thanks

    thanks for the responses! I havn't tried any of them yet but the lines from itchy look good. I have thought of just dropping z but as already said this would eliminate any perspetive. I'll look at the site link too.

    In response to the 'window', i have already made a program that plots the x and y of where the line from the 3D point cross the window and it just looks wierd. I suspect the shape of the window is vital. I tried it flat (ie no z) and this lead to perspective but only in z. I.e. the shapes just skewed as they got to the edges. I also tried a spherical window around the 'eye' and that made it look like a fish-eye lense!

    I'll get back to you on what works and maybe you'll see something 3D on martinev.co.uk...
     
    Last edited: Jun 6, 2002
  10. martinev.co.uk Registered Member

    Messages:
    9
    the 3D cube is good now but only as a wire-frame. i will edit this post in a couple of days with a link to the VB5 code i made. then if you lot could guide the code into something better... well, you'll see!
     
Thread Status:
Not open for further replies.

Share This Page