Graphics matrices give odd render results

Started by
18 comments, last by Paradigm Shifter 10 years, 5 months ago

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:

KjDRt8q.jpg

45 degrees rotation around the z-axis.

Z1rjnak.jpg

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.

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

Advertisement

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.

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

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

Show the code instead.

http://pastebin.com/4hgiY8vr

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

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

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

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

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Oh sorry, yes:


const static float WINDOW_WIDTH = 1024;
const static float WINDOW_HEIGHT = 768;
"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

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...
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

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}

}

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me

This topic is closed to new replies.

Advertisement