Jump to content
  • Advertisement
Sign in to follow this  
fireshadow4126

Custom Matrix Stacks

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

i've been trying to implement custom matrix stacks (like GL.PushMatrix() and GL.PopMatrix()), but I've run into some trouble, and I don't quite understand the problem. Could someone point me to a good tutorial on this?

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
You have a "MatrixStack" class.

It contains limited or unlimited array of matrix objects and index (current stack index).

By default, "index" = 0.

When you use push matrix you do something like that:



 stackMatrices[index++] = <matrix which you want to load into stack>;



If you are using limited size of array of matrices you need to check for "stack overflow" before using operation above. (for example, index >= MAX_STACK_SIZE)

When you use pop matrix do something like that:



 <OpenGL Matrix State> = stackMatrices[--index];



But you need to check "index" for "stack underflow" before using operation above. (for example, index > 0).

If you want to create a matrix manipulator (translate,rotate,...) which has a stack you need to use "stackMatrices[index]" instead of "matrix" variable.

Push and pop are look like:



// push

 stackMatrices[index+1] = stackMatrices[index];

 index++;

// pop

 index--; 



Here you also need to check for "stack overflow" (for "push") ... (if array limited) and "stack underflow" (for "pop") before command execution.

And then send it to GL when you want.




Best wishes, FXACE.

Share this post


Link to post
Share on other sites


<OpenGL Matrix State> = stackMatrices[--index];



Use this if your matrix stack class affect matrix states of OpenGL. Otherwise, just "index--".




Best wishes, FXACE.

Share this post


Link to post
Share on other sites
Thanks a lot!

I now understand how to push and pop a matrix, but how do I actually apply transformations, like Rotate, Translate, and Scale? And once transformations are done, what do I actually do with them to let OpenGL know about it?

Share this post


Link to post
Share on other sites
 


I now understand how to push and pop a matrix, but how do I actually apply transformations, like Rotate, Translate, and Scale?  And once transformations are done, what do I actually do with them to let OpenGL know about it?


You can implement it by yourself (its not a problem) or get the source code of OpenGL Mesa Lib and to make it workable in your application.


"to let OpenGL know about it?" - you mean apply matrix to OpenGL?

Share this post


Link to post
Share on other sites
Yes, I mean apply matrix to OpenGL. usually I think it has to do with GL.LoadMatrix(), but I'm using shaders, and I've normally been sending the MVP of my camera straight to the shader. So, what order do I multiply with the camera matrix?

Share this post


Link to post
Share on other sites

Yes, I mean apply matrix to OpenGL.  usually I think it has to do with GL.LoadMatrix(), but I'm using shaders, and I've normally been sending the MVP of my camera straight to the shader.  So, what order do I multiply with the camera matrix?


You can use any way as you wish.

If you want to use matrix stack only as model matrix, so: mvp = <"camera matrix"> * <"matrixStack[index]">.





Best wishes, FXACE.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!