I got some stupid question about matrix type. Is there any predefinded matrix type in OpenGL? If yes - how can I load it?
Thanks in advance!
I got some stupid question about matrix type. Is there any predefinded matrix type in OpenGL? If yes - how can I load it?
Thanks in advance!
There is modelview,projection&texture matrices. To set them as identity matrices call glLoadIdentity, to modify glRotate(Translate)f + additional scale commands. To swith between them call glMatrixMode(GL_MODELVIEW) for ex.
Do you mean, like a matrix struct? If so, there isn't one defined in OpenGL. When you get the matrices with glGetFloatv, you just get them as a float array. There's nothing to stop you from making your own struct with a float array of 16 floats, though.
Deiussum
Software Engineer and OpenGL enthusiast
You are in beginner forum, rigght? I'd recomend you reading red book & try to start using simple stuff like glRot../Trans.., because serious matrix transformations comes only with fake embos bumpmaping & vertex/fragment progs and that sort of things don't bother yourself with this stuff right now, that'll become clearer later on (automaticaly) I can say that from my own experience All you need to know now is what each matrix affects. ModelView->object transforms&positioning Projection->how 3D object is transformed in 2D. Texture matrix isn't used quite often.
I'd say that learning how opengl works internally to rasterize,that is convert world-space vertices to pixels,is definately worth it.Knowing that means knowing what opengl can and can't do and it might save a lot of wasted time on useless questions.I don't mean you should learn exactly how perspective projection works from a mathematical point of view,at least not as a beginner,but you also shouldn't believe than glRotatef rotates your camera or world in some magic way(but you can of course think of it this way to visualize transforms).glRotate just creates a rotation matrix and multiplies it with the current one.It can be used for modeling viewing,texture animations or even projection tricks(I assume).
First of all is the Matrix stuff not that hard and second forget about glTranslate/glRotate and do your own matrix operations since it's much easier to control your Objects/Lights/etc in the way you want it. I started OGL with creating my own matrix stuff and can't say that I miss anything from not using glRotate/glTranslate. And knowing some vector and matrix math is no bad thing in grafx programming. Just my 2 cent.Originally posted by M/\dm/\n:
You are in beginner forum, rigght? I'd recomend you reading red book & try to start using simple stuff like glRot../Trans.., because serious matrix transformations comes only with fake embos bumpmaping & vertex/fragment progs and that sort of things don't bother yourself with this stuff right now, that'll become clearer later on (automaticaly) I can say that from my own experience All you need to know now is what each matrix affects. ModelView->object transforms&positioning Projection->how 3D object is transformed in 2D. Texture matrix isn't used quite often.
Hey! Thanks
Firstfull : I know veritces and matrix mathematics but my problem is that I don't know what to do with the matrix and why is it so important. You see, I know there is some matrix in OpenGL but how does it work - how pixels coordinates are computed and how can I with them.
Secondary : I am not sure if it's a good idea to write my own transformatios because the performance'll be worser, that's for sure.
Where can I find a descripiton of how OpenGL work exactly?
Thanks again
As I told, try to look for RedBook. Despite the fact it's old it's book No1 in OGL. About performance, aplying rotations by standart GL f calls will be faster, + you dont need to care about modelview matrix, which actually consists from two matrices. And I can't believe that someone is going to tell me that manual matrix creation is whole lot better, just take a look how that looks (RedBook) every element is a whole formula and I think that standart f calls will be the fastest ones. I bet they are written in assembler. Of course, somtimes you need to get the matrix, but thats usually in vertex programs and that's another story (NICE story), and even then you usally import OGL matrix to vcard registers & preform simple multiplication with each vertex.
BTW custom matrixes are usually used in advanced techniques, starting from billboarding.
[This message has been edited by M/\dm/\n (edited 12-14-2002).]
I am not talking about setting up all matrices on your own.
For the projection matrix I let OGL do the stuff. For my models I keep a matrix for every one and pass this to glMultMatrix after using gluLookat to set up my camera.
And for the speed issues I don't think that it will help much to do my three additions for a translation in assembler. It seems to be quite fast. Rotations are a little more complex and need some multiplications but when I ask my profiler my transformations seem not to be the big deal.
And I am quite sure that most people do the transformations on their own and just pass the matrices to OGL (just think about using quaternions for rotations).
And even for some simple frustum culling you need the projection and modelview matrices and if you want to get screen coords from world coords (or the other way round) you need them, too. And this I think are not advanced techniques (just think about mouse input from the user). But I also don't think that billboarding is an advanced technique.
p.s.:and to the 'f calls', 'fv calls' are faster
[This message has been edited by satan (edited 12-14-2002).]
Modelview is just one matrix.Conceptually though it is used ofr two different things(modelling and viewing).As I told, try to look for RedBook. Despite the fact it's old it's book No1 in OGL. About performance, aplying rotations by standart GL f calls will be faster, + you dont need to care about modelview matrix, which actually consists from two matrices. And I can't believe that
If every element has to be a whole formula then it will be.Hiding it behind a function call won't change things.The glRotatef call for example just fills a suitable matrix and doues glMultMatrix for you.So creating your own matrices might save you from the function calling overhead.But of course that's negligible nowadays.Let's consider this though:someone is going to tell me that manual matrix creation is whole lot better, just take a look how that looks (RedBook) every element is a whole formula and I think that standart f calls will be the fastest ones. I bet they are written in assembler. Of course, somtimes you need to get the
glTranslatef(a,b,c);
glRotatef(d,0,0,1);
The above code first calculates a (4x4) translation matrix then does a matrix mutiplication to multiply it with the modelview matrix.Then it goes on to calc. the rotation matrix and does another multiplication with the modelview matrix.Now consider this:
search google for the matrix and quaternion faq.Look through the matrix section and find suitable matrices for translation (matrix T) and rotation (matrix R).Now take pencil and paper and translate them to get M=T*R an do:
float M[16]={...};
glLoadMatrixf(M);
Now this fills one matrix (but still calculates two) and does one multiplication.Which do you think will be faster?But as satan said (this sounds kinda funny ) this won't make much difference so don't go about optimizing all you transformations until the last optimization step.Just get it working first!
Regarding assembler.Asm helps you write nice tight code for an inner loop but it doesn't do magic.Using assembler to assign values to a vector won't help much.Calculating sines and cosines with fsincos might but I haven't looked into that.
Matrices are used to do transformations.Just because GL provides functions to hide the actual math it doesn't mean that using it directly is advanced.BTW custom matrixes are usually used in advanced techniques, starting from billboarding.
Besides knowing how something works ,or better wanting to find out is the whole essence of science.So instead of just issuing glRotatef calls and thinking they're some obscure opengl command to make my cube rotate I'd want to find out what exactly happens,...and then still use glRotatef because it's faster.As longs as it suits me and until I optimize.
[This message has been edited by zen (edited 12-14-2002).]