i drawn a cube and i can rotate it. I would want to print out the position of vertices after rotation. in some tutorials i found that i can use QMatrix4x4 to rotate my cube and the to get the new position of vertices. the i changed mu code:
void MyWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
QMatrix4x4 matrix; // new matrice for transformation
matrix.translate(0.0, 0.0, -10.0);
matrix.Rotate(xRot / 16.0, 1.0, 0.0, 0.0);
matrix.Rotate(yRot / 16.0, 0.0, 1.0, 0.0);
matrix.Rotate(zRot / 16.0, 0.0, 0.0, 1.0);
glBegin(GL_QUADS); //1st quad
qglColor(Qt::green);
glNormal3f(0.0f, 0.0f, -1.0f);
---
glEnd();
}
my question is how to apply the matrix to draw the vertice because glvertex3f can't take that matrix. Then i will print out the new position as follow: ( matrix * QVector3D(0.0f, 0.0f, -1.0f)) for example;
After Some days and thanks to the links you gave me, i had tried to read about Modern OpenGL: Here is my code now:
void GLWidget::paintGL()
{
--------
QMatrix4x4 matrixTransformation;
matrixTransformation.rotate(alpha, 0,1,0);
matrixTransformation.rotate(beta, 0, 1, 0);
QVector3D cameraPosition = matrixTransformation * QVector3D(0,0,distance);
QVector3D cameraUpDirection = matrixTransformation * QVector3D(0, 1, 0);
vMatrix.lookAt(cameraPosition, QVector3D(), cameraUpDirection);
// display the coordinates
foreach(const QVector3D& p, cameraPosition) {
qDebug() << "Rotated position =" << matrixTransformation * p;
}
shaderProgram.bind();
shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix *mMatrix);
shaderProgram.setUniformValue("color", QColor(Qt::white));
shaderProgram.setAttributeArray("vertex", vertices.constData());
shaderProgram.enableAttributeArray("vertex");
glDrawArrays(GL_TRIANGLES, 0,vertices.size());
shaderProgram.disableAttributeArray("vertex");
shaderProgram.release();}
} an error appeared : error C2039: ‘const_iterator’ : is not a member of ‘QVector3D’ error C2039: ‘i’ : is not a member of ‘QForeachContainer’
I had included and in my header but the error still there.
- Is the way i used correct to get the coordinates of vertices??
- the error is from my foreach loop code, and is maybe about the declaration of QVector3D in a qvector3d.h of Qt. How to solve it??
- if the use of transformation matrix , how can iuse a transform feedback object to pass the vertex positions that come out of the vertex shader back into another buffer object. I seen that its another solution to get coordinates of vertices after rotation.
Thanks and sory for my questions which are may be for beginners.