本文整理汇总了C++中QMatrix4x4::frustum方法的典型用法代码示例。如果您正苦于以下问题:C++ QMatrix4x4::frustum方法的具体用法?C++ QMatrix4x4::frustum怎么用?C++ QMatrix4x4::frustum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMatrix4x4
的用法示例。
在下文中一共展示了QMatrix4x4::frustum方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: projectionMatrix
/*!
Returns the transformation matrix to apply to the projection matrix
to present the scene as viewed from the camera position.
The \a aspectRatio specifies the aspect ratio of the window the
camera view is being displayed in. An \a aspectRatio of 1 indicates that
the window is square. An \a aspectRatio greater than 1 indicates that
the window is wider than it is high. An \a aspectRatio less than 1
indicates that the window is higher than it is wide.
\sa apply(), modelViewMatrix()
*/
QMatrix4x4 Camera::projectionMatrix(qreal aspectRatio) const
{
Q_D(const Camera);
QMatrix4x4 m;
if (!d->adjustForAspectRatio)
aspectRatio = 1.0f;
if (d->screenRotation != 0) {
m.rotate((qreal)(d->screenRotation), 0.0f, 0.0f, 1.0f);
if (d->screenRotation == 90 || d->screenRotation == 270) {
if (aspectRatio != 0.0f)
aspectRatio = 1.0f / aspectRatio;
}
}
if (d->projectionType == Perspective && d->fieldOfView != 0.0f) {
m.perspective(d->fieldOfView, aspectRatio,
d->nearPlane, d->farPlane);
} else {
qreal halfWidth = d->viewSize.width() / 2.0f;
qreal halfHeight = d->viewSize.height() / 2.0f;
if (aspectRatio > 1.0f) {
halfWidth *= aspectRatio;
} else if (aspectRatio > 0.0f && aspectRatio < 1.0f) {
halfHeight /= aspectRatio;
}
if (d->projectionType == Perspective) {
m.frustum(-halfWidth, halfWidth, -halfHeight, halfHeight,
d->nearPlane, d->farPlane);
} else {
m.ortho(-halfWidth, halfWidth, -halfHeight, halfHeight,
d->nearPlane, d->farPlane);
}
}
return m;
}
示例2: getProjMatrix
QMatrix4x4 PerspectiveCamera::getProjMatrix(int width, int height)
{
// can probably remove this now
float pixdx = 0;
float pixdy = 0;
// taken from gluPerspective docs
float aspect = (float)width / (float)height;
float zNear = .1f;
float zFar = 100.0f;
float top = tan(fov()*3.14159/360.0) * zNear;
//float top = tan(fov*0.5) * zNear;
float bottom = -top;
float left = aspect * bottom;
float right = aspect * top;
//int viewport[4];
//glGetIntegerv(GL_VIEWPORT, viewport);
float xwsize = right - left;
float ywsize = top - bottom;
// MAINT: width/height should be pulled from viewport if it doesn't match
// size of render
float dx = -(pixdx * xwsize / (float)width);
float dy = -(pixdy * ywsize / (float)height);
QMatrix4x4 m;
m.frustum(left+dx, right+dx, bottom+dy, top+dy, zNear, zFar);
//m.perspective(PerspectiveCamera->fov(), aspect, zNear, zFar);
return m;
}
示例3: paintScreen
void CoverSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
{
effects->paintScreen(mask, region, data);
if (mActivated || stop || stopRequested) {
QMatrix4x4 origProjection;
QMatrix4x4 origModelview;
ShaderManager *shaderManager = ShaderManager::instance();
if (effects->numScreens() > 1) {
// unfortunatelly we have to change the projection matrix in dual screen mode
QRect fullRect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop());
float fovy = 60.0f;
float aspect = 1.0f;
float zNear = 0.1f;
float zFar = 100.0f;
float ymax = zNear * tan(fovy * M_PI / 360.0f);
float ymin = -ymax;
float xmin = ymin * aspect;
float xmax = ymax * aspect;
float xTranslate = 0.0;
float yTranslate = 0.0;
float xminFactor = 1.0;
float xmaxFactor = 1.0;
float yminFactor = 1.0;
float ymaxFactor = 1.0;
if (area.x() == 0 && area.width() != fullRect.width()) {
// horizontal layout: left screen
xminFactor = (float)area.width() / (float)fullRect.width();
xmaxFactor = ((float)fullRect.width() - (float)area.width() * 0.5f) / ((float)fullRect.width() * 0.5f);
xTranslate = (float)fullRect.width() * 0.5f - (float)area.width() * 0.5f;
}
if (area.x() != 0 && area.width() != fullRect.width()) {
// horizontal layout: right screen
xminFactor = ((float)fullRect.width() - (float)area.width() * 0.5f) / ((float)fullRect.width() * 0.5f);
xmaxFactor = (float)area.width() / (float)fullRect.width();
xTranslate = (float)fullRect.width() * 0.5f - (float)area.width() * 0.5f;
}
if (area.y() == 0 && area.height() != fullRect.height()) {
// vertical layout: top screen
yminFactor = ((float)fullRect.height() - (float)area.height() * 0.5f) / ((float)fullRect.height() * 0.5f);
ymaxFactor = (float)area.height() / (float)fullRect.height();
yTranslate = (float)fullRect.height() * 0.5f - (float)area.height() * 0.5f;
}
if (area.y() != 0 && area.height() != fullRect.height()) {
// vertical layout: bottom screen
yminFactor = (float)area.height() / (float)fullRect.height();
ymaxFactor = ((float)fullRect.height() - (float)area.height() * 0.5f) / ((float)fullRect.height() * 0.5f);
yTranslate = (float)fullRect.height() * 0.5f - (float)area.height() * 0.5f;
}
QMatrix4x4 projection;
projection.frustum(xmin * xminFactor, xmax * xmaxFactor, ymin * yminFactor, ymax * ymaxFactor, zNear, zFar);
QMatrix4x4 modelview;
modelview.translate(xTranslate, yTranslate, 0.0);
if (shaderManager->isShaderBound()) {
GLShader *shader = shaderManager->pushShader(ShaderManager::GenericShader);
origProjection = shader->getUniformMatrix4x4("projection");
origModelview = shader->getUniformMatrix4x4("modelview");
shader->setUniform("projection", projection);
shader->setUniform("modelview", origModelview * modelview);
shaderManager->popShader();
} else {
#ifndef KWIN_HAVE_OPENGLES
glMatrixMode(GL_PROJECTION);
pushMatrix();
loadMatrix(projection);
glMatrixMode(GL_MODELVIEW);
pushMatrix(modelview);
#endif
}
}
QList< EffectWindow* > tempList = currentWindowList;
int index = tempList.indexOf(selected_window);
if (animation || start || stop) {
if (!start && !stop) {
if (direction == Right)
index++;
else
index--;
if (index < 0)
index = tempList.count() + index;
if (index >= tempList.count())
index = index % tempList.count();
}
foreach (Direction direction, scheduled_directions) {
if (direction == Right)
index++;
else
index--;
if (index < 0)
index = tempList.count() + index;
if (index >= tempList.count())
index = index % tempList.count();
}
}
int leftIndex = index - 1;
if (leftIndex < 0)
leftIndex = tempList.count() - 1;
int rightIndex = index + 1;
if (rightIndex == tempList.count())
//.........这里部分代码省略.........
示例4: paintGL
void CubeWindow::paintGL()
{
float timeSinceLastFrame;
if (m_lastFrameTime == -1) {
m_lastFrameTime = QDateTime::currentMSecsSinceEpoch();
timeSinceLastFrame = 0;
} else {
qint64 timeNow = QDateTime::currentMSecsSinceEpoch();
timeSinceLastFrame = timeNow - m_lastFrameTime;
m_lastFrameTime = timeNow;
}
float rotationScale = timeSinceLastFrame / (ROTATION_TIME * 1000.0f);
float xAngle = 0.0f, yAngle = 0.0f;
switch(m_currentDirection) {
case RIGHT:
yAngle = rotationScale * 360.0f;
break;
case LEFT:
yAngle = - rotationScale * 360.0f;
break;
case UP:
xAngle = - rotationScale * 360.0f;
break;
case DOWN:
xAngle = rotationScale * 360.0f;
break;
}
QMatrix4x4 perspectiveMatrix;
perspectiveMatrix.frustum(-0.75f, 0.75f, -0.75f, 0.75f, 1.0f, 3.0f);
QMatrix4x4 matrix;
matrix.translate(0, 0, -2);
matrix.rotate(xAngle, 1.0f, 0.0f, 0.0f);
matrix.rotate(yAngle, 0.0f, 1.0f, 0.0f);
matrix.translate(0, 0, 2);
for (int i = 0; i < CUBE_VERTICES; i += 4) {
QVector4D vector(cubeVertices[i], cubeVertices[i + 1],
cubeVertices[i + 2], cubeVertices[i + 3]);
vector = matrix * vector;
cubeVertices[i] = vector.x();
cubeVertices[i + 1] = vector.y();
cubeVertices[i + 2] = vector.z();
cubeVertices[i + 3] = vector.w();
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_program->bind();
m_program->setUniformValue(m_perspectiveMatrixUniform, perspectiveMatrix);
m_program->enableAttributeArray(m_posAtr);
m_program->setAttributeArray(m_posAtr, cubeVertices, 4);
m_program->enableAttributeArray(m_colorAtr);
m_program->setAttributeArray(m_colorAtr, colorData, 4);
glDrawArrays(GL_TRIANGLES, 0, 3 * 12);
m_program->disableAttributeArray(m_posAtr);
m_program->disableAttributeArray(m_colorAtr);
m_program->release();
}