Public Group

# Graphics matrices give odd render results

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

## Recommended Posts

Hello all,

I've been fiddling around with matrices. I think I have everything it working, however, the results seem kind of strange.

No rotation:

45 degrees rotation around the z-axis.

It seems like the proportions after rotations are incorrect, is this just me or what?

I've set the FOV to 90 degrees and the aspect ratio to 1024/768 for a 1024x768 window.

Thanks in advance for any help.

##### Share on other sites

By far the most common error would be the way you calculate the aspect ratio. If both the dividend and the divisor are integers, then, depending on the language, you are likely getting an integer division so the aspect ratio is an integer. Solution is to cast either the dividend or the divisor, or both, to a floating point value to force a floating point division.

##### Share on other sites

(Un)fortunately, this is not the case. Are there any other common mistakes?

##### Share on other sites

http://pastebin.com/4hgiY8vr

I've tried to include everything without too much clutter.

##### Share on other sites

Are WINDOW_WIDTH and WINDOW_HEIGHT floating point values? If not, you are doing integer division when calculating the aspect ratio.

Edited by Brother Bob

##### Share on other sites

Camera c(1, 100, .25*TAU, WINDOW_WIDTH / WINDOW_HEIGHT);

are WINDOW_WIDTH and WINDOW_HEIGHT integers? Try this

Camera c(1, 100, .25*TAU, (float)WINDOW_WIDTH / WINDOW_HEIGHT);

EDIT: Ninja'd

##### Share on other sites

Oh sorry, yes:

const static float WINDOW_WIDTH = 1024;
const static float WINDOW_HEIGHT = 768;


##### Share on other sites

void setLookat(const Vector3f& target, const Vector3f& up)

{
n = target.normalized();
u = up.normalized().cross(n);
v = n.cross(u);

computeView();
}

If n and u aren't orthogonal you need to normalise v after the cross product, try that...

##### Share on other sites

As far as I know n and u are orthogonal for target=(0,0,1) and up=(0,1,0) but I've changed

v = n.cross(u)

to

v = n.cross(u).normalized()

but still the same image.

Maybe I should have mentioned this earlier, but the quad is a square, the vertex coordinates are:

{

{-0.5f,  0.5f, 1},
{ 0.5f,  0.5f, 1},
{-0.5f, -0.5f, 1},
{ 0.5f, -0.5f, 1}

}

• 19
• 22
• 23
• 16
• 10