Jump to content
  • Advertisement
Sign in to follow this  
MichaelBarth

OpenGL Best Way to Achieve Transformations?

This topic is 968 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

Hi there!

 

I've recently been getting pretty in depth in learning OpenGL and boy is it complicated. I've never dealt with matrices before, not even matrix math in high school or the like.

 

Aside from understanding that, I'm trying to understand the best way to perform transformations. Which from what I gather is by using your own matrices such as view, projection, and model and multiplying them together. Which again, I don't understand them, nor have I really grasped the concept of what the projection, view, and model matrix really are.

 

Up to this point I've been using glTranslate to achieve what I want as far as translations go. But, in reading I notice that people seem to be using the shader as a way to manipulate position with matrices. Which this seems a little odd to me, do you need to do that? Or is there a way to do the same thing without a shader? I know at some point I'd be implementing shaders anyway which I'm already looking into, but still.

 

I'm just having a very difficult time wrapping my head around these concepts, especially trying to teach it to myself as I don't have a teacher. If somebody could please explain this to me like I'm an idiot, which I won't deny, I kind of am, I'd greatly appreciate it.

 

Any help in understanding these concepts is much appreciated and I just wish I was smarter.

Share this post


Link to post
Share on other sites
Advertisement

You should learn about matrices and you should learn about shaders as using glTranslate etc is quite dated. you can still use them until you are comfortable without of course. You can use shaders without having to use matrices and vice-versa. I would personally start with matrices as they will fit in to what you are doing now - instead of using glTranslate you just use glMultMatrix (I believe that is the function,t here is also glLoadMatrix)..

 

In a sense you are already using matrices but OpenGL is creating them for you. You can think of a matrix (though this isn't all they are used for mathematically) as being used to transform a point in one 'space' into a point in another 'space'. Initially it is a difficult concept to understand, the 'screen' in OpenGL goes from -1 to +1 for both x and y, that is screen space. When you define something in the world that is world space but then you also have model space and view space.. It's quite a lot and it generally goes from Model space->world space->view space->screen space. When you use glTranslate and so on (at a basic level) you are doing the 'World Matrix' which is the matrix that moves from model space to world space. The 'View Matrix' is what then turns from world space into view space, finally the 'Projection Matrix' is what transforms from view space to screen space. Often in a shader you might see MVP (model view projection) which is them all multiplied together into one matrix that transforms straight from model space to screen space.

 

I'd definitely suggest you try to find some tutorials for this. Translation matrices are easy enough to make as are scale. Rotation are a bit more difficult. Actually multiplying them together into a single matrix is a great deal of maths (I never even saw matrix multiplication until I went to university). 

 

I found this link which seems reasonable:

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

It is using a prebuilt matrix class so you wouldn't have to create your own matrix code.

 

Modern OpenGL you pretty much have to use shaders and you have to use matrices (although I noticed Glew has glTranslate functions still, not sure how that's working though) so it is probably a good idea not to rely on using older methods of doing things.

 

If you are doing 2D stuff then you can use shaders without any of the matrix or transforming stuff, just make sure all the points you use are between (-1 +1,-1 +1) and they will be on screen.

 

When I was 'Getting back into it' recently I followed this tutorial:

https://open.gl/drawing

Which got me running with setting up shaders and drawing some basic things. It also has a section on transformation using matrices. I haven't watched this series but they link to it in the tutorial and it might be useful for you to watch something rather than reading, though I briefly checked it and it is more general matrices rather than just using them for transformations:

https://www.khanacademy.org/math/algebra2/alg2-matrices/basic-matrix-operations-alg2/v/introduction-to-the-matrix

Edited by Nanoha

Share this post


Link to post
Share on other sites

I have been where you are not so long ago. You have to get some grasp on matrices. But I would not recommend trying to know everything there is about them. I picked up a book called Math primer for Graphics and Game development and Chapter 7 introduction to matrices it gives you the fundamentals. When you read this chapter you will understand that a matrix is just a bunch of vectors. Best bet is to start from 2x2 matrices and multiply them yourself on a piece of paper to see what is going on.

Check this website out: http://www.songho.ca/opengl/gl_matrix.html
 play around with the example.

Check this guy out he also gives an awesome explanation on MVP 




 A lot of matrix operations are in glm library, take a look at it. 

This is also another video but a bit harder to grasp but it also explains a lot on Camera transform as long as you get the concept I think it will benefit you.



Just like most things matrices are not too hard when you pick them apart and get the concept.
Hope that helps.

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!