本文整理汇总了C++中QMatrix4x4::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ QMatrix4x4::translate方法的具体用法?C++ QMatrix4x4::translate怎么用?C++ QMatrix4x4::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMatrix4x4
的用法示例。
在下文中一共展示了QMatrix4x4::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: preprocess
void QSGAnimatorNode::preprocess()
{
QSGNode::preprocess();
if (m_controller->isInitialized()) {
if (m_transformNode) {
qreal x = m_controller->registeredProperty("x")->value().toReal();
qreal y = m_controller->registeredProperty("y")->value().toReal();
QMatrix4x4 m = m_controller->transformMatrix();
QPointF transformOrigin = m_controller->registeredProperty("transformOriginPoint")->value().toPointF();
qreal scale = m_controller->registeredProperty("scale")->value().toReal();
qreal rotation = m_controller->registeredProperty("rotation")->value().toReal();
m.translate(transformOrigin.x(), transformOrigin.y());
m.translate(x, y);
m.scale(scale);
m.rotate(rotation, 0, 0, 1);
m.translate(-transformOrigin.x(), -transformOrigin.y());
m_transformNode->setMatrix(m);
if (m_controller->isUpdating())
m_transformNode->markDirty(QSGNode::DirtyMatrix);
}
if (m_opacityNode) {
qreal opacity = m_controller->registeredProperty("opacity")->value().toReal();
m_opacityNode->setOpacity(qMin(qreal(MAX_OPACITY), qMax(qreal(MIN_OPACITY), opacity)));
if (m_controller->isUpdating())
m_opacityNode->markDirty(QSGNode::DirtyOpacity);
}
}
}
示例2: render
void SatHorizon::render(QMatrix4x4 projection, float distance, QQuaternion quat, QVector3D posnorm, float alt, QColor rendercolor)
{
float radius = sqrt( alt * alt - 1 ) / alt;
float theta = acos(QVector3D::dotProduct(QVector3D(0,0,1), posnorm));
QVector3D vecnorm = QVector3D::crossProduct(QVector3D(0,0,1), posnorm);
vecnorm.normalize();
createCircleBuffer(radius, SEGMENTS);
QMatrix4x4 modelview;
modelview.translate(0.0, 0.0, distance);
modelview.rotate(quat);
modelview.translate(posnorm * (1/alt) * (alt > 1.5 ? 1.0015 : 1.0001));
modelview.rotate(theta * 180.0f/ PI, vecnorm );
posBuf.bind();
posBuf.write(0, vertexData, SEGMENTS * sizeof(QVector3D));
posBuf.release();
program->bind();
program->setUniformValue("MVP", projection * modelview);
QMatrix3x3 norm = modelview.normalMatrix();
program->setUniformValue("NormalMatrix", norm);
program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));
QOpenGLVertexArrayObject::Binder vaoBinder(&vao);
glDrawArrays(GL_LINE_LOOP, 0, SEGMENTS);
}
示例3: rotate
void Navigation::rotate(
float hAngle
, float vAngle)
{
static const QVector3D up(0.0, 1.0, 0.0);
m_rotationHappened = true;
const QVector3D ray((m_camera.center() - m_eye).normalized());
const QVector3D rotAxis(QVector3D::crossProduct(ray, up));
hAngle *= ROTATION_HOR_DOF;
vAngle *= ROTATION_VER_DOF;
enforceRotationConstraints(hAngle, vAngle);
QVector3D t = m_i0Valid ? m_i0 : m_center;
QMatrix4x4 transform;
transform.translate( t);
transform.rotate(hAngle, up);
transform.rotate(vAngle, rotAxis);
transform.translate(-t);
m_camera.setEye(transform * m_eye);
m_camera.setCenter(transform * m_center);
m_camera.update();
}
示例4: color
template <typename R> void call(R *r) {
using V = decltype(declval<typename R::Cell>().getPosition());
const auto &view = r->getViewMatrix();
const auto &projection = r->getProjectionMatrix();
shader.bind();
disk.vao.bind();
QVector4D color(0.9f, 0.9f, 0.05f, 1.0f);
shader.setUniformValue(shader.uniformLocation("color"), color);
shader.setUniformValue(shader.uniformLocation("projection"), projection);
shader.setUniformValue(shader.uniformLocation("view"), view);
for (auto &con : r->getScenario().getWorld().cellCellConnections) {
auto &cc = con.second;
QMatrix4x4 model;
model.translate(
toQV3D(cc.cells.first->getPosition() + cc.normal * cc.midpoint.first));
auto rot = V::getRotation(V(0, 0, 1), cc.normal);
model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
float rad = static_cast<float>(sqrt(cc.sqradius));
model.scale(rad, rad, rad);
QMatrix4x4 nmatrix = (model).inverted().transposed();
shader.setUniformValue(shader.uniformLocation("model"), model);
shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
}
color = QVector4D(0.1f, 0.7f, 0.f, 1.0f);
shader.setUniformValue(shader.uniformLocation("color"), color);
for (auto &con : r->getScenario().getWorld().cellCellConnections) {
auto &cc = con.second;
QMatrix4x4 model;
model.translate(toQV3D(cc.cells.first->getPosition() +
cc.icb.first.currentBasis.X * cc.midpoint.first));
auto rot = V::getRotation(V(0, 0, 1), cc.icb.first.currentBasis.X);
model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
float rad = static_cast<float>(sqrt(cc.sqradius));
model.scale(rad, rad, rad);
QMatrix4x4 nmatrix = (model).inverted().transposed();
shader.setUniformValue(shader.uniformLocation("model"), model);
shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
}
color = QVector4D(0.f, 0.1f, 0.7f, 1.0f);
shader.setUniformValue(shader.uniformLocation("color"), color);
for (auto &con : r->getScenario().getWorld().cellCellConnections) {
auto &cc = con.second;
QMatrix4x4 model;
model.translate(toQV3D(cc.cells.second->getPosition() +
cc.icb.second.currentBasis.X * cc.midpoint.second));
auto rot = V::getRotation(V(0, 0, 1), cc.icb.second.currentBasis.X);
model.rotate(rot.teta * 180.0 / M_PI, toQV3D(rot.n));
float rad = static_cast<float>(sqrt(cc.sqradius));
model.scale(rad, rad, rad);
QMatrix4x4 nmatrix = (model).inverted().transposed();
shader.setUniformValue(shader.uniformLocation("model"), model);
shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
GL->glDrawElements(GL_TRIANGLES, disk.indices.size(), GL_UNSIGNED_INT, 0);
}
disk.vao.release();
shader.release();
}
示例5: updateShotLines
/**
\brief When a station has been selected, this updates the shot lines
This shows the shot lines from the selected station. If no station is
currently selected, this will hide the lines
*/
void cwScrapStationView::updateShotLines() {
if(scrap() == nullptr) { return; }
if(scrap()->parentNote() == nullptr) { return; }
if(scrap()->parentNote()->parentTrip() == nullptr) { return; }
if(transformUpdater() == nullptr) { return; }
cwNoteStation noteStation = scrap()->station(selectedItemIndex());
//Get the current trip
cwNote* note = scrap()->parentNote();
cwTrip* trip = note->parentTrip();
cwCave* cave = trip->parentCave();
cwStationPositionLookup stationPositionLookup = cave->stationPositionLookup();
//Clear all the lines
ShotLines.clear();
if(noteStation.isValid() && stationPositionLookup.hasPosition(noteStation.name())) {
QString stationName = noteStation.name();
QSet<cwStation> neighboringStations = trip->neighboringStations(stationName);
//The position of the selected station
QVector3D selectedStationPos = stationPositionLookup.position(noteStation.name());
//Create the matrix to covert global position into note position
QMatrix4x4 noteTransformMatrix = scrap()->noteTransformation()->matrix(); //Matrix from page coordinates to cave coordinates
noteTransformMatrix = noteTransformMatrix.inverted(); //From cave coordinates to page coordinates
QMatrix4x4 notePageAspect = note->scaleMatrix().inverted(); //The note's aspect ratio
QMatrix4x4 offsetMatrix;
offsetMatrix.translate(-selectedStationPos);
QMatrix4x4 dotPerMeter;
dotPerMeter.scale(note->dotPerMeter(), note->dotPerMeter(), 1.0);
QMatrix4x4 noteStationOffset;
noteStationOffset.translate(QVector3D(noteStation.positionOnNote()));
QMatrix4x4 toNormalizedNote = noteStationOffset *
dotPerMeter *
notePageAspect *
noteTransformMatrix *
offsetMatrix;
//Go through all the neighboring stations and add the position to the line
foreach(cwStation station, neighboringStations) {
QVector3D currentPos = stationPositionLookup.position(station.name());
QVector3D normalizeNotePos = toNormalizedNote.map(currentPos);
ShotLines.append(QLineF(noteStation.positionOnNote(), normalizeNotePos.toPointF()));
}
示例6: homothetie
/**
* Homothétie sur le mesh, ayant pour centre le centre de gravité du
* mesh.
* @param x rapport de l'homothétie.
*/
void Mesh::homothetie(float x)
{
QMatrix4x4 t;
t.translate(centre_);
t.scale(x);
t.translate(-centre_);
for (int i=0;i<nbVertices_;i++)
{
QVector3D &v=vertices_[i];
setXYZ(i, (t*v));
}
octree_->changerTailleOctree(x-1);
}
示例7: if
QMatrix4x4 Exercise12::rotateClockwise(int frame)
{
/////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: Aufgabe 12
// Apply correct transformations (rotate, translate, scale) with respect to the current frame
/////////////////////////////////////////////////////////////////////////////////////////////////
QMatrix4x4 transform;
int degree = frame % 360;
transform.setToIdentity();
if(degree < 90) {
transform.translate(0.5, 0.5, 0.0);
transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
transform.translate(-0.5, 0.5, 0.0);
} else if(degree < 180) {
transform.translate(0.5, -0.5, 0.0);
transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
transform.translate(-0.5, -0.5, 0.0);
} else if(degree < 270) {
transform.translate(-0.5, -0.5, 0.0);
transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
transform.translate(0.5, -0.5, 0.0);
} else if(degree < 360) {
transform.translate(-0.5, 0.5, 0.0);
transform.rotate(-2 * degree, 0.0, 0.0, 1.0);
transform.translate(0.5, 0.5, 0.0);
}
return transform;
}
示例8: call
template <typename R> void call(R *r) {
const auto &view = r->getViewMatrix();
const auto &projection = r->getProjectionMatrix();
for (auto &con : r->getScenario().getWorld().cellCellConnections) {
auto &cc = con.second;
shader.bind();
cube.vao.bind();
QColor color = QColor::fromHsvF(0.7, 0.7, 0.7);
shader.setUniformValue(shader.uniformLocation("color"), color);
shader.setUniformValue(shader.uniformLocation("projection"), projection);
shader.setUniformValue(shader.uniformLocation("view"), view);
// first
QMatrix4x4 model;
auto ab =
toQV3D(cc.targets.first.b.X.rotated(cc.cells.first->getOrientationRotation()) *
cc.targets.first.d);
model.translate(toQV3D(cc.cells.first->getPosition()) + ab * 0.5);
auto dp = ab.normalized().x();
if (dp != 1 && dp != -1) {
model.rotate(acos(dp) * 180.0 / M_PI,
QVector3D::crossProduct(QVector3D(1, 0, 0), ab));
model.scale(ab.length() * 0.5, 1.0, 1.0);
QMatrix4x4 nmatrix = (model).inverted().transposed();
shader.setUniformValue(shader.uniformLocation("model"), model);
shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
GL->glDrawElements(GL_TRIANGLES, cube.indices.size(), GL_UNSIGNED_INT, 0);
}
// second
color = QColor::fromHsvF(0.3, 0.7, 0.7);
shader.setUniformValue(shader.uniformLocation("color"), color);
model = QMatrix4x4();
ab = toQV3D(
cc.targets.second.b.X.rotated(cc.cells.second->getOrientationRotation()) *
cc.targets.second.d);
model.translate(toQV3D(cc.cells.second->getPosition()) + ab * 0.5);
dp = ab.normalized().x();
if (dp != 1 && dp != -1) {
model.rotate(acos(dp) * 180.0 / M_PI,
QVector3D::crossProduct(QVector3D(1, 0, 0), ab));
model.scale(ab.length() * 0.5, 1.0, 1.0);
QMatrix4x4 nmatrix = (model).inverted().transposed();
shader.setUniformValue(shader.uniformLocation("model"), model);
shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
GL->glDrawElements(GL_TRIANGLES, cube.indices.size(), GL_UNSIGNED_INT, 0);
}
cube.vao.release();
shader.release();
}
}
示例9:
void QQuickTransformAnimatorJob::Helper::apply()
{
if (!wasChanged || !node)
return;
QMatrix4x4 m;
m.translate(dx, dy);
m.translate(ox, oy);
m.scale(scale);
m.rotate(rotation, 0, 0, 1);
m.translate(-ox, -oy);
node->setMatrix(m);
wasChanged = false;
}
示例10: transformQuad
void HgTransformedQuad::transformQuad(int index, const QMatrix4x4& projView, HgQuad* quad,
qreal mirroringPlaneY, const QVector2D& translate, const QPointF& center,
const QSizeF& windowSize)
{
mIndex = index;
mQuad = quad;
QMatrix4x4 tm;
tm.setToIdentity();
tm.rotate(quad->outerRotation());
if (mQuad->mirrorImageEnabled())
{
computeMirroredPoints(tm, projView, mirroringPlaneY, translate, center, windowSize);
}
tm.translate(quad->position());
tm.rotate(quad->rotation());
tm.scale(quad->scale().x(), quad->scale().y());
tm = projView * tm;
perspectiveTransformPoints(mTransformedPoints, tm, center, windowSize);
for (int i = 0; i < 4; i++)
mTransformedPoints[i] += translate;
}
示例11: TextureData
ImageData::ImageData(const QSize &size, const Format::Id format, const GLubyte *const data) :
TextureData(size, format, data), rect(QPoint(0, 0), size),
projectionMatrix([this]() {
const float halfWidth = (float)this->size.width() / 2.f;
const float halfHeight = (float)this->size.height() / 2.f;
QMatrix4x4 temp;
temp.scale(1.f / (float)halfWidth, 1.f / (float)halfHeight);
temp.translate(-halfWidth, -halfHeight);
return temp; }()),
vertexArray([this](){
GLuint vertexArray;
glGenVertexArrays(1, &vertexArray);
return vertexArray; }()),
vertexBuffer([this](){
GLuint vertexBuffer;
glGenBuffers((GLsizei)1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
const GLfloat vertices[][2] = {
{0.f, 0.f},
{(GLfloat)this->size.width(), 0.f},
{(GLfloat)this->size.width(), (GLfloat)this->size.height()},
{0.f, (GLfloat)this->size.height()},
};
glBufferData(GL_ARRAY_BUFFER, 4 * 2 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
return vertexBuffer; }())
{
}
示例12: getMatrix
QMatrix4x4 ModelInterface::getMatrix(const aiMatrix4x4* m)
{
QMatrix4x4 nodeMatrix;
if(m->IsIdentity())
return nodeMatrix;
aiQuaternion rotation;
aiVector3D position;
aiVector3D scale;
m->Decompose(scale, rotation, position);
QVector3D qscale(scale.x,scale.y, scale.z);
QVector3D qposition(position.x, position.y, position.z);
QQuaternion qrotation(rotation.w, rotation.x, rotation.y, rotation.z);
if(!qscale.isNull())
nodeMatrix.scale(qscale);
if(!qposition.isNull())
nodeMatrix.translate(qposition);
if(!qrotation.isNull())
nodeMatrix.rotate(qrotation);
return nodeMatrix;
}
示例13: paintGL
void Visualizer::paintGL()
{
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
texture->bind();
// Calculate model view transformation
QMatrix4x4 matrix;
matrix.translate(0.0, 0.0, -5.0);
matrix.rotate(rotation);
// Set modelview-projection matrix
program.setUniformValue("mvp_matrix", projection * matrix);
// Use texture unit 0 which contains cube.png
program.setUniformValue("texture", 0);
// Generate 2 VBOs
arrayBuf.create();
indexBuf.create();
// Initializes cube geometry and transfers it to VBOs
initCubeGeometry();
drawCubeGeometry(&program);
}
示例14: updateTransform
void MultiTrackPlotter::updateTransform()
{
qreal y_scaling = 1.0;
y_scaling *= m_height * 0.5;
if (!m_overlay && m_channel_count > 1)
y_scaling /= m_channel_count;
qreal x_scaling = m_width;
if (m_frame_count > 1)
x_scaling /= (m_frame_count - 1);
for (int idx = 0; idx < m_channel_count; ++idx)
{
qreal y_translation = 1.0;
if (!m_overlay)
y_translation += idx * 2.0;
QMatrix4x4 matrix;
matrix.scale(x_scaling, y_scaling);
matrix.translate(0.0, y_translation);
matrix.scale(1.0, -m_scaling); // flip y axis!
QSGTransformNode *transformNode = static_cast<QSGTransformNode*>( childAtIndex(idx) );;
transformNode->setMatrix(matrix);
}
}
示例15: col
template <typename R> void call(R *r) {
const auto &view = r->getViewMatrix();
const auto &projection = r->getProjectionMatrix();
shader.bind();
sphere.vao.bind();
texture->bind(0);
shader.setUniformValue(shader.uniformLocation("projection"), projection);
shader.setUniformValue(shader.uniformLocation("view"), view);
for (auto &n : r->getScenario().nutrientSources) {
QMatrix4x4 model;
model.translate(n.pos.x(), n.pos.y(), n.pos.z());
double c = n.content / n.initialcontent;
double l = 15.0 + sqrt(n.sqradius * c) * 0.05;
model.scale(l, l, l);
QMatrix4x4 nmatrix = (model).inverted().transposed();
shader.setUniformValue(shader.uniformLocation("model"), model);
shader.setUniformValue(shader.uniformLocation("normalMatrix"), nmatrix);
auto hsv = QColor::fromHsvF(c * 0.35, 0.9, 0.9);
QVector4D col(hsv.redF(), hsv.greenF(), hsv.blueF(), 0.5);
std::cerr << "c = " << c << ", r = " << col.x() << std::endl;
shader.setUniformValue(shader.uniformLocation("color"), col);
GL->glDrawElements(GL_TRIANGLES, sphere.indices.size(), GL_UNSIGNED_INT, 0);
}
sphere.vao.release();
shader.release();
}