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

## 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 on other sites
Is your matrix a one dimension column major order?

##### 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 on other sites
if mat[2]=Z; then this is row major.

##### Share on other sites
or some combination of both as the translation lives in 12 13 14 15

##### Share on other sites
or some combination of both as the translation lives in 12 13 14 15

##### 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

??

##### 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 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 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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002297
×