3d
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
3d
Author Message
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 04 Mar 2009 10:04:37 pm    Post subject:

Well, from what i've been told the equation was something like

x cor \ zcor + screenwith * 1\2 -> xcor where z is I think the distance into the background

and same with y coordinate.. But i'm confused since there's an infinite asymtope at 0 so numbers less then <1 and >0 have you value changes that don't make sense. Second, the graph isn't even linear and I thought that the location of something on the screen was proportionate to the distance.

And about rotations... When you say something rotates like a "Camera", that means everything is actually rotating around you right? Your camera is actually stationary, but everything moves around you from some sin\cos math and an angle of the camera?


Last edited by Guest on 04 Mar 2009 10:06:03 pm; edited 1 time in total
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 05 Mar 2009 10:34:12 am    Post subject:

To implement 3D graphics you need to know a bit about geometry and linear algebra.

About projections:

When you're trying to draw something in "3D", what you're doing is taking coordinates in 3-space and projecting them onto a 2-dimensional screen. If you imagine that the three-dimensional scene actually exists behind the calculator screen, and you draw a ray connecting your eye to some particular point in the scene, the point where that line intersects the screen is where you want to draw the object in question.

Most of the time, the screen we are drawing on is flat, which makes the projection fairly simple. Let's assume that the eye is located at (0, 0, 0), and the plane of the screen is Z = 1. Then the ray between the eye and (Xo, Yo, Zo) is defined by (X, Y, Z) = (0, 0, 0) + (Xo, Yo, Zo) t, for t > 0. The intersection point (Xs, Ys, 1) must lie on this line, so (Xs, Ys, 1) = (Xo, Yo, Zo) t. So, assuming Zo > 0, t = 1 / Zo, and thus Xs = Xo (1 / Zo), and Ys = Yo (1 / Zo).

So what happens when Zo <= 0? Well, think for a minute. What does it mean for Zo to be less than 0? If Zo = 1 is the plane of the screen, and Zo > 1 is stuff behind the screen, then Zo < 1 is stuff in front of the screen. Zo < 0 is behind your eye, and Z = 0 is a plane passing through your eye. If you draw a ray from your eye to something behind your eye, obviously that ray will never intersect with the calculator screen. So if an object has Zo <= 0, you don't draw it. (You may in fact want to "clip" objects before they get that close to your eye, but that's just to improve precision and to deal with lines and polygons that are partly in front and partly behind your eye.)

No, the perspective projection is not linear. Suppose you were to draw a picture of a long straight train track heading off into the distance. In the real world, the ties are spaced evenly, but in your picture they aren't; as they get farther away from the viewer, they get smaller and closer together on the page.

About coordinate transformations:

What does it mean to be stationary? What does it mean to be rotating? Where exactly is (0, 0, 0), anyway? You need to define what your coordinates are. There are often several sets of coordinates that you may want to use. You usually want to define a single set of "world" coordinates, which are considered to be "fixed": a stationary object such as a tree would have a fixed set of world coordinates. The tree itself has a set of "object" coordinates: we might define (0, 0, 0) to be the base of the tree and (0, 1, 0) to be its top. And if we have several trees, each of them has its own set of object coordinates. Your eye has its own set of coordinates, as well; these are the coordinates we used (although we didn't define them properly) in the calculations above. We might say (for instance) that the Z axis points directly into the screen, that X points right, and that Y points down, and that one unit is the distance from the eye to the screen.

The relationship between any two of these coordinate systems is defined by a function called an affine transformation. Affine transformations can consist of rotations, reflections, scalings, and translations, and combinations of these (the tree is scaled by a factor of 10 in the Y direction, rotated 40 degrees about the Y axis, then translated by 50 units in the Z direction, to obtain the world coordinates.) Most of the time, the affine transformations you'll deal with are invertible; you can construct another affine transformation that does the exact opposite (the world is translated by -50 units in the Z direction, rotated -40 degrees about Y, then scaled by a factor of 0.1 to obtain the tree coordinates.) In particular, the transformation from world to eye coordinates will always be invertible: you can say that the eye is rotated by 40 degrees to reach the world coordinates, or that the world is rotated by -40 degrees to reach the eye coordinates. Keep in mind that nothing is actually moving: all we're doing is translating between coordinate systems. When we "rotate" the tree, it isn't actually moving; we're just looking at it with a different set of coordinate axes.
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 05 Mar 2009 10:45:14 am    Post subject:

well, i think people use raycasting

this works as follows:

take a tilemap:
1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1,1

calucate the position of your camera in the tilemap:

1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,X,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1,1

calucate your angle + screen width (in pixels)
say tou are looking upwards, you angle is :
90+45 (about 96/2..)

cast a ray, use trig to deteminate what angle the ray is:
x=.5 root(2
y=.5 root(2

add the numbers to your x and y coordinate:
x=x+sin(135)
y=y+cos(135)

calucate that positon in the tilemap:
1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,X,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1,1

if the tilemap pice is invisuible (zero...), repeat
otherwise, calucate Z, and draw an vertical line from (-screen height/Z) to (screen height/Z) (asume (x,0) is center of the screen)
(= one pixel of your wall)

edit: holy fuck, FloppusMaximus beat me to it Neutral
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 05 Mar 2009 04:57:05 pm    Post subject:

Just so you know, raycasting isn't quite as simple as darkstone knight says it is. Wink You might have to cast a ray like this:

1,1,1,1,1,1,1,1,1,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,X,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,0,0,0,0,0,0,0,0,1
1,1,1,1,1,1,1,1,1,1

Though I didn't get the impression from your post that you were talking about raycasting... more like 3D in general.
Back to top
cjgone
Aw3s0m3


Active Member


Joined: 24 May 2006
Posts: 693

Posted: 05 Mar 2009 06:06:36 pm    Post subject:

Eh, but what happens as something approaches 0? Objects get infinitely large which makes little sense. I have something that i made using that equation to draw a simple board thing. And it does weird stuff as values approach 0.

And theres other weird things that happen too.. I dunno why..


And I'm not sure if what Flop is describing as raycasting, cuz that looks really hard. I just like the proj_x = x \ z + screenwidth\2 thing.
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 05 Mar 2009 08:10:39 pm    Post subject:

cjgone wrote:
Eh, but what happens as something approaches 0? Objects get infinitely large which makes little sense.
That's correct, though. Rasterisers usually clip objects against a near clipping plane (clipping is cutting out parts of objects that lie outside a boundary) with z > 1 to avoid the complications when approaching zero.
Quote:
And I'm not sure if what Flop is describing as raycasting, cuz that looks really hard. I just like the proj_x = x \ z + screenwidth\2 thing.
Raycasting is the rendering technique exemplified in Wolfenstein 3D.
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 05 Mar 2009 10:47:02 pm    Post subject:

cjgone wrote:
Eh, but what happens as something approaches 0? Objects get infinitely large which makes little sense. I have something that i made using that equation to draw a simple board thing. And it does weird stuff as values approach 0.

And theres other weird things that happen too.. I dunno why..


And I'm not sure if what Flop is describing as raycasting, cuz that looks really hard. I just like the proj_x = x \ z + screenwidth\2 thing.

Well, if you put your eye closer and closer to a wall, it seems taller and taller. Razz Though, there is a physical limit on how close you can get, of course.

Edit:
400 posts! Woo!


Last edited by Guest on 06 Mar 2009 10:05:11 am; edited 1 time in total
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 06 Mar 2009 07:07:36 am    Post subject:

calc84maniac wrote:
Just so you know, raycasting isn't quite as simple as darkstone knight says it is. Wink You might have to cast a ray like this:

<map>


thats why is said you need to keep track of X and Y coordinates Rolling Eyes
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 06 Mar 2009 10:27:52 am    Post subject:

Er, no, I didn't say anything about raycasting. I was just talking about geometry. It doesn't matter whether you're trying to write a raycaster, traditional rasterizer, scaled sprites, or whatever -- any way you go about it you're going to have to learn a bit of math.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
3d
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement