# Re: A89: 3d programming

```
> Yes, but what equations would I need is what I should have asked.  Sorry
for
> not being specific enough.  Thanks for your help but, that doesn't answer
> *exactly* what I want/need to know.
>

There are many way to perform 3d programming, some of them being very
simples but not very efficients. In fact all depend of what exactly you want
to do. Do you want just a 3d object that is moving in front of you, like
3dlib does ? Or do you really want to be able to move inside a virtual world
?

In the first case, it is very easy to display a three dimensionnal scene.
You just have to apply some basic equations, you don't need to understand
So, let's say that your 3d object is defined by a list of plots, each of one
having (x,y,z) coordinates. The first thing you have to do is to convert
each of your 3d plot into 2d-coordinates (x', y'), in order to be able to
display it on the screen. That is very easy to do, you just have to use the
following formulas :

x' = (x * d) / (z + d)
y' = (y * d) / (z + d)

Here, d is a constant that in theory define the distance in pixels between
your eyes and the screen. 128 is a good value for it.
After that, it is easy to stroke lines between your plots, for example by
using graphlib::fline.

The second thing you may want to do is to perform rotations on your object.
Then again, you can use the following formulas without understanding them.
Those apply on the 3d-coordinates :

Let's say "a" is the angle.

For a rotation around Z axis :
x' = x.cos(a) - y.sin(a)
y' = x.sin(a) + y.cos(a)
z' = z

(Now, I'm not pretty sure of the following formulas)
For a rotation aroud Y axis :
x' = z.sin(a) + x.sin(a)
y' = y
z' = z.cos(a) - x.sin(a)

For a rotation around X axis :
x' = x
y' = y.cos(a) - z.sin(a)
z' = y.sin(a) + z.sin(a)

After the rotations, you have to apply the same old formula to convert
3d-coordinates into 2d.

I'm not sure that is enough to write a 3d game. Anyway, you should first try
to play with those ones, to be familiar with 3d basis. Then, look around for
a good 3d tutorial (there are many of them on the web, as well as book about
3d in libraries).

```

Follow-Ups:
References: