12-12-2002, 10:29 PM

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!

Thanks in advance!

View Full Version : Matrix etc...

12-12-2002, 10:29 PM

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!

Thanks in advance!

M/\dm/\n

12-12-2002, 10:51 PM

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.

Deiussum

12-13-2002, 06:07 AM

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.

M/\dm/\n

12-13-2002, 06:57 AM

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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif don't bother yourself with this stuff right now, that'll become clearer later on (automaticaly) I can say that from my own experience http://www.opengl.org/discussion_boards/ubb/smile.gif 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.

zen

12-13-2002, 07:26 AM

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).

satan

12-13-2002, 09:20 AM

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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif don't bother yourself with this stuff right now, that'll become clearer later on (automaticaly) I can say that from my own experience http://www.opengl.org/discussion_boards/ubb/smile.gif 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.

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.

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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif don't bother yourself with this stuff right now, that'll become clearer later on (automaticaly) I can say that from my own experience http://www.opengl.org/discussion_boards/ubb/smile.gif 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.

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.

12-14-2002, 03:08 AM

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

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

M/\dm/\n

12-14-2002, 06:03 AM

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).]

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).]

satan

12-14-2002, 09:49 AM

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by satan (edited 12-14-2002).]

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 http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by satan (edited 12-14-2002).]

zen

12-14-2002, 04:27 PM

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

Modelview is just one matrix.Conceptually though it is used ofr two different things(modelling and viewing).

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

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:

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 http://www.opengl.org/discussion_boards/ubb/smile.gif) 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.

BTW custom matrixes are usually used in advanced techniques, starting from billboarding.

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.

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).]

Modelview is just one matrix.Conceptually though it is used ofr two different things(modelling and viewing).

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

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:

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 http://www.opengl.org/discussion_boards/ubb/smile.gif) 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.

BTW custom matrixes are usually used in advanced techniques, starting from billboarding.

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.

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).]

M/\dm/\n

12-15-2002, 08:47 PM

Still I prefer using stadart fcalls in OGL, less stuff to think about. And later (where I need) I do all the matrix stuff in vert progs.

zen

12-16-2002, 02:03 AM

Yep,that's exactly what I'm talking about as well http://www.opengl.org/discussion_boards/ubb/biggrin.gif Just wanted to point out that handcoding something that's taylored to your specific needs can always potentially be better than the generic api version(worst case is same efficiency if you do it just like the api).Unless of course the api doesn't expose enough information.(like in the case of texture paging for example where opengl might actually do better since it knows more about the VRAM's state)

12-17-2002, 11:30 AM

Thanks you all! Now I see that OGL is much more interesting (but I don't say it became easier...). There's one thing I'm still courius about... THE REDBOOK? How can I get it and what is it about exactly. I suppose that I won't find in my country but still... is worth buying?

satan

12-17-2002, 02:57 PM

http://fly.cc.fer.hr/~unreal/theredbook/

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.