3x3 or 4x4 matrix?

Started by
6 comments, last by Dmytry 19 years, 5 months ago
ok currently I am working on a Raytracing program in c#. My problem is that i know very little of graphics theory! i have currently created a program that can check for planes / polygons / spheres (the easy one of um all hehe the geometric method to solve it is simple as heck). now i know to do a transformationt o an object i am supposed to do the inverse transformation to the ray correct? If this is so do i use 4 x 4 matrix for the transformation or 3 x 3? i have a matrix library form a friend for 3 x 3. i THINK i need a 4 x 4 one though. since i am also planning to write a kinematics library and a nueral net library I _KNOW_ I will need different n x n matrix types. wondering if i should create a general class n x n matrix class <shudder> or just make my specific excelerated 3 x 3 and 4 x 4 matrix classes? hmm. anyways does anyone know which it is? 4 x 4 for 3d transforms or 3 x 3? also anyone have a good link to ray to object checks? not one of these sites. looked here they have good info but if you click some of the links they don't say HOW to do the intersects they just tell you which of the 100-300 dollar books have the info <shudder> me <=== broke http://www.realtimerendering.com/int/ http://www.devmaster.net/articles/raytracing/ http://thorkildsen.no/faqsys/cates/math.html <lots of cool articles> http://fuzzyphoton.tripod.com/ http://easyweb.easynet.co.uk/~mrmeanie/algos.htm <not great but some cool stuff> http://www.cs.unc.edu/~rademach/xroads-RT/RTarticle.html http://www.c-sharpcorner.com/Code/2002/Oct/RayTracing.asp <doesn't even explain how to generate a camera. everything is hard coded. ugg!> http://www.cl.cam.ac.uk/Teaching/1999/AGraphHCI/SMAG/node2.html <best general intersection site i have found EVER! awsome site, al layed out in mathmatical notation consise and precise> so anyone have any other sites? i have used like 40 different search engines. (google yahoo lycos etc etc) and these are the best i could find. if you know a good site for intersection or raytracing please say. also if you know the answer to my matrix info problem. lastly. i don't use other peoples code i will have to write something myself no matter what here. i will look at others code but this project is going in my portfolio so i plan to use only my code =/ so lots and lots of coding! rofl. if anyone wants to see my code i can place a zip of my code / exe. some bugs atm but some fun =-)
Advertisement
If you write *renderer*, go for maximal flexibility - that is, use 4x4 matrices, and use other things in supplemental code and "client" code (just like OpenGL do).

And, i think 3x3 and 4x4 matrices must be implemented specially.

dump:
I'm using 4x4 matrices for general homogeneous coordinate transform and perspective transform. I'm using 3x3matrix&vector(placed in one class that works exactly as 4x4 matrix with lowest row = 0,0,0,1 ) for linear with translation. And i'm using 3x3 for linear without translation. I use Quaternions for variable rotation-only transform, and quaternion&vector for rotation&translation transforms... in summary i have very many things.

[Edited by - Dmytry on November 11, 2004 5:41:32 PM]
For any realistic specialist maths you will need to use 4x4 matrices. That ol' omega can come in handy...
No bombs, No guns, just an army of game creators...
I'll just second that 2x2, 3x3 and 4x4 matrices are generally special-cased rather than being templated. Operations such as finding the determinant or inversion can be written more efficiently for those cases than for the general case. Also, multiplication and whatnot can be unrolled when you know the size, which can gain a little performance.

Can't tell you much about the raytracing, but I will remind you that whatever method you use you'll probably have to distinguish between vectors (such as the direction of a ray), which should only be rotated, and points (such as the origin of a ray) which can be transformed. This can be accomplished through selective use of 3x3 and 4x4 matrices, or by using 4x4 matrices and homogenous coordinates. (There are other ways too.)
Your choices are quite simple. With a 3x3 matrix you can store rotation and scaling, but you need an extra 3d vector to store translations. With a 4x4 matrix, you can store rotationg, scaling and translations all in one transform matrix. The fact that you can use a single object to represent transformations is actually interesting... And you can multiply these matrices to add up transformations, which is also interesting.

All modern renderers go with 4x4, and you should probably go that way as well...

Looking for a serious game project?
www.xgameproject.com
thanks i think i will go this method.

so for a follow up question anyone know how to do the det of a 4 x 4 fast (any tricks i know the standard method)
and this one is mucho important! the INVERSE of a 4 x 4? i can do the inverse of a 3 x 3 but not the 4 x 4

reason: to do a transformation of an object i do the inverse transform to the ray precheck. then check vs the standard object.
Quote:Original post by Max_Payne
Your choices are quite simple. With a 3x3 matrix you can store rotation and scaling, but you need an extra 3d vector to store translations. With a 4x4 matrix, you can store rotationg, scaling and translations all in one transform matrix. The fact that you can use a single object to represent transformations is actually interesting... And you can multiply these matrices to add up transformations, which is also interesting.

All modern renderers go with 4x4, and you should probably go that way as well...


i must say:
for cameras and similar things i'm using quaternion for rotation&vector for translation. And 'em is placed in one object, and can be multiplied together. And multiplication of 'em is as well-defined as multiplication of quaternions or matrices, it's just i defined multiplication myself, other than that, it's as well defined as anything else. Also there's well-defined inverse. This object effectively represent rotation&translation transforms. 'em form noncommutative division algebra, just like quaternions.

There's no reason to use 4x4 matrices if you only want linear and translation. Because in that case you have (0,0,0,1) in your matrix and it is not useful and you can just assume having 0,0,0,1 in all calculations and use 12 floats instead of 16. There's reason to use 4x4 matrices if you want to use w. For example if you want to use homogeneous coordinates. Or if you want to divide by w.

IMHO, most uses of homogeneous coordinates, where you have only w=0 or w=1, it's abuse of 4x4 matrices, and it's more practical to make separate vector and point classes that vector-vector=point, that point may be converted to vector but not other way around, etc.

4x4 matrices is really useful if you want to use w, for example to divide by w, for perspective transforms. And because you never know all uses of renderer, it's better to make it as flexible as possible...
Intel's paper about 4x4 matrix inverse

html version from google

and search i used

It's pretty hard to really explain how 4x4 inverse work and it's hard to prove it's really inverse. I found it's waay simpler to explain how [3x3 matrix & vector] or [quaternion & vector] inverse works.

This topic is closed to new replies.

Advertisement