本文整理汇总了C++中QMatrix4x4::lookAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QMatrix4x4::lookAt方法的具体用法?C++ QMatrix4x4::lookAt怎么用?C++ QMatrix4x4::lookAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMatrix4x4
的用法示例。
在下文中一共展示了QMatrix4x4::lookAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: modelViewMatrix
/*!
Returns the transformation to apply to the modelview matrix
to present the scene as viewed from the eye() position.
\sa apply(), projectionMatrix()
*/
QMatrix4x4 Camera::modelViewMatrix() const
{
Q_D(const Camera);
QMatrix4x4 m;
if (d->motionQuaternion.isIdentity()) {
m.lookAt(d->eye, d->center, d->upVector);
} else {
QVector3D up = d->motionQuaternion.rotatedVector(d->upVector);
QVector3D view = d->motionQuaternion.rotatedVector(d->viewVector);
QVector3D eye = d->center - view;
m.lookAt(eye, d->center, up);
}
return m;
}
示例2: paintGL
void GlWidget::paintGL()
{
setMatrixes();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
QMatrix4x4 vMatrix;
vMatrix.lookAt(camera[0], camera[1], camera[2]);
for(int i=0; i<objects.size(); i++){
if(i!=3 || canonFire==true){
shaderProgram.bind();
shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * *objects[i]->getMMatrix());
objects[i]->getTexture()->bind();
DrawReferenceGrid();
shaderProgram.setAttributeArray("vertex", objects[i]->getVertices()->constData());
shaderProgram.enableAttributeArray("vertex");
shaderProgram.setAttributeArray("textureCoordinate", objects[i]->getUVS()->constData());
shaderProgram.enableAttributeArray("textureCoordinate");
glDrawArrays(GL_TRIANGLES, 0, objects[i]->getVertices()->size());
shaderProgram.disableAttributeArray("vertex");
shaderProgram.disableAttributeArray("textureCoordinate");
}
}
shaderProgram.release();
}
示例3: glActiveTexture
void Painter::paint_3_4(float timef)
{
paint_3_3_shadowmap(timef);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_depthTex);
glActiveTexture(GL_TEXTURE0);
QOpenGLShaderProgram * program(m_programs[PaintMode1]);
// Task_3_3 - ToDo Begin
QVector3D light = m_light.normalized();
QMatrix4x4 L;
// L.lookAt(light, center ,up);
L.perspective(camera()->fovy(), camera()->viewport().width()/static_cast<float>(camera()->viewport().height()), camera()->zNear(), camera()->zFar());
L.lookAt(m_light,QVector3D(0.0,0.0,0.0),QVector3D(0.0,0.1,0.0));
// QMatrix4x4 ...
program->bind();
program->setUniformValue("light", m_light);
program->setUniformValue("viewProjection", L);
program->release();
// Task_3_3 - ToDo End
paint_3_1_scene(true, timef);
paint_3_2_label(camera()->viewProjection(), timef);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
}
示例4: paintGL
void MyGLWidget::paintGL()
{
// Clear buffer to set color and alpha
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shaderProgram.setUniformValue(unifMatrixPerspective,projectionMatrix);
// VIEW TRANSFORMATION
QMatrix4x4 viewMatrix ;
viewMatrix.lookAt(cameraPos,cameraPos+cameraFront,cameraUp);
shaderProgram.setUniformValue(unifMatrixView,viewMatrix);
// MODEL TRANSFORMATION (Neues OpenGL)
QMatrix4x4 modelMatrix ;
// Initialisierung des Modells
modelMatrix.setToIdentity();
modelMatrixStack.push(modelMatrix);
// Zeit zwischen den Render Bildern
elapsedTime = tmrRender.elapsed();
//qDebug() << elapsedTime ;
tmrRender.start();
// glBindTexture(GL_TEXTURE_2D,tList[sun]);
//qTex->bind();
textures[1]->bind();
textures[1]->bind();
// Übergebe die Textur an die Uniform Variable
// Die 0 steht dabei für die verwendete Unit (0=Standard)
//shaderProgram.setUniformValue("texture",0);
// Triggern des Renderns
sonne.render();
// Stack wieder säubern.
modelMatrixStack.pop();
//qTex->release();
}
示例5: setLookAt
/**
* Sets mvMatrix to a lookAt transformation.
* Call setPMatrix or setPerspective first.
*/
void GLESRenderer::setLookAt(const QVector3D & eye,const QVector3D & center,const QVector3D & up )
{
QMatrix4x4 m;
m.setToIdentity();
m.lookAt(eye, center, up);
setMvMatrix(m);
}
示例6: paintGL
void Widget::paintGL()
{
glClearColor(.3, .4, .5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
myShader.bind();
QMatrix4x4 modelview;
modelview.perspective(70, 1.0 * this->width() / this->height(), 0.1, 100);
QVector3D to = QVector3D(sin(yaw) * cos(pitch), cos(yaw) * cos(pitch), sin(pitch));
move();
modelview.lookAt(from, from + to, QVector3D(0, 0, 1));
myShader.setUniformValue("mvp", modelview);
groundMesh.draw(this, &myShader);
modelview.scale(2);
myShader.setUniformValue("mvp", modelview);
torusMesh.draw(this, &myShader);
myShader.release();
// TODO: use QOpenGLDebugLogger
}
示例7: directionLightPass
void Scene::directionLightPass(RenderTarget *target)
{
ShaderProgram * shader =ShaderPool::getInstance ()->get("dir_light_pass");
shader->use ();
int texture_offset = 5;
for(int i = 0 ;i<4;i++)
{
directionLight.getCSM_FBO (i)->BindForReading(GL_TEXTURE0+i+texture_offset);
char GLSL_shadowMap_name [30];
sprintf(GLSL_shadowMap_name,"g_shadow_map[%d]",i);
directionLight.getCSM_FBO (i)->applyShadowMapTexture (shader,i+texture_offset,GLSL_shadowMap_name);
}
QMatrix4x4 m;
m.setToIdentity ();
m_quad->setShaderProgram (shader);
shader->setUniformMat4v ("g_MVP_matrix",m.data ());
shader->setUniform2Float ("g_screen_size",1024,768);
shader->setUniformInteger ("g_color_map",0);
shader->setUniformInteger ("g_position_map",1);
shader->setUniformInteger ("g_normal_map",2);
shader->setUniformInteger ("g_depth_map",4);//for depth
auto camera = target->camera ();
if(camera)
{
shader->setUniform3Float ("g_eye_position",
camera->pos ().x(),
camera->pos ().y(),
camera->pos ().z());
}
QMatrix4x4 lightView;
lightView.setToIdentity();
QVector3D lightDir = directionLight.getDirection ();
QVector3D pos = QVector3D(0,0,0);
lightView.lookAt(pos,lightDir,QVector3D(0,1,0));
for(int i =0 ;i <4 ;i++)
{
if(!camera) break;
auto split_frustum_aabb = camera->getSplitFrustumAABB (i);
split_frustum_aabb.transForm (target->camera()->getModelTrans ());
split_frustum_aabb.transForm (lightView);
auto matrix = getCropMatrix (split_frustum_aabb);
QMatrix4x4 light_vp;
light_vp = matrix * lightView ;
char GLSL_light_VP_name [30];
sprintf(GLSL_light_VP_name,"g_light_vp_matrix[%d]",i);
shader->setUniformMat4v (GLSL_light_VP_name,light_vp.data ());
}
this->directionLight.apply(shader);
this->ambientLight.apply(shader);
m_quad->draw (true);
}
示例8: modelViewMatrix
/*!
Returns the transformation to apply to the modelview matrix
to present the scene as viewed from the eye position.
The \a eye parameter is used to adjust the camera's position
horizontally by half of eyeSeparation() if \a eye is QGL::LeftEye
or QGL::RightEye.
\sa projectionMatrix()
*/
QMatrix4x4 QGLCamera::modelViewMatrix(QGL::Eye eye) const
{
Q_D(const QGLCamera);
QMatrix4x4 m;
QVector3D adjust;
if (eye == QGL::LeftEye)
adjust = translation(-d->eyeSeparation / 2.0f, 0.0f, 0.0f);
else if (eye == QGL::RightEye)
adjust = translation(d->eyeSeparation / 2.0f, 0.0f, 0.0f);
if (d->motionQuaternion.isIdentity()) {
m.lookAt(d->eye + adjust, d->center, d->upVector);
} else {
QVector3D up = d->motionQuaternion.rotatedVector(d->upVector);
QVector3D view = d->motionQuaternion.rotatedVector(d->viewVector);
m.lookAt(d->center - view + adjust, d->center, up);
}
return m;
}
示例9: qglClearColor
void Dragon2Widget::paintGL()
{
qglClearColor(Qt::white);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// use the OpenGL shader program for painting
glUseProgram(_program);
// set model matrix
glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, _modelMatrix.data());
// set view matrix
QMatrix4x4 viewMatrix;
viewMatrix.setToIdentity();
viewMatrix.lookAt(QVector3D(0, 0, -1000), QVector3D(0, 0, 0), QVector3D(0, -1, 0));
glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, viewMatrix.data());
// set projection matrix
QMatrix4x4 projectionMatrix;
projectionMatrix.setToIdentity();
projectionMatrix.perspective(30, (float)width()/height(), 0.01f, 1e5f);
glUniformMatrix4fv(_projectionMatrixLocation, 1, GL_FALSE, projectionMatrix.data());
// bind ArrayBuffer to _vertBuffer
glBindBuffer(GL_ARRAY_BUFFER, _vertBuffer);
// enable vertex attribute "position" (bound to 0 already)
glEnableVertexAttribArray(0);
// set the data of vertex attribute "position" using current ArrayBuffer
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(_vertices.first()), 0);
// enable vertex attribute "normal" (bound to 1 already)
glEnableVertexAttribArray(1);
// set the data of vertex attribute "normal" using current ArrayBuffer
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(_vertices.first()), (void*)(3 * sizeof(float)));
// bind ElementArrayBuffer to _triangleIndicesBuffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _triangleIndicesBuffer);
// draw mesh using the indices stored in ElementArrayBuffer
glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, 0);
// disable vertex attributes
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
// unbind buffers
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// restore states
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
}
示例10: 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();
}
示例11: getCameraMatrix
QMatrix4x4 Viewer::getCameraMatrix() {
QMatrix4x4 vMatrix;
QMatrix4x4 cameraTransformation;
auto cameraPosition = QVector3D(0, 0, 2.0);
QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
return mPerspMatrix * vMatrix * mTransformMatrix;
}
示例12: initializeOpenGLFunctions
void Tutorial03::initializeGL(void)
{
// initialize OpenGL
initializeOpenGLFunctions();
bool success;
// load and compile vertex shader
success = shaderProgram.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/SimpleTransform.vert");
// load and compile fragment shader
success = shaderProgram.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/SingleColor.frag");
// link the shader program
shaderProgram.link();
GLuint programID = shaderProgram.programId();
// Get a handle for our buffers
vertexPosition_modelspaceID = glGetAttribLocation(programID, "vertexPosition_modelspace");
// Get a handle to the colors
color_location = glGetAttribLocation(programID, "v_color");
// Get a handle for our "MVP" uniform
MatrixID = glGetUniformLocation(programID, "MVP");
// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
QMatrix4x4 projection;
projection.perspective(45.0, 4.0/3.0, 0.1, 100.0);
// Camera matrix
QMatrix4x4 view;
view.lookAt( QVector3D(4,3,3), // Camera is at (4,3,3), in World Space
QVector3D(0,0,0), // and looks at the origin
QVector3D(0,1,0) // Head is up (set to 0,-1,0 to look upside-down)
);
// Model matrix : an identity matrix (model will be at the origin)
QMatrix4x4 model;
model.setToIdentity();
// Our ModelViewProjection : multiplication of our 3 matrices
MVP = projection * view * model; // Remember, matrix multiplication is the other way around
glGenBuffers(1, &vertexbuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
glGenBuffers(1, &colorbuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorbuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(triangle_colors), triangle_colors, GL_STATIC_DRAW);
glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
}
示例13: glClear
void Visu3D::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 mMatrix;
QMatrix4x4 vMatrix;
QMatrix4x4 cameraTransformation;
cameraTransformation.rotate(alpha, 0, 1, 0);
cameraTransformation.rotate(beta, 1, 0, 0);
QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, distance);
QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
mMatrix.setToIdentity();
QMatrix4x4 mvMatrix;
mvMatrix = vMatrix * mMatrix;
shaderProgram.bind();
shaderProgram.setUniformValue("mvpMatrix", pMatrix * mvMatrix); // modele-vue-projection
shaderProgram.setUniformValue("greyMax", (float) lvlOfGreyMax);
verticesDataBuffer.bind();
shaderProgram.setAttributeBuffer("vertex", GL_FLOAT, 0, 3, 0);
shaderProgram.enableAttributeArray("vertex");
verticesDataBuffer.release();
greyDataBuffer.bind();
shaderProgram.setAttributeBuffer("inGrey", GL_FLOAT, 0, 1, 0);
shaderProgram.enableAttributeArray("inGrey");
greyDataBuffer.release();
glDrawArrays(GL_TRIANGLES, 0, verticesData.size());
shaderProgram.disableAttributeArray("vertex");
shaderProgram.disableAttributeArray("inGrey");
shaderProgram.release();
glClear(GL_DEPTH_BUFFER_BIT); // On annule le test de profondeur afin
//que le repere soit devant
QMatrix4x4 mvpMatrix = pMatrix * mvMatrix; // Matrice de transfo pour que le repere tourne
//en meme temps que la scene
makeLandMark(mvpMatrix);
}
示例14: shadowPassDirectional
void Scene::shadowPassDirectional(RenderTarget * target)
{
auto light = this->getDirectionalLight ();
for(int j =0;j<4;j++)
{
// Clear color and depth buffer
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
light->getCSM_FBO ( j )->BindForWriting ();
glClear(GL_DEPTH_BUFFER_BIT);
ShaderProgram * shadow_shader = ShaderPool::getInstance ()->get("shadow");
PipeLine p;
for (std::vector<Entity *>::iterator i =m_entityList.begin();i!=m_entityList.end();i++)
{
shadow_shader->use ();
Entity * entity = (* i);
if(!entity->isEnableShadow()) continue;
if(target->isIgnoreEntity (entity))continue;
p.setModelMatrix(target->auxMatrix ()*entity->getModelTrans());
QMatrix4x4 lightView;
lightView.setToIdentity();
auto lightDir = directionLight.getDirection ();
QVector3D pos = QVector3D(0,0,0);
lightView.lookAt(pos,lightDir,QVector3D(0,1,0));
auto aabb = camera ()->getSplitFrustumAABB ( j );
aabb.transForm (camera()->getModelTrans ());
aabb.transForm (lightView);
auto matrix = getCropMatrix (aabb);
p.setProjectionMatrix(matrix);
p.setViewMatrix(lightView);
ShaderProgram * tmp_shader = entity->getShaderProgram ();
entity->setShaderProgram (shadow_shader);
setEntityBoneTransform(entity);
p.apply(shadow_shader);
entity->draw();
entity->setShaderProgram (tmp_shader);
}
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);//switch the frame buffer back.
}
}
示例15: paintGL
void DragonWidget::paintGL()
{
makeCurrent();
qglClearColor(Qt::white);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH);
// set model-view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
QMatrix4x4 viewMatrix;
viewMatrix.lookAt(QVector3D(0, 0, -1000), QVector3D(0, 0, 0), QVector3D(0, -1, 0));
glMultMatrixf(viewMatrix.data());
glMultMatrixf(_modelMatrix.data()); // now model-view matrix = lookAt(...) * _modelMatrix
// set projection matrix
// (projection matrix is often set in resizeGL(width, height) functions,
// since it only relies on the size of the window in most cases)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
QMatrix4x4 projectionMatrix;
projectionMatrix.perspective(30.0f, (float)width() / height(), 0.01f, 1e5f);
glMultMatrixf(projectionMatrix.data());
// draw mesh
glBegin(GL_TRIANGLES);
for(int vid : _triangleIndices)
{
glColor3fv(&(_vertices[vid].normal[0]));
glVertex3fv(&(_vertices[vid].position[0]));
}
glEnd();
glDisable(GL_DEPTH_TEST);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
}