3D matrix translations

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

3D matrix translations

Post by RyoDC »

Never understanded them. How they work?
Well, I understand, for example, that we have a matrix, containing, for example, object vertices as 3d-coordinates, one for x, one for y and one for z, imagine, that we have 8 those coordinates. Then it somehow transformated (multiplied on smth or added with smth), depending on camera view and projection type, and we receive a 2d-coordinates of polys on the screen. But I've always wondering about that part when it's 'somehow transformated'. On what exactly thay are multiplying by, to what they added, on which stage do we count our camera coordinates and etc.? I tried to read articles on the net, but they are all so embarassing, so I drop the idea of reading them in a far basket. But still the idea of my own game bother me and I can get rid of it, so still wanna to develop and understand.
How do I try to build a Dreamcast toolchain:
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: 3D matrix translations

Post by BlueCrab »

I suggest picking up a good book on computer graphics if you really want to understand these types of things in depth (and maybe a book on Linear Algebra). I've used this particular textbook for a few classes (or rather the second edition thereof), and found it to be pretty good.

The rest of this is all off of the top of my head, so I apologize if I screw any of it up or don't explain it clearly...

Basically, all of your standard 3D transformations can be represented as 4x4 matrices. To combine two transformations, you multiply their matrices together. As an example, the identity transformation (i.e, one that does nothing looks like this as a matrix:

Code: Select all

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Lets say you want to translate your coordinates by some arbitrary (x,y,z) amount. Your matrix to do that would look something like this:

Code: Select all

1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
Once you're done chaining your transformations by matrix multiplication, you use the resulting matrix to transform your coordinates. You do this by matrix vector multiplication. Since you have a 4x4 matrix, you will need a 4 element vector to do the multiplication. For this, take your point (Px,Py,Pz) and add a 4th (w) component to it, and set it equal to 1. Then you can do the multiplication in the normal fashion, and you should end up with a 4 element vector. If the w component of the final vector is not equal to 1, then you'd generally divide each component by that w for the final result (Tx,Ty,Tz).
Ayla
DC Developer
DC Developer
Posts: 142
Joined: Thu Apr 03, 2008 7:01 am
Has thanked: 0
Been thanked: 4 times
Contact:

Re: 3D matrix translations

Post by Ayla »

Thank you, that was very interesting. Is there a way to accelerate those calculations on the SH-4? Does it provide some kind of SIMD instructions?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: 3D matrix translations

Post by BlueCrab »

You have two vector-related opcodes on SH4. Specifically, FIPR - Floating Point Inner Product; and FTRV - Floating Point Transform Vector. FIPR calculates the inner product of two vectors. FTRV does the matrix/vector multiplication that's needed for transforming the coordinates in the last step. Both of them operate much faster than if you were to do all the floating point operations manually to implement them.
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: 3D matrix translations

Post by RyoDC »

BlueCrab, ty. Ironically, today my academical group were receiving credit for the course "Image formation for computer graphics", while I was passing Computer systems. While I was waiting for a teacher, I had some time, which I spend for reading manual for those course, were those matrix translations were pretty described, lol. But anyway, thanks for your explanation too. And yes, and I need to read a few books dedicated to this topic.
How do I try to build a Dreamcast toolchain:
Image
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

Re: 3D matrix translations

Post by RyoDC »

Crab, can you advice any good book about 3d graphics algorithms in modern games? I mean how these all lightning and camera effects are achieved, it could be very interesting to read, I thought.
How do I try to build a Dreamcast toolchain:
Image
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5652
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: 3D matrix translations

Post by BlueCrab »

Your best bets for books about 3D Graphics in modern stuff may be references about recent versions of OpenGL and the actual OpenGL specification itself. Other than that, I could only recommend various academic papers that I've read over the years, which would probably end up getting pretty expensive to get a hold of (unless you belong to some institution that gets them for free).
Post Reply