本文整理汇总了C++中QMatrix4x4::rotate方法的典型用法代码示例。如果您正苦于以下问题:C++ QMatrix4x4::rotate方法的具体用法?C++ QMatrix4x4::rotate怎么用?C++ QMatrix4x4::rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMatrix4x4
的用法示例。
在下文中一共展示了QMatrix4x4::rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeViewport
void ViewportViewPerspective::initializeViewport(const QVector3D& surfmin, const QVector3D& surfmax, int width, int height)
{
// add margin to max/min
QVector3D diff = 0.01 * _margin * (surfmax - surfmin);
QVector3D min = surfmin - diff;
QVector3D max = surfmax + diff;
// calculate the midpoint of the bounding box, which is used as the center of the
// model for rotating the model
_midpoint = 0.5 * (min + max);
QVector3D panpoint = _midpoint;
panpoint.setX(panpoint.x() + _panX);
panpoint.setY(panpoint.y() + _panY);
panpoint.setZ(panpoint.z() + _panZ);
// calculate the distance of the camera to the center of the model, following from
// the field of view from the camera
float dist = sqrt((max.y() - min.y()) * (max.y() - min.y())
+ (max.z() - min.z()) * (max.z() - min.z()));
if (dist == 0)
dist = 1E-2f;
if (atan(_field_of_view) != 0) {
_distance = 1.5 * dist / atan(_field_of_view);
if (_distance > 1E5)
_distance = 1E5;
}
else
_distance = 1E5;
// build the vertex transformation matrix from the perspective
// and the angle, elevation
float aspect_ratio = 1.0;
if (height != 0)
aspect_ratio = width / static_cast<float>(height);
_proj = QMatrix4x4();
// create projection
_proj.perspective(RadToDeg(_field_of_view) / _zoom, aspect_ratio, 0.1f, 40.0f);
// find the camera location
QMatrix4x4 model;
model.translate(_panX, _panY, _panZ);
model.rotate(-_elevation, 1, 0, 0);
model.rotate(_angle, 0, 0, 1);
_camera_location = model.map(QVector3D(max.x() + _distance, 0, 0));
// view matrix
QMatrix4x4 view;
view.lookAt(_camera_location, panpoint, QVector3D(0,0,1));
_view = view;
finishSetup();
}
示例2: QGLSceneNode
coordinates::coordinates( float size, float thickness ):
m_node( new QGLSceneNode() )
{
QGLBuilder builder;
builder << QGLCylinder( thickness, thickness, size, 12 );
QGLSceneNode* cylinder = builder.finalizedSceneNode();
cylinder->setPosition( QVector3D( 0, 0, 0.5 * size ) );
cylinder->setEffect( QGL::LitMaterial );
QGLBuilder arrowBuilder;
arrowBuilder << QGLCylinder( 0.01, 2 * thickness, size / 3, 12 );
QGLSceneNode* arrow = arrowBuilder.finalizedSceneNode();
arrow->setPosition( QVector3D( 0, 0, size ) );
arrow->setEffect( QGL::LitMaterial );
QGLSceneNode* x = new QGLSceneNode( m_node );
x->addNode(cylinder);
QMatrix4x4 matrix;
QQuaternion q = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f);
matrix.rotate( q );
x->setLocalTransform( matrix );
QGLSceneNode* xArrow = new QGLSceneNode( m_node );
xArrow->addNode( arrow );
xArrow->setLocalTransform( matrix );
QGLMaterial* xMaterial = new QGLMaterial;
xMaterial->setDiffuseColor( QColor( 255, 0, 0, 128 ) );
x->setMaterial( xMaterial );
xArrow->setMaterial( xMaterial );
QGLSceneNode* y = new QGLSceneNode( m_node );
y->addNode(cylinder);
q = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -90.0f);
matrix.rotate( q );
y->setLocalTransform( matrix );
QGLSceneNode* yArrow = new QGLSceneNode( m_node );
yArrow->addNode( arrow );
yArrow->setLocalTransform( matrix );
QGLMaterial* yMaterial = new QGLMaterial;
yMaterial->setDiffuseColor(Qt::green);
y->setMaterial( yMaterial );
QGLMaterial* yArrowMaterial = new QGLMaterial;
yArrowMaterial->setDiffuseColor( QColor( 0, 255, 0, 128 ) );
yArrow->setMaterial( yArrowMaterial );
QGLSceneNode* z = new QGLSceneNode( m_node );
z->addNode(cylinder);
QGLSceneNode* zArrow = new QGLSceneNode( m_node );
zArrow->addNode( arrow );
QGLMaterial* zMaterial = new QGLMaterial;
zMaterial->setDiffuseColor(Qt::blue);
z->setMaterial( zMaterial );
QGLMaterial* zArrowMaterial = new QGLMaterial;
zArrowMaterial->setDiffuseColor( QColor( 0, 0, 255, 128 ) );
zArrow->setMaterial( zArrowMaterial );
}
示例3: paintGL
void CompasWidget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
m_world.setToIdentity();
m_world.rotate(180.0f - (m_xRot / 16.0f), 1, 0, 0);
m_world.rotate(m_yRot / 16.0f, 0, 1, 0);
m_world.rotate(m_zRot / 16.0f, 0, 0, 1);
/*
QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
m_program->bind();
m_program->setUniformValue(m_projMatrixLoc, m_proj);
m_program->setUniformValue(m_mvMatrixLoc, m_camera * m_world);
QMatrix3x3 normalMatrix = m_world.normalMatrix();
m_program->setUniformValue(m_normalMatrixLoc, normalMatrix);
glDrawArrays(GL_TRIANGLES, 0, m_logo.vertexCount());
m_program->release();
*/
QOpenGLFunctions *f = context()->functions();
const bool newFrameReady=true;
if (newFrameReady) {//new frame ready
f->glFrontFace(GL_CW); // because our cube's vertex data is such
f->glBindTexture(GL_TEXTURE_2D, m_fbo2->texture());
m_program2->bind();
QOpenGLVertexArrayObject::Binder vaoBinder(m_vao2);
// If VAOs are not supported, set the vertex attributes every time.
if (!m_vao2->isCreated()){
setupVertexAttribs2();
}
static GLfloat angle = 0;
QMatrix4x4 m;
m.translate(0, 0, -20);
m.rotate(90, 0, 0, 1);
m.rotate(angle, 0.5, 1, 0);
angle += 0.5f;
m_program2->setUniformValue(m_matrixLoc, m_proj * m);
// Draw the cube.
f->glDrawArrays(GL_TRIANGLES, 0, 36);
m_program2->release();
}
}
示例4: render
void Renderer::render()
{
QMutexLocker locker(&m_windowLock);
if (m_windows.isEmpty())
return;
HelloWindow *surface = m_windows.at(m_currentWindow);
QColor color = surface->color();
m_currentWindow = (m_currentWindow + 1) % m_windows.size();
if (!m_context->makeCurrent(surface))
return;
QSize viewSize = surface->size();
locker.unlock();
if (!m_initialized) {
initialize();
m_initialized = true;
}
QOpenGLFunctions *f = m_context->functions();
f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
f->glFrontFace(GL_CW);
f->glCullFace(GL_FRONT);
f->glEnable(GL_CULL_FACE);
f->glEnable(GL_DEPTH_TEST);
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.translate(0.0f, -0.2f, 0.0f);
m_program->bind();
m_program->setUniformValue(matrixUniform, modelview);
m_program->setUniformValue(colorUniform, color);
paintQtLogo();
m_program->release();
f->glDisable(GL_DEPTH_TEST);
f->glDisable(GL_CULL_FACE);
m_context->swapBuffers(surface);
m_fAngle += 1.0f;
QTimer::singleShot(0, this, SLOT(render()));
}
示例5: render
void LogoRenderer::render()
{
//glClearColor(0.5f, 0.5f, 0.7f, 1.0f);
glClearColor(0, 0, 0, 1);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPointSize(5.0);
//glClearDepth(1.0f);
glDisable(GL_SCISSOR_TEST);
glEnable(GL_STENCIL_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
handleEvents();
handleLogic();
drawStuff();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
return;
glDepthMask(true);
glClearColor(0.5f, 0.5f, 0.7f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CW);
glCullFace(GL_FRONT);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.scale(m_fScale);
modelview.translate(0.0f, -0.2f, 0.0f);
program1.bind();
program1.setUniformValue(matrixUniform1, modelview);
paintQtLogo();
program1.release();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
m_fAngle += 1.0f;
}
示例6: rotate
void SceneNode::rotate(char axis, double angle)
{
QMatrix4x4 m;
if(axis == 'x') m.rotate(angle, 1.0, 0.0, 0.0);
else if(axis == 'y') m.rotate(angle, 0.0, 1.0, 0.0);
else if(axis == 'z') m.rotate(angle, 0.0, 0.0, 1.0);
set_transform(get_transform() * m);
}
示例7: GetMatrix
QMatrix4x4 Transform::GetMatrix() const
{
QMatrix4x4 transformation;
transformation.translate(m_pos);
//Should use quaternions for the following
transformation.rotate(m_rotation.z(),QVector3D(0.0f,0.0f,1.0f));
transformation.rotate(m_rotation.y(),QVector3D(0.0f,1.0f,0.0f));
transformation.rotate(m_rotation.x(),QVector3D(1.0f,0.0f,0.0f));
transformation.scale(m_scale);
return transformation;
}
示例8: apply
void CameraShader::apply() {
QMatrix4x4 mv;
mv.setToIdentity();
// ModelView.rotate(eye, at, up);
mv.rotate(-_pitch, 1.0, 0.0, 0.0);
mv.rotate( -_yaw, 0.0, 1.0, 0.0);
mv.rotate( -_roll, 0.0, 0.0, 1.0);
mv.translate(-_position.x, -_position.y, -_position.z);
_shaderProgram->setUniformValue("ModelView", mv);
}
示例9:
void Renderable3DEntity::updateTransform()
{
QMatrix4x4 m;
//Do the translation after rotating, otherwise rotation around the x,y,z axis would be screwed up
m.translate(m_position);
m.rotate(m_fRotX, QVector3D(1.0f, 0.0f, 0.0f));
m.rotate(m_fRotY, QVector3D(0.0f, 1.0f, 0.0f));
m.rotate(m_fRotZ, QVector3D(0.0f, 0.0f, 1.0f));
m_pTransform->setMatrix(m);
}
示例10: updateRotation
void Camera::updateRotation( float pitch, float yaw, float roll)
{
QMatrix4x4 cameraTransformation;
cameraTransformation.setToIdentity();
cameraTransformation.rotate(-roll, m_cameraForwardVector.toVector3D());
cameraTransformation.rotate(-pitch, m_cameraRightVector.toVector3D());
cameraTransformation.rotate(yaw, m_cameraUpVector.toVector3D());
m_cameraForwardVector = m_cameraForwardVector * cameraTransformation;
m_cameraRightVector = m_cameraRightVector * cameraTransformation;
m_cameraUpVector = m_cameraUpVector * cameraTransformation;
}
示例11: render
void LogoRenderer::render()
{
#if 1
QString fileName="c:\\shareproject\\jpg\\512img004.jpg";
QImage image(fileName);
if (image.isNull()) {
qDebug()<<"image.isNull";
return;
}
image = image.convertToFormat(QImage::Format_RGB888);
//image = image.convertToFormat(QImage::Format_ARGB32);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0,
//GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image.bits());
GL_RGB, GL_UNSIGNED_BYTE, image.bits());
glDrawArrays(GL_TRIANGLES, 0, 6);
QImage imagefrag(512,384,QImage::Format_RGB888);
unsigned char *pixels = (unsigned char *) imagefrag.bits();
glReadPixels(0, 0, 512, 384, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)pixels);
imagefrag.save("c:\\shareproject\\jpg\\512img005_frag2.jpg");
#endif
#if 0
glDepthMask(true);
glClearColor(0.5f, 0.5f, 0.7f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glFrontFace(GL_CW);
glCullFace(GL_FRONT);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.scale(m_fScale);
modelview.translate(0.0f, -0.2f, 0.0f);
program1.bind();
program1.setUniformValue(matrixUniform1, modelview);
paintQtLogo();
program1.release();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
m_fAngle += 1.0f;
#endif
}
示例12: render
void QtRenderer::render()
{
QMutexLocker locker(&m_windowLock);
if (m_windows.isEmpty())
return;
HelloWindow *surface = m_windows.at(m_currentWindow);
QColor color = surface->color();
m_currentWindow = (m_currentWindow + 1) % m_windows.size();
if (!m_context->makeCurrent(surface))
return;
m_fboController->bind(surface->size());
m_fboController->bindAndDraw();
m_fboController->release();
QSize viewSize = surface->size();
locker.unlock();
if (!m_initialized) {
initialize();
m_initialized = true;
}
//f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
QOpenGLFunctions *f = m_context->functions();
f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 modelview;
modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
modelview.translate(0.0f, -0.2f, 0.0f);
m_program->setUniformValue(matrixUniform, modelview);
m_program->setUniformValue(colorUniform, color);
m_context->functions()->glDrawArrays(GL_TRIANGLES, 0, vertices.size());
m_context->swapBuffers(surface);
m_fAngle += 1.0f;
QTimer::singleShot(250, this, SLOT(render()));
}
示例13: position
static QMatrix4x4 CreateMatrix(PositionDesc & desc)
{
QMatrix4x4 cameraMatrix;
cameraMatrix.setToIdentity();
QVector3D position(desc._xPos, desc._yPos, desc._zPos);
cameraMatrix.rotate(desc._azimuth, 0, 0, 1);
QVector3D vec(0, 0, 1);
QVector3D vec2(cos(qDegreesToRadians(desc._azimuth)), sin(qDegreesToRadians(desc._azimuth)), 0);
QVector3D axis = QVector3D::crossProduct(vec, vec2);
cameraMatrix.rotate(desc._elevation, axis);
cameraMatrix.translate(position);
return cameraMatrix;
}
示例14: rotateView
void AwesomeCamera::rotateView(float z_angle,float x_angle){
// rotM.setToIdentity();
double cosPhi = cos(mouse_sens*(-z_angle)/180*M_PI);
double sinPhi = sin(mouse_sens*(-z_angle)/180*M_PI);
direction = QVector3D(cosPhi*direction.x()+sinPhi*direction.z(),direction.y(),
cosPhi*direction.z()-sinPhi*direction.x());
QMatrix4x4 rotMat;
rotMat.setToIdentity();
rotMat.rotate(mouse_sens*(-x_angle),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
tmpVec.normalize();
double angleTheta = QVector3D::dotProduct(tmpVec,QVector3D(0,1,0));
if(qAbs(angleTheta) < 0.9){
rotMat.setToIdentity();
rotMat.rotate(mouse_sens*(-x_angle)*(1-qAbs(angleTheta)),QVector3D::crossProduct(direction,QVector3D(0,1,0)));
QVector3D tmpVec = (rotMat*QVector4D(direction)).toVector3D();
tmpVec.normalize();
direction = tmpVec;
}
side_direction = QVector3D(cosPhi*side_direction.x()+sinPhi*side_direction.z(),0,
cosPhi*side_direction.z()-sinPhi*side_direction.x());
updown_direction = QVector3D::crossProduct(direction,side_direction);
/*
rot_angles[0] += mouse_sens*(z_angle);//przesuniecie X
rot_angles[1] -= mouse_sens*(x_angle);//przesuniecie Y
if(rot_angles[1] > 90) rot_angles[1] = 90;
if(rot_angles[1] <-90) rot_angles[1] = -90;
// przesuniecie do przodu
direction = QVector3D(-sin(rot_angles[0]/180*M_PI),sin(rot_angles[1]/180*M_PI),cos(rot_angles[0]/180*M_PI));
// przesuniece na boki
side_direction = QVector3D(sin((rot_angles[0]+90)/180*M_PI),0,-cos((rot_angles[0]+90)/180*M_PI));
// przesuwanie gora dol
updown_direction = QVector3D::crossProduct(direction,side_direction);
*/
direction.normalize();
side_direction.normalize();
updown_direction.normalize();
}
示例15: setCursor
void Dragon2Widget::mouseMoveEvent( QMouseEvent * e )
{
if(e->buttons() != Qt::NoButton)
{
setCursor(Qt::ClosedHandCursor);
auto t = (e->pos() - _lastMousePos);
QMatrix4x4 rotMat;
rotMat.rotate(-t.x() / 10.0 * M_PI, 0, 1, 0);
rotMat.rotate(t.y() / 10.0 * M_PI, 1, 0, 0);
_modelMatrix = rotMat * _modelMatrix;
_lastMousePos = e->pos();
update();
}
}