About matrices

Started by
5 comments, last by Great_White 15 years, 7 months ago
Hi all, I've just started to learn Cg programming from the Cg Tutorial book. So far, I'm confused about matrix implementations used in the book's examples. When I used them in the OpenGL, I get different pespective and view matrix values: OpenGL's matrices are the transpose of the implemented functions. Is this due to the column major matrices that OpenGL using ? In addition, I tried to implement the OpenGL matrix routines according to this ref.site but these are giving strange results. Any idea on how to fix them? Thanks.
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
Advertisement
what kind of a universe is this? Seen 52 times no reply yet c'mon...
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
Quote:what kind of a universe is this? Seen 52 times no reply yet c'mon...
These forums get a fair amount of traffic - a high view-to-reply ratio is not uncommon. (Also, it's the weekend, and things tend to be a little slower on the weekend.)

I'm not familiar with Cg so I can't really answer your questions, but I seem to recall that Cg matrices are laid out in memory in row-major order and therefore are transposed relative to their OpenGL counterparts. I don't know that for sure though - just give it some time, and it's likely that someone who's familiar with Cg will be able to provide you with some answers.
I can't give a ton of help on this subject but I know the matrices you use will be dependent on the graphic API your using. OpenGL will mirror a standard math representation of a matrix while directX is using the transpose (correct me if I'm wrong please). With that in mind I would just make sure your using "apples to apples" with examples to your API or make sure your doing the proper conversions.
Quote:Original post by Skaff
I can't give a ton of help on this subject but I know the matrices you use will be dependent on the graphic API your using. OpenGL will mirror a standard math representation of a matrix while directX is using the transpose (correct me if I'm wrong please). With that in mind I would just make sure your using "apples to apples" with examples to your API or make sure your doing the proper conversions.


Hmm my problem is when I implement and send the transformation matrices(all are right handed) such as found in the ref site above to the Cg using cgSetMatrixParameterfr() function, I'll get different results. I'm using column major format due to OpenGL, and sending them with the cgSetMatrixParameterfr() which is row major. So the question is how Cg is using transformations: is it column major bec. of OpenGL or row major ? which one should I use to obtain correct results?
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein
You can use either - just as long as its consistent. The only real difference between using column major vs. row major is that you need to keep in mind that the order of multiplications should be different between the two. Both options will be able to give you "correct" results. However, I'd recommend using whatever the underlying API uses (ie. use what OpenGL uses).
NextWar: The Quest for Earth available now for Windows Phone 7.
Quote:Original post by Sc4Freak
You can use either - just as long as its consistent. The only real difference between using column major vs. row major is that you need to keep in mind that the order of multiplications should be different between the two. Both options will be able to give you "correct" results. However, I'd recommend using whatever the underlying API uses (ie. use what OpenGL uses).


as far as I know OpenGL matrix ordering is P*V*M*p where P is projection , V is view and M is world matrix. So this order should be reversed if we use row major with Cg?

[Edited by - Great_White on September 21, 2008 10:28:18 PM]
"A human being is a part of a whole, called by us,universe, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."A. Einstein

This topic is closed to new replies.

Advertisement