3D Games: How do I get the "Z"?

Started by
7 comments, last by Daaark 17 years ago
I'm not a very expierenced programmer. So with the knowledge I have of programming, I know only how to make things happen in the "X and Y" of dimensions. I guess technically a "Z" has to be an illusion because it is a flat screen but when I look at a proffesional game like World of Warcraft, there obviously has to be some sort of way to mimic a "Z" dimension. In world of warcraft you have multiple players looking at things from multiple perspectives and from varied distances. I don't understand how this effect can be achieved. Especially the graphics end, how is it that I can run in a 360 degree circle around a player and see him from every possible angle? How can graphics be that dynamic? I have a really hard time trying to imagine how a 3D game works, I know it's possible but...how? It's like they are working with a dimension which never existed. Can someone please explain it to me?
Advertisement
What API are you using for rendering? Depending on what you're using for graphics, you can initialize in a certain way to allow you to plot points in 3D.
Quote:Original post by ScottC
What API are you using for rendering? Depending on what you're using for graphics, you can initialize in a certain way to allow you to plot points in 3D.


I've heard of an API but I don't know what it is. I only know how to write code in C++. By the way, I wouldn't expect someone to explain something so complicated in full, maybe just explain these API's are and where to find out how to use them or something.
Learn a 3D API. Two of the most popular ones are Direct3D or OpenGL.

But..I will tell you that lots of math is going on. What you are seeing is technically a 2D image...with lots of math. :). The 3D API's though hide most of that math though, and you just have to call it's functions and it will figure out how to do it it's self.

Chad.

EDIT: An API stands for Application Programming Interface. They are used for you to tell your hardware to draw graphics and such and such. Ofcourse this is just a BASIC explanation. So of the most popular ones include SDL (2D Only...but VERY easy to use), Allegro (never used it, but easy also..just like SDL), OpenGL (profesional API that is crossplatform), and DirectX (A collection of API's from Microsoft that only works on Windows. This is profesional also).

Quote:Original post by skunkfart
I'm not a very expierenced programmer. So with the knowledge I have of programming, I know only how to make things happen in the "X and Y" of dimensions.

I guess technically a "Z" has to be an illusion because it is a flat screen but when I look at a proffesional game like World of Warcraft, there obviously has to be some sort of way to mimic a "Z" dimension.

In world of warcraft you have multiple players looking at things from multiple perspectives and from varied distances. I don't understand how this effect can be achieved. Especially the graphics end, how is it that I can run in a 360 degree circle around a player and see him from every possible angle? How can graphics be that dynamic?

I have a really hard time trying to imagine how a 3D game works, I know it's possible but...how? It's like they are working with a dimension which never existed.

Can someone please explain it to me?


Well, are you equally amazed when you watch TV? Or fotographs? Or even art?
There is mathematics governing the relation between lines in three dimensions and the corresponding two dimensional lines on a surface, given a certain perspective, when looking through that surface. Using this you can calculate the corresponding two dimensional image, given the three dimensional geometry and current perspective. That's how 3D games render there graphics.

EDIT: To clarify further. In 2D games you usually have distinct pre-rendered images. These will be static ofcourse, so animation is usually done by having several still images and switching between them, like how film works.
In 3D however (note that this can be done for 2D graphics aswell) you don't have images, but rather geometrical data in terms mathematically defined shapes, usually you only deal with surfaces (most often triangles). You can then calculate the projection of a given 3D shape unto a 2D dimensional surface, which would be your screen. It's hard to give a good explanation unless you know some of the math behind transformations and shapes in mathematical terms.
Best regards, Omid

Boiled down to its essence it's a very simple trick. You work with x,y, and z until it's time to actually draw the thing, then you divide the x and y by the z and use the resulting x and y to draw with. This way, things that are more distant (larger z) are smaller...things are obviously problematic when z=0 occurs, and there is more to it than this, as there are several transforms to do before you even get to this point.

A good math for game programmers book will get you started in the right direction
API - Application Programming Interface. A library of code that has been prewritten such that you can use it to abstract away repetitive, boring, or difficult tasks and focus on the logic of your code alone. Now, of course the level of abstraction offered by different APIs varies but it's certainly a lot easier than writing hardware accelerated graphics routines from the base up.

As has been said, you can actually have as many dimensions as you like. Games and the suchlike use 3 because it's what we're used to - there are a few programs both for fun and for other purposes that deal with more (a common one is to rotate a 4 dimensional hypercube (just a cube in 4 dimensions), producing something called a tesseract).

You simply store the location of a set of vertices as a point (e.g. (1, 1) or (1, 1, 1) for 2/3 dimensions, respectively). You then 'project' these 'world-space' coordinates to the 2D 'screen-space' coordinates of your monitor. The process of the projection handles Z-ordering (what's in front of what), perspective (if necessary), etc. all depending on the camera's location.

However - a lot of this maths is handled by your graphics API. Equally - while it's good to have an idea of how to use vectors and matrices (and quaternions, too) for graphics purposes (transforming objects - translation (moving), rotation, distortion, etc.), you don't need to have really in-depth solid knowledge of the maths behind each of them - or even what they're used for outside of graphics (as far as hobbyists are concerned, anyway, IMMO).
[TheUnbeliever]
The illusion of depth is done through the magic of Perspective Projection.
Quote:Original post by skunkfart
In world of warcraft you have multiple players looking at things from multiple perspectives and from varied distances. I don't understand how this effect can be achieved. Especially the graphics end, how is it that I can run in a 360 degree circle around a player and see him from every possible angle? How can graphics be that dynamic?
Because 3d characters aren't drawn as preset images, they made up of a series of points in space. You can rotate and project them however you like.

http://en.wikipedia.org/wiki/Wire_frame_model
http://en.wikipedia.org/wiki/3D_computer_graphics

This topic is closed to new replies.

Advertisement