Jump to content
  • Advertisement
Sign in to follow this  
Tahir

problem with glLoadMatrix

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I am having a bitter problem, my program has the following stucture in a class, list is member of the class GLWidget: void GLWidget::initalizeGL() { qglClearColor(trolltechPurple.blue()); glShadeModel(GL_FLAT); glEnable( GL_DEPTH_TEST); glFrontFace(GL_CW); list= makeList(); } void GLWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScaled(zoom, zoom, zoom); glRotated(xRot / 16.0, 1.0, mid, mid); glRotated(yRot / 16.0, mid, 1.0, mid); glRotated(zRot / 16.0, mid, mid, 1.0); draw(list1, true, 0.0, 0.0, 0.0, -2.0 * (zRot / 16.0) - 9.0, 1, 1); } GLuint GLWidget::makeObject() { GLuint list; list = glGenLists(1); glNewList(list, GL_COMPILE); glBegin(GL_LINE_STRIP); do some drawing........ glEnd(); glPushMatrix(); glMatrixMode(GL_MODELVIEW_MATRIX); glLoadMatrixd(mat); // mat is my own 16 integer array matrix glBegin(GL_LINE_STRIP); do some drawing........ glEnd(); glPopMatrix(); glEndList(); return list ; } void GLWidget::draw(GLuint list, bool model_trafo, GLdouble dx, GLdouble dy, GLdouble dz, GLdouble angle, GLdouble scale_x, GLdouble scale_y) { glPushMatrix(); glTranslated(mx, my, mz); glCallList(list); glPopMatrix(); } void GLWidget::setZRotation(int angle) { normalizeAngle(&angle); if (angle != zRot) { zRot = angle; emit zRotationChanged(angle); updateGL(); } } Now it works perfectly fine, the rotation for the drawing i draw Without the block of glLoadMatrix. And transformation, rotation, scaling etc work fine that drawing. But NOT ON THE DRAWING DRAWN WITH MY OWN TRANSFORMATION MATRIX LOADED WITH glLoadMatrix. Note that PaintGL() is called each time the UpdateGL() is called. Can any body help me ? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Is your matrix a one dimension column major order?

Share this post


Link to post
Share on other sites
My matrix is column major matrix.

Like
double mat[16];

mat[0]=temp[0];
mat[1]=temp[1];
mat[2]=Z;
mat[3]=0;
mat[4]=temp[2];
mat[5]=temp[3];
mat[6]=Z;
mat[7]=0;
mat[8]=0;
mat[9]=0;
mat[10]=1;
mat[11]=0;
mat[12]=trans_mat.ef.xp;
mat[13]=trans_mat.ef.yp;
mat[14]=Z;
mat[15]=1;
Problem i have is that i want to change transformation without calling whole drawing function each time. I want the change of transformation by just calling glScale or glRotate() and then calling the display list. THis works fine if i dont load my own matrix.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if mat[2]=Z; then this is row major.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
or some combination of both as the translation lives in 12 13 14 15

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
or some combination of both as the translation lives in 12 13 14 15

Share this post


Link to post
Share on other sites
basically Z is always 0. I may also can write

mat[0]=temp[0];
mat[1]=temp[1];
mat[2]=0;
mat[3]=0;
mat[4]=temp[2];
mat[5]=temp[3];
mat[6]=0;
mat[7]=0;
mat[8]=0;
mat[9]=0;
mat[10]=1;
mat[11]=0;
mat[12]=trans_mat.ef.xp;
mat[13]=trans_mat.ef.yp;
mat[14]=0;
mat[15]=1;

12,13,14 are translation coordinates. So is it correct to load this mat like

glLoadMatrixd(mat);

??

Share this post


Link to post
Share on other sites
IMHO whether the matrix is in row or column major format is not directly obvious since the definition of the local variables used is unkown. mat[2] in column major order is xz, i.e. the z co-ordinate of the x vector, so assigning Z may be okay. However, assigning Z to both the rotational/scaling part (mat[2], mat[6]) but also the translational part (mat[14]) is curious. Could you please explain what those local variables should denote?


EDIT: Yes, [12] to [14] store the translational part for OpenGL.

Share this post


Link to post
Share on other sites
Basically i am converting a 2D matrix into 3D with Z=0. And for this, i have the following matrix.

mat[0]=temp[0];
mat[1]=temp[1];
mat[2]=0;
mat[3]=0;
mat[4]=temp[2];
mat[5]=temp[3];
mat[6]=0;
mat[7]=0;
mat[8]=0;
mat[9]=0;
mat[10]=1;
mat[11]=0;
mat[12]=trans_mat.ef.xp; //X coordinate
mat[13]=trans_mat.ef.yp; // Y coordinate
mat[14]=0; // Z = 0
mat[15]=1;

temp contains the 2D transformation matrix, and trans_mat.ef.* has translation vector.

Share this post


Link to post
Share on other sites
Not necessarily the one problem currently looked at, but: The order of glPushMatrix and glMatrixMode inside makeObject seems me wrong.

GLuint GLWidget::makeObject()
{

GLuint list;
list = glGenLists(1);
glNewList(list, GL_COMPILE);

glBegin(GL_LINE_STRIP);
do some drawing........
glEnd();

/// the following two lines should be exchanged IMHO
glPushMatrix();
glMatrixMode(GL_MODELVIEW_MATRIX);

glLoadMatrixd(mat); // mat is my own 16 integer array matrix
glBegin(GL_LINE_STRIP);
do some drawing........
glEnd();
glPopMatrix();

glEndList();
return list ;
}


The current order would make problems only if another matrix than MODELVIEW is active when this routine is called. However, it would be better to clarify the code at all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!