PDA

View Full Version : Projection matrix issue (using a coded 4x4)



jrdIis
12-28-2014, 10:33 AM
The below matrix set up works until I hit the projection matrix. Until that point the square shows up flat - nearly in the middle of the screen. After adding the proj_mat, depending on the calcs I use I get differing results. Normally, I can't see the graphic - some of the calculations I tried allow me to see the square if I roll around an angle, but it's never where I expect it to be. I've tried multiple solutions
http://www.songho.ca/opengl/gl_projectionmatrix.html
http://www.geeks3d.com/20090729/howto-perspective-projection-matrix-in-opengl/
http://ogldev.atspace.co.uk/www/tutorial12/tutorial12.html




glViewport(0.0f, 0.0f, width, height);
glEnable(GL_DEPTH_TEST);

.....

GLfloat x_roll_floaters[4][4] = {
{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, cos((x_roll_angle*3.141592654)/180), sin((x_roll_angle*3.141592654)/180), 0.0f},
{0.0f, -sin((x_roll_angle*3.141592654)/180), cos((x_roll_angle*3.141592654)/180), 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}
};
GLfloat y_roll_floaters[4][4] = {
{cos((y_roll_angle*3.141592654)/180), 0.0f, -sin((y_roll_angle*3.141592654)/180), 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{sin((y_roll_angle*3.141592654)/180), 0.0f, cos((y_roll_angle*3.141592654)/180), 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}
};
GLfloat z_roll_floaters[4][4] = {
{cos((z_roll_angle*3.141592654)/180), sin((z_roll_angle*3.141592654)/180), 0.0f, 0.0f},
{-sin((z_roll_angle*3.141592654)/180), cos((z_roll_angle*3.141592654)/180), 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}
};
GLfloat view_floaters[4][4] = {
/*right up look*/
{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}
};
GLfloat proj_floaters[4][4] = {
{0.138f/1.777f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.222f, 0.0f, 0.0f},
{0.0f, 0.0f, -1.0f, -0.2f},
{0.0f, 0.0f, -1.0f, 0.0f}
};


vertex shader


mat4 model = z_roll * y_roll * x_roll;/
gl_Position = proj_mat * view_mat * model * vec4(position, 1.0f);/


Graphic


0.2f, 0.2f, -1.0f,
0.2f, 0.4f, -1.0f,
-0.2f, 0.4f, -1.0f,
-0.2f, 0.2f, -1.0f


Thanks.

GClements
12-28-2014, 12:12 PM
Are you transposing the matrices when passing them to OpenGL?

By default, GL expects matrices in column-major order, but C uses row-major order, so you need to set the transpose parameter to glUniformMatrix*fv() to GL_TRUE.

If you fail to do that, the only effect upon the rotation matrices will be to reverse the rotation direction, but the projection matrix will be garbage.

jrdIis
12-28-2014, 12:46 PM
Wonderful, will give that a try later tonight.
I thought it automatically changed to column-major.

Ty much.