RobotRock
RobotRock

Reputation: 4459

Why is my OpenGL program using matrix rotations displaying nothing?

I can't find how to create the view matrix with yaw, pitch and roll. I'm working with LWJGL and have a rotate function available.

    viewMatrix.setZero();
    viewMatrix.rotate(pitch, new Vector3f(1.0f, 0.0f, 0.0f));
    viewMatrix.rotate(yaw, new Vector3f(0.0f, 1.0f, 0.0f));
    viewMatrix.rotate(roll, new Vector3f(0.0f, 0.0f, 1.0f));
    viewMatrix.m33 = 1.0f;
    viewMatrix.translate(position);

I am doing something fundamentally wrong, and I hate the fact that I can't fix it do to the lack of documentation (or my lack of google skills).

I do not transpose the matrix.

As a note, position is a zero vector and I do not see anything on the screen (when view matrix is zero I do).

Added: I am trying to reach the equivalent of the following:

    GL11.glRotatef(pitch, 1.0f, 0.0f, 0.0f);
    GL11.glRotatef(yaw, 0.0f, 1.0f, 0.0f);
    GL11.glRotatef(roll, 0.0f, 0.0f, 1.0f);
    GL11.glTranslatef(position.x, position.y, position.z);

Upvotes: 2

Views: 374

Answers (2)

Tal Darom
Tal Darom

Reputation: 1409

You should use viewMatrix.setIdentity() instead of viewMatrix.setZero() to initially set the matrix to a unit matrix, instead of zeroing the matrix.

Upvotes: 3

Fonix
Fonix

Reputation: 11597

compounding rotations like that is the wrong way to go about it, try this: http://tutorialrandom.blogspot.com/2012/08/how-to-rotate-in-3d-using-opengl-proper.html

Upvotes: 0

Related Questions