Plotting 3D points

I know this is sorta not directly related with SDL, but all the tutorials /
demonstrations of the 3D starfield are for dos and in asm. Nothing is truly
described all the way. I’m becoming frustrated because I can’t find a working
formula for plotting 3D coordinates on a 2D screen. I know the concept of a
starfield…but I don’t know how to plot the 3D coordinates.

Status:

200 stars.
x = 1-200 (random)
y = 1-200 (random)
z = 1-200 (1…200)

All I need is a standard formula to plot the 3D coordinates on a 2D surface.

I’ve seen this in tutorials:

x2d = x3d / z;
y2d = y3d / z;

But it doesn’t work.

What am I doing wrong?

Paul Lowe
spazz at ulink.net

Paul Lowe wrote:

All I need is a standard formula to plot the 3D coordinates on a 2D surface.

I’ve seen this in tutorials:

x2d = x3d / z;
y2d = y3d / z;

But it doesn’t work.

What am I doing wrong?

The ‘standard’ formula is a little more complex:
you need to declare a zoom factor, and then do this:

zoom factor values : well, if your zoom equals the screen width the FOV
will
be around 90? [check!], as zoom increases the FOV will get narrower,
etc.

ratio = zoom / z3d;
x2d = x3d * ratio;
y2d = y3d * ratio;

Hope this helps a bit. BTW, any decent computer graphics book will
explain this much more clearly than my ramblings.

James Turner

All I need is a standard formula to plot the 3D coordinates on a 2D surface.

I’ve seen this in tutorials:

x2d = x3d / z;
y2d = y3d / z;

      sx1 = (xx1 + xoff) / ((zz1 + DISTANCE) / ASPECT);
      sy1 = yy1 / ((zz1 + DISTANCE) / ASPECT);

      sx1 = sx1 + WIDTH / 2;
      sy1 = sy1 + HEIGHT / 2;

I chose 250 for DISTANCE and 200 for ASPECT. Note: I figured this junk
out for myself, so it’s probably not quite the way you “really” want to do
it, but it worked for me!

-bill!>From my vector-based “3D Pong” game for X-Window:

      sx1 = (xx1 + xoff) / ((zz1 + DISTANCE) / ASPECT);
      sy1 = yy1 / ((zz1 + DISTANCE) / ASPECT);

      sx1 = sx1 + WIDTH / 2;
      sy1 = sy1 + HEIGHT / 2;

Please define xoff, xx1, yy1, sx1, sy1, zz1, DISTANCE and ASPECT.

I chose 250 for DISTANCE and 200 for ASPECT. Note: I figured this junk
out for myself, so it’s probably not quite the way you “really” want to do
it, but it worked for me!

I really would like the “standard” and “perfect” way of placing a 3D coordinate
on a 2D plain.

thanks,

Paul Lowe
spazz at ulink.net> >From my vector-based “3D Pong” game for X-Window:

      sx1 = (xx1 + xoff) / ((zz1 + DISTANCE) / ASPECT);
      sy1 = yy1 / ((zz1 + DISTANCE) / ASPECT);

      sx1 = sx1 + WIDTH / 2;
      sy1 = sy1 + HEIGHT / 2;

Please define xoff, xx1, yy1, sx1, sy1, zz1, DISTANCE and ASPECT.

xx1, yy1 and zz1 are the x/y/z coordinates in 3d space
sx1, sy1 are the x/y coordinates in 2d space (on the “screen”, hence “s”)

xoff is… uhmm… lemme check :wink: oops… forget that :slight_smile: that’s for my
3d glasses mode… it appies an offset in 3d space so that the two
versions (red and blue) of the line being drawn appear as they’d look
from slightly different positions

DISTANCE is how far away from the 3d origin we are

ASPECT is pretty much like that “zoom” thing the other person mentioned. :slight_smile:

-bill!> > >From my vector-based “3D Pong” game for X-Window:

I chose 250 for DISTANCE and 200 for ASPECT. Note: I figured this junk
out for myself, so it’s probably not quite the way you “really” want to do
it, but it worked for me!

I really would like the “standard” and “perfect” way of placing a 3D coordinate
on a 2D plain.

thanks,

Paul Lowe
spazz at ulink.net

Hi Guys,

What’s the status of the Mac port, in terms of what needs to be done ? I
wouldn’t mind taking another look at it, or discussing it with anyone else
involved.

Mark

Mark Elliott wrote:

Hi Guys,

What’s the status of the Mac port, in terms of what needs to be done ? I
wouldn’t mind taking another look at it, or discussing it with anyone else
involved.

Mark

I was going to do some work on the Mac port, but Sam got talking with a
guy who’s written a library for CodeWarrior Win32 and Mac. He uses DX
and DrawSprocket, and his code is certainly better than mine :slight_smile:

So I was just going to leave it until I heard something back from Sam
regarding incorporationg this guy’s code. I don’t have mucht ime to
spend working on the Mac port on my own, but I’d be happy to help
someone else with testing / polishing / bug-fixing.

Any thoughts?

James Turner

Mark Elliott wrote:

Hi Guys,

What’s the status of the Mac port, in terms of what needs to be done ? I
wouldn’t mind taking another look at it, or discussing it with anyone else
involved.

Mark

So I was just going to leave it until I heard something back from Sam
regarding incorporationg this guy’s code. I don’t have mucht ime to
spend working on the Mac port on my own, but I’d be happy to help
someone else with testing / polishing / bug-fixing.

Any thoughts?

James Turner

Go ahead and collaborate guys, I haven’t heard back from anyone who
said they would work on it yet. :slight_smile:

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/