Sign in to follow this  
Great_White

About matrices

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this