Jump to content

  • Log In with Google      Sign In   
  • Create Account


Perspective, Camera, Model - basic matrix math


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 mg_mchenry   Members   -  Reputation: 177

Like
0Likes
Like

Posted 31 August 2012 - 11:27 AM

My matrices are all muddy and I wonder if anyone has a favorite resource for a reference on this.

I have a coordinate system where +x is to the right, +y goes into the screen, and +z is up. But it doesn't always quite work out.

I tried baking my camera matrix into my perspective matrix. Is that a mistake? Should people avoid that?
My camera has x rotation, z rotation, and a location. To get my camera matrix, I start from an identity matrix, do the rotations, then translate by the camera location.

Then I have an ortho perspective matrix. I multiply the perspective matrix by the camera matrix and pass that into the shader. Should I keep it separate?

Well, it's all mixed up. Moving the camera +z has the opposite of expected result. y also seems to be flipped when moving the camera. Yet, objects appear on screen as expected. Translating objects on the screen acts as expected.

I think the camera translations need to be inversed?

The model view matrix works exactly as expected. As does the perspective matrix.

[EDIT]
OK, OK! Before anyone attacks, I see that the camera does not go into the perspective matrix. I took it out and tacked it onto the model view matrix. Makes sense.
http://www.opengl.org/archives/resources/faq/technical/viewing.htm

It's still not doing the right thing, but I'll work it out.

Edited by mg_mchenry, 31 August 2012 - 12:29 PM.


Sponsor:

#2 MarekKnows.com   Members   -  Reputation: 478

Like
0Likes
Like

Posted 01 September 2012 - 05:14 AM

Have a look at video #8 on my website, it should clear some things up: http://www.marek-knows.com/downloads.php5?vmk=gameEng8

---
Free C++, OpenGL, and Game Development Video Tutorials @
www.MarekKnows.com
Play my free games: Ghost Toast, Zing, Jewel Thief


#3 mg_mchenry   Members   -  Reputation: 177

Like
0Likes
Like

Posted 06 September 2012 - 12:06 PM

So one thing I'm wondering is why it isn't common to have three matrices in the shader - one for model-to-wold space, one for world-to-camera space (is that the same as eye space?), and the projection matrix.

In my case, I'm working in javascript. Every object has an mv matrix that still has to be multiplied with the camera matrix before being passed to the shader. There has to be a break even point where it is faster to do that in the shader than in the javascript and I'm just wondering why it isn't normal to do it that way, even for native code.

#4 BornToCode   Members   -  Reputation: 920

Like
0Likes
Like

Posted 06 September 2012 - 12:28 PM

Yes eye space is camera space. You can always break the View Matrix out of the Model. That way when you past the matrices to your shader you can pass three matrices instead of two. If you have a camera class for example, that will be your view matrix. Each Object will have his own wolrd matrix. Then in the shader you can just do Projection*View*World

Edited by BornToCode, 06 September 2012 - 12:30 PM.


#5 Radikalizm   Crossbones+   -  Reputation: 2824

Like
0Likes
Like

Posted 06 September 2012 - 12:29 PM

So one thing I'm wondering is why it isn't common to have three matrices in the shader - one for model-to-wold space, one for world-to-camera space (is that the same as eye space?), and the projection matrix.

In my case, I'm working in javascript. Every object has an mv matrix that still has to be multiplied with the camera matrix before being passed to the shader. There has to be a break even point where it is faster to do that in the shader than in the javascript and I'm just wondering why it isn't normal to do it that way, even for native code.


When you create the WVP matrix on the CPU you'll only have to go through this process once for every mesh. However, when doing this in a shader it'll have to be done for every vertex. For simple meshes the GPU will probably still outperform the CPU as it can do matrix multiplications really fast, but for more complex meshes this could not be the case anymore. You could also take the cost for uploading 3 matrices vs 1 matrix to the GPU into account, but this won't be that much of an issue tbh.

I have to say though that it isn't really a standard to calculate the WVP matrix on the CPU, I've seen many cases where this transformation was always calculated on the GPU without any real drawbacks.

And yes camera-space, eye-space and view-space are all the synonyms Posted Image

I gets all your texture budgets!


#6 mg_mchenry   Members   -  Reputation: 177

Like
0Likes
Like

Posted 07 September 2012 - 07:47 AM

When you create the WVP matrix on the CPU you'll only have to go through this process once for every mesh. However, when doing this in a shader it'll have to be done for every vertex.


Aha, that would be it. Thanks. My meshes only have a few dozen vertices, so shader matrix multiplication still might be faster. Probably faster.

This is a webgl app, so I'd have to test how it works out on low-powered devices with integrated graphics.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS