]]>It's no big deal, it only does that when I tilt a lot, like > 45 deg. I'm still learning about all that matrices stuff in OpenGL.

Thanks Reed for your help. Have a Happy New Year....

]]>Hmm. It shouldn't be affecting the depth value of objects. You can see for yourself that the matrix doesn't change Z values; it only affects Y values. I haven't tried this myself but as far as I can envision in my head, the pseudo-pitch should only slide things around, not make them expand/contract on screen.

Your code looks correct though, so I'm not sure what's going on.

]]>Never mind about shearing too much the more I pitch up/dn, that's expected.

But when I pan up/dn, it works but it also affect the Z, meaning, it's also moving away or closer. Is that normal too?

]]>oh I see what you mean! It's working, but it's not quite right. Here is what I do. My matrices are in row major but I transpose them before sending them to OpenGL using glLoadMatrixf...

My view matrix M1...

`Z = CamDir; // CamDir is vec3(0,0,-1) rotated by CamRot then normalized. X = Normalize(Cross(Vec3(0,1,0),Z)); Y = Cross(Z,X); M1 = ( X.x, X.y, X.z, 0, Y.x, Y.y, Y.z, 0, Z.x, Z.y, Z.z, 0, 0, 0, 0, 1 );`

Then your shear matrix M2...

`a = tan(CamRot.x); // CamRot is already Deg->Rad M2 = ( 1, 0, 0, 0, 0, 1, 0, 0, 0, a, 1, 0, 0, 0, 0, 1, );`

Then the cam pos matrix M3...

`M3 = ( 1, 0, 0, -CamPos.x, 0, 1, 0, -CamPos.y, 0, 0, 1, -CamPos.z, 0, 0, 0, 1, );`

Then I build the view matrix by doing...

`ModelViewMatrix = m2*m1*m3`

It looks good, and verticals are verticals, I have depth too, but it shear too much the more I pitch up/dn.

]]>OK, if you want to look up/down then you'll need the pseudo-pitch I mentioned.

When you construct your view matrix for a normal camera, you'd usually do it by combining some rotations for yaw and pitch (and maybe roll). The shear matrix I'm talking about would replace the pitch rotation.

If your camera starts out in standard position, facing along the -Z axis, you'd normally do a X-rotation to pitch it. Instead, you're going to do a YZ shear, meaning there will be an offset along the Y axis proportional to position along the Z axis. The matrix for it will go like:

`[1 0 0] [x y z] [0 1 0] = [x y+az z] [0 a 1]`

The value 'a' there is the shear amount, which is equal to the tangent of the pitch angle. The matrix above is written for row-vector math; transpose it if you're using column vectors in your app. Move the 'a' to a different component of the matrix if you need to shear along different axes.

]]>That's exactly what I did Reed, but the problem is, I don't want to only display my model horizontally. For example, my camera is on a street at human height over the street, looking at high buildings. I want to look up a bit but I want the verticals to stay verticals. The same with Ortho projection, you can still look up/down, rotate etc. and the verticals still stay verticals except there is no depth. So I'm trying to build a matrix that will do kind of like ortho except with depth. Do I make sense?

]]>You're making it way more complicated than it needs to be. Just get a regular camera view and projection matrix working for your raytracer. You can look up the docs for glOrtho, glFrustum, and gluPerspective and they give you the exact formulas for the matrices. So just use those and get regular cameras working.

Then, for two-point perspective just use a regular camera with no pitch or roll, just yaw, so it stays horizontal. That's all there is to it. Forget the idea of an extra "two-point matrix". There's no such thing. It's just the regular view and projection matrix, with the camera horizontal.

(Optionally add back in a pseudo-pitch by shearing the camera up and down instead of rotating it. This is the only part that would be different from a standard camera matrix stack.)

]]>I finally got the Ortho to work in OpenGL without using glOrtho. thanks for the links.

For the two-point perspective, I have found lots of documentation, but I just can't get it to work in OpenGL. I am not understanding it or I'm not using it right. What I want to do is use it with glLoadMatrixf after using glMatrixMode(GL_PROJECTION); or glMatrixMode(GL_MODELVIEW); and I don't know which of the two to use, but I assume it's the model view matrix. Also, do I have to build the normal view matrix first then multiply it with the two-point matrix? I'm lost!!!

]]>Then you are not zooming the camera, you are moving it.

For ortho you have, well google.

For parallel you have

]]>It's not for a game but for my raytracer!

My zoom is done by moving the camera forward/back.

I do not use gluPerspective, glOrtho or gluLookAt. I'm trying to make my own matrices for them, which I did for the normal Projection and View matrices, but I'm having problem for Ortho and Parallel projection.

]]>So you don't want to pitch the camera up and down? You want the camera to rise and fall instead?

Zoom is easy, just increase or decrease the field of view Rotating around the vertical is easy, take a forward vector and rotate it by the current heading

Then just create a look at matrix from the camera position towards the rotated forward vector. Create a perspective matrix with the desired field of view and you are away.

When you have it working, a neat trick is to zoom in and move the camera at the same time to get the famous horror movie camera trick.

]]>Yes, but I do want to rotate, pan and zoom, just like in ortho view!

]]>It's not something you do with a matrix. That's down to the controls. You just don't let the user tilt it up or down.

]]>So how do you set such matrix to keep the camera horizontal?

]]>I think I remember a StackOverflow question about this once. IIRC, two-point perspective is just regular pinhole perspective where you're looking at a scene that has lots of vertical lines (like buildings, fence posts, etc), and you keep the camera horizontal, not tilting it up and down. That way vertical lines in the scene are guaranteed to be mapped to vertical lines on screen.

(You can actually still get a form of vertical camera motion by shearing the frustum up and down rather than tilting - since it keeps vertical lines vertical that way.)

The matrix for it would be the same as the regular perspective projection, since it's just a restriction that the camera be horizontal.

]]>What would be the correct OpenGL matrix for "two point perspective"? and would I have to multiply the projection matrix by it?