IGNORED

# Let's talk 3D graphics

## Recommended Posts

So ... how far are we away from a version of "I, Robot" or "Major Havoc" on the 8-bit?

##### Share on other sites

Well, I would wait for him to complete his project. Then, it's a working 3D engine that can do some stuff.

At that point, hacking on it to generalize input to it would make some sense for other projects. My .02

Doing it now sort of adds complexity to what is already going to have some. And there are memory constraints. Probably important to do the project and not do other things, until that's done so that the RAM is there for the project. Again, my .02

##### Share on other sites

I'm not sure if I can make it clear for anyone, but I will start with something and then we can focus on anything not clear.

I use matrices for representing camera and objects rotation (not angles). I multiply object matrix and inverse camera matrix to get so called model-view matrix. That transforms vertex coordinates from object space right into camera space. So transformation of 1 point is just 3 axis vector multiplied with 3x3 matrix.

After this I do clipping with viewport. I use 90 degrees view angle, so limits of what I can see are simply planes of X=Z, -X=Z, Y=Z and Y=-Z. That simplifies clipping a bit.

Perspective transformation is also simpler because of 90 degrees view angle, it's just x = X/Z, y = Y/Z.

I can see that your trying to explain this, but I really don't understand at all, matrices? Are you using tables or real-time calculations?

##### Share on other sites

I can see that your trying to explain this, but I really don't understand at all, matrices? Are you using tables or real-time calculations?

Here's a good primer:

https://en.wikipedia.org/wiki/Matrix_(mathematics)

There would be no 3D graphics without this stuff. If you'd like to learn more, get some books at the library, on "Discrete Structures", and "Matrix Algebra", and read them while reading a book on "3D Computer Graphics". Going over the basics of "Set Theory" is also good. You should also have some kind of grasp of Geometry & Trigonometry. Also, it would help to learn & understand a programming language that includes arrays. Most modern ones do. Hope that helps!

##### Share on other sites

Here's a good primer:

https://en.wikipedia.org/wiki/Matrix_(mathematics)

There would be no 3D graphics without this stuff. If you'd like to learn more, get some books at the library, on "Discrete Structures", and "Matrix Algebra", and read them while reading a book on "3D Computer Graphics". Going over the basics of "Set Theory" is also good. You should also have some kind of grasp of Geometry & Trigonometry. Also, it would help to learn & understand a programming language that includes arrays. Most modern ones do. Hope that helps!

##### Share on other sites

or codebase64.org, C#hacking issues for fundamentals on 3d and 8bit computers.

as I have published the source you can see that I am setting up the rotation matrix (3x3) in 16bit and then multiply everything out.

@MrSid

you mentioned that you are doing transformation as well into your matrix but would that not be a 4x4 then? I am interested really how you actually do the camera/worldview problem upfront.

##### Share on other sites

```;matrix temp
mtmp1	org *+1
mtmp2	org *+1
mtmp3	org *+1
mtmp4	org *+1
mtmp5	org *+1
mtmp6	org *+1
mtmp7	org *+1
mtmp8	org *+1
mtmp9	org *+1
mtmp10	org *+1
mtmp11	org *+1
mtmp12	org *+1
mtmp13	org *+1
mtmp14	org *+1
mtmp15	org *+1
mtmp16	org *+1
mtmp17	org *+1
mtmp18	org *+1
mtmp19	org *+1
mtmp20	org *+1
mat	org *+1 ;18 bytes!

```

this is the rotation matrix variables

amd here the preparation of the matrix:

```.proc render_scene
;prepare rotation matrix
makemat:
; mat format M_lo(3,3) ;M_hi(3,3) = 9 bytes low, 9 bytes hi
lda angy+1
sec
sbc angz+1
tax
clc
sta mtmp1

lda angy+1
clc
tay
clc
sta mtmp2

lda sintab_rotl+\$c0,x
sec
sbc costab_rotl,y
sta mat+0
lda sintab_roth+\$c0,x
sbc costab_roth,y
sta mat+9

lda sintab_rotl,x
sec
sbc sintab_rotl,y
sta mat+1
lda sintab_roth,x
sbc sintab_roth,y
sta mat+10

ldx angy+1
lda sintab_rotl,x
asl
sta mat+2
lda sintab_roth,x
rol
sta mat+11

lda angx+1
clc
tax
sec
sbc angy+1
sta mtmp4

lda angx+1
sec
sbc angz+1
tay
sec
sbc angy+1
sta mtmp3

lda sintab_rotl,x
sec
sbc sintab_rotl,y
sta mtmp5
lda sintab_roth,x
sbc sintab_roth,y
sta mtmp6

lda costab_rotl,x
clc
sta mtmp7
lda costab_roth,x
sta mtmp8

lda costab_rotl,x
sec
sbc costab_rotl,y
sta mtmp9
lda costab_roth,x
sbc costab_roth,y
sta mtmp10

lda angz+1
sec
sbc angx+1
tay
lda sintab_rotl,y
sec
sbc sintab_rotl,x
sta mtmp11
lda sintab_roth,y
sbc sintab_roth,x
sta mtmp12

ldx mtmp3
ldy mtmp4
lda costab_rotl,x
clc
sta mtmp13
lda costab_roth,x
sta mtmp14
asl
ror mtmp14
ror mtmp13

ldx mtmp1
ldy mtmp2
lda sintab_rotl,y
sec
sbc sintab_rotl,x
sta mtmp15
lda sintab_roth,y
sbc sintab_roth,x
sta mtmp16
asl
ror mtmp16
ror mtmp15

lda costab_rotl,x
clc
sta mtmp17
lda costab_roth,x
sta mtmp18
asl
ror mtmp18
lda mtmp17
ror
sec
sbc mtmp13
tax

lda mtmp18
sbc mtmp14
tay

txa
clc
sta mat+3
tya
sta mat+12

ldx mtmp3
ldy mtmp4
lda sintab_rotl,x
sec
sbc sintab_rotl,y
sta mtmp17
lda sintab_roth,x
sbc sintab_roth,y
sta mtmp18
asl
ror mtmp18
lda mtmp17
ror
clc
tax
lda mtmp18
tay
txa
sec
sbc mtmp7
sta mat+4
tya
sbc mtmp8
sta mat+13

lda angx+1
clc
tay
lda angy+1
sec
sbc angx+1
tax
lda sintab_rotl,x
sec
sbc sintab_rotl,y
sta mat+5
lda sintab_roth,x
sbc sintab_roth,y
sta mat+14

lda angx+1
sec
sbc angy+1
tax
lda costab_rotl,x
clc
sta mat+8
lda costab_roth,x
sta mat+17

ldx mtmp1
ldy mtmp3
lda sintab_rotl,x
sec
sbc sintab_rotl,y
sta mtmp13
lda sintab_roth,x
sbc sintab_roth,y
sta mtmp14
asl
ror mtmp14
ror mtmp13

lda costab_rotl,x
sec
sbc costab_rotl,y
sta mtmp15
lda costab_roth,x
sbc costab_roth,y
sta mtmp16
asl
ror mtmp16
ror mtmp15

ldx mtmp2
ldy mtmp4
lda sintab_rotl,x
sec
sbc sintab_rotl+1,y
sta mtmp19
lda sintab_roth,x
sbc sintab_roth+1,y
sta mtmp20
asl
ror mtmp20
ror mtmp19

lda mtmp19
clc
sta mtmp19
lda mtmp20
sta mtmp20

lda mtmp19
sec
sbc mtmp9
sta mat+6
lda mtmp20
sbc mtmp10
sta mat+15

ldx mtmp2
ldy mtmp4
lda costab_rotl,y
sec
sbc costab_rotl+1,x
sta mtmp19
lda costab_roth,y
sbc costab_roth+1,x
sta mtmp20
asl
ror mtmp20
lda mtmp19
ror
clc
tax
lda mtmp20
tay
txa
clc
sta mat+7
tya
sta mat+16
```
##### Share on other sites

and then the actual multiplication:

```;x
;y x M = x*m11+y*m21+z*m31+x*m12+y*m22+z*m32+x*m13+y*23+z*m33
;z

;x'''=x*m00+y*m01+z*m02
;y'''=x*m10+y*m11+z*m12
;z'''=x*m20+y*m21+z*m22
max_vert	ldx #max_vertices ;7 for object 2 ;5 vertices for object 1
rot
;x
lda px_l,x
sta t1
lda px_h,x
sta t1+1
lda mat+0
sta t2
lda mat+9 ;hi
sta t2+1
sec
jsr multiply_16bit_signed
lda product+2
sta xn
lda product+3
sta xn+1

lda py_l,x
sta t1
lda py_h,x
sta t1+1

lda mat+1
sta t2
lda mat+9+1 ;hi
sta t2+1
sec ;reuse t1
jsr multiply_16bit_signed
lda product+2
clc
sta xn
lda product+3
sta xn+1

lda pz_l,x
sta t1
lda pz_h,x
sta t1+1

lda mat+2
sta t2
lda mat+9+2 ;hi
sta t2+1
sec ;reuse t1
jsr multiply_16bit_signed
lda product+2
clc
sta xn
lda product+3
sta xn+1
;y
;y'''=x*m10+y*m11+z*m12
lda px_l,x
sta t1
lda px_h,x
sta t1+1
lda mat+3
sta t2
lda mat+9+3 ;hi
sta t2+1
sec
jsr multiply_16bit_signed
lda product+2
sta yn
lda product+3
sta yn+1

lda py_l,x
sta t1
lda py_h,x
sta t1+1

lda mat+4
sta t2
lda mat+9+4 ;hi
sta t2+1
sec ;reuse t1
jsr multiply_16bit_signed
lda product+2
clc
sta yn
lda product+3
sta yn+1

lda pz_l,x
sta t1
lda pz_h,x
sta t1+1

lda mat+5
sta t2
lda mat+9+5 ;hi
sta t2+1
sec ;reuse t1
jsr multiply_16bit_signed
lda product+2
clc
sta yn
lda product+3
sta yn+1
;
;z'''=x*m20+y*m21+z*m22
lda px_l,x
sta t1
lda px_h,x
sta t1+1
lda mat+6
sta t2
lda mat+9+6 ;hi
sta t2+1
sec
jsr multiply_16bit_signed
lda product+2
sta zn
lda product+3
sta zn+1

lda py_l,x
sta t1
lda py_h,x
sta t1+1

lda mat+7
sta t2
lda mat+9+7 ;hi
sta t2+1
sec ;reuse t1
jsr multiply_16bit_signed
lda product+2
clc
sta zn
lda product+3
sta zn+1

lda pz_l,x
sta t1
lda pz_h,x
sta t1+1

lda mat+8
sta t2
lda mat+9+8 ;hi
sta t2+1
sec ;reuse t1
jsr multiply_16bit_signed
lda product+2
clc
sta zn
lda product+3
sta zn+1
```
##### Share on other sites

@MrSid

Hey he's a doctor, DrSid.

MrSid is the other, the one from the Prince of Persia C64 version .

Edited by José Pereira
##### Share on other sites

Another Sid here ? Damn ..

Anyway .. tranformation goes like this:

I use 3x3 matrices. I use position (which makes the 4th row usually) outside the matrix, because I use 8 bits for matrices, and more for position.

So at the beginning I have camera matrix (it's Z pointing to where camera is looking, X goes to camera right, Y to camera up, all is ortonormal - perpenficular to each other and of unity length - that means 7f).

Then I have object matrix. Same sense as camera matrix. Then there is camera position and object posion, let's say in 16 bits (it's more, but it's not imporant now). Then I have object vertices in 8 bits.

First I get so called model-view matrix. It's combination of transformation from object space to world space and then from world space to camera space. So I multiply inverse matrix of camera with object matrix. Inverse camera matrix is easy to obtain, as the matrix is ortonormal, it's just the matrix flipped around its main diagonal.

But as my matrices are 3x3, this matrix does not contain translation. To get correct translation, I have to basically get relative vector from camera to object (just simple subtraction) and transform it into camera space. This is done by multiplying the relative position vector again with inverse camera matrix.

After that it's simple. Each object vertex is multiplied with model-view matrix and then transformed relative position is added to it. This gives me final position of the vertex in camera space.

Sorry I didn't have time to go through your code so far. I don't understand one thing .. in this demo of yours, you don't even need camera, or perspective to that matter. How is it ?

Edited by Dr.Sid
##### Share on other sites

I left out the transformation which comes after the rotation which I can post tomorrow but is nothing but 4 muls and adding middle of screen to result.

You find it in the complete source in the render scene subroutines after the rotation.

Edited by Heaven/TQA
##### Share on other sites

To me, it seems all too obvious that the standard Atari 8-bit hardware is not suitable for 3D graphics as such - that to get a high enough frame rate - you end up with very simple graphics - 2600 like in wire frame/etc.

And I would take a guess - that the alternative is to use pre-drawn graphic objects - which can rotate in 3D - but even so the hardware still has the same frame rate problem.

The only answer is to use hardware enhancement - to get higher frame rates going - and so, would this then be morphing the Atari home computer into a vectrex like machine? Which would seem to be a project not so worthwhile.

Pseudo-3D seems to be only thing possible - looking very effective - the likes in Pole Position, Encounter - and it is in this area you can get fast moving graphics done to a decent standard?

Harvey

##### Share on other sites

It depends on what you are expecting. rescue on fractalus is damned good, same with mercenary, eidolon, koronis rift, star Raiders, encounter just to name few.

##### Share on other sites

To me, it seems all too obvious that the standard Atari 8-bit hardware is not suitable for 3D graphics as such - that to get a high enough frame rate - you end up with very simple graphics - 2600 like in wire frame/etc.

It depends on how you look at it really. Some people may say that the graphics in most normal games are very simple and should be a lot better (like a PC), but to be fair to it's place in time, these machines were made in the late 70s. Therefore I'd say that "for the time", the Atari does well with the wireframe. And when it comes to filled 3D objects, yes, it is slower, but did anyone really think in 1979 that people would be doing that with hardware from then?

Perhaps expecting full frame rate 3D is asking a bit much, but the machine does well considering.

##### Share on other sites

To me, it seems all too obvious that the standard Atari 8-bit hardware is not suitable for 3D graphics as such - that to get a high enough frame rate - you end up with very simple graphics - 2600 like in wire frame/etc.

A good mix of 3D calculations , hardware features, and some trickery as with the C64... would result in jawdropping games....

##### Share on other sites

The problem when you see some demos running - is how much time/resources are there left? to add the gaming content that is missing in the demo?

I'd guess that in a lot? of cases - they are using the resources up - so that there's not enough left to add the game bits?

It's like running a car to it's maximum speed ... almost everything is being used already to achieve what is on screen?

Though I don't know in Project-M - what is it - that is going to be added to that? How is the gaming part actually going to work?

Harvey

##### Share on other sites

The problem when you see some demos running - is how much time/resources are there left? to add the gaming content that is missing in the demo?

I'd guess that in a lot? of cases - they are using the resources up - so that there's not enough left to add the game bits?

It's like running a car to it's maximum speed ... almost everything is being used already to achieve what is on screen?

Though I don't know in Project-M - what is it - that is going to be added to that? How is the gaming part actually going to work?

Harvey

It's here on the the Programming forum, now is exactly two posts under this one:

http://www.atariage.com/forums/topic/174274-project-m-20

Edited by José Pereira
##### Share on other sites

Though I don't know in Project-M - what is it - that is going to be added to that? How is the gaming part actually going to work?

Even though, "Project-M" is called a demo, it is a game already , as you search for keys to open doors. It runs at 20 fps and uses a heavy load of "on the fly register changes" to have the "APAC" mode running.
##### Share on other sites

Even though, "Project-M" is called a demo, it is a game already , as you search for keys to open doors. It runs at 20 fps and uses a heavy load of "on the fly register changes" to have the "APAC" mode running.

Still, to turn it into a full-featured FPS would involve a lot of CPU power needed for large sprites that must be resizeable, clipped when moving half-way behind walls, with collision detection etc. Actually I do not wonder that the work has stalled at the current phase.

##### Share on other sites

Me too.

It's a cool demo though.

But, the project put here is a different sort of thing. Might be a pretty cool thing too. Would hate to see it go away for the same pressures, same discussions put here so many times...

##### Share on other sites

Still, to turn it into a full-featured FPS would involve a lot of CPU power needed for large sprites that must be resizeable, clipped when moving half-way behind walls, with collision detection etc. Actually I do not wonder that the work has stalled at the current phase.

If this is the case --- then it seems the only way to get over it, is to have hardware assistance - taking it away from standard A8 hardware software... not desirable but maybe the only possible solution for a good outcome...

Harvey

##### Share on other sites

But what if the hardware assist was in game's cart, like Nosty's Tomek project - then the acceleration would be available to all users, no special hardware required.

Kinda like SFX chips in SNES games, or the DPC chip in 2600 Pitfall 2.

That would be the best way to go IMHO if one could not achieve the results alone.

sTeVE

##### Share on other sites

If this grows into something new similar to Mercenary or C64s Moonfall it will be great!

Give me 3d wireframe game any day of the week, I'm happy

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.