本文整理汇总了C++中QVector2D::x方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::x方法的具体用法?C++ QVector2D::x怎么用?C++ QVector2D::x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVector2D
的用法示例。
在下文中一共展示了QVector2D::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: angleBetweenVectors
float Collider::angleBetweenVectors(QVector2D v1, QVector2D v2)
{
float dot = QVector2D::dotProduct(v1,v2);
float det = v1.x ()*v2.y() - v1.y ()*v2.x();
return (-qRadiansToDegrees(atan2(det,dot)));
}
示例2: center
QVector<QVector3D> SurfaceItem::vertices() const
{
QSize size = surface()->size();
qreal w = (m_height * size.width()) / size.height();
qreal h = m_height;
QVector3D pos = m_pos + m_normal * m_depthOffset;
QVector2D center(pos.x(), pos.z());
QVector3D perp = QVector3D::crossProduct(QVector3D(0, 1, 0), m_normal);
QVector2D delta = w * QVector2D(perp.x(), perp.z()).normalized() / 2;
qreal scale = qMin(1.0, m_time.elapsed() * 0.002);
qreal top = m_pos.y() + h * 0.5 * scale;
qreal bottom = m_pos.y() - h * 0.5 * scale;
QVector2D left = center - delta * scale;
QVector2D right = center + delta * scale;
QVector3D va(left.x(), top, left.y());
QVector3D vb(right.x(), top, right.y());
QVector3D vc(right.x(), bottom, right.y());
QVector3D vd(left.x(), bottom, left.y());
QVector<QVector3D> result;
result << va << vb << vc << vd;
return result;
}
示例3: addPoint
/**
* update the bounding box by adding a new point.
*
* @param newPt new point
*/
void BBox::addPoint(const QVector2D& newPt) {
minPt.setX(qMin(minPt.x(), newPt.x()));
minPt.setY(qMin(minPt.y(), newPt.y()));
maxPt.setX(qMax(maxPt.x(), newPt.x()));
maxPt.setY(qMax(maxPt.y(), newPt.y()));
}
示例4: createScaledContainer_
QPixmap ContainerSVG::createScaledContainer_(const QVector2D &factors)
{
if (factors.x() == 1 && factors.y() == 1 && m_cache.contains(m_size))
{
return m_cache[m_size];
}
QSize mySize(qRound(m_size.width() * factors.x()),
qRound(m_size.height() * factors.y()));
if (!m_nocache && m_cache.contains(mySize))
{
return m_cache[mySize];
}
QPixmap pix(mySize);
pix.fill(Qt::transparent);
QPainter pixPainter(&pix);
pixPainter.setRenderHints(QPainter::Antialiasing |
QPainter::SmoothPixmapTransform, true);
m_renderer->render(&pixPainter);
pixPainter.end();
if (!m_nocache)
{
m_cache.insert(mySize, pix);
}
#ifdef IMAGEMAP_DEBUG
wzLog(LOG_IM) << "\tGenerated:" << m_filename << pix.size();
#endif
return pix;
}
示例5: save
void DesignDialog::save()
{
QList<Graph*> graph_list = graphView->getGraphList();
FileController fc;
fc.setFile(fileName);
fc.clearFile();
for(int i=0; i<graph_list.size(); i++) {
for(int j=0; j<graph_list[i]->getSize(); j++) {
QVector2D pnt = graph_list[i]->getPoint(j);
fc.appendPair(pnt.x(), pnt.y());
}
}
fc.setFile(fileName.left(fileName.lastIndexOf(".")) + ".tbl");
fc.clearFile();
for(int i=0; i<graph_list.size(); i++) {
qreal x_step = ui->intervalSpinBox->value();
qreal x_start = 0.;
qreal x_end = graph_list[i]->getPoint(graph_list[i]->getSize() - 1).x();
for ( int x=x_start; x<x_end; x+= x_step ) {
QVector2D pnt = graph_list[i]->getFunctionAtX(x);
fc.appendPair(pnt.x(), pnt.y());
}
}
}
示例6: mouseMoveEvent
void OpenGLWidget::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::LeftButton)
{
// Mouse release position - mouse press position
QVector2D diff = QVector2D(e->localPos()) - m_lastMousePosition;
m_lastMousePosition = QVector2D(e->localPos());
// Rotation axis is perpendicular to the mouse position difference vector
QVector3D n = QVector3D(diff.y(), diff.x(), 0.0).normalized();
// Update rotation
m_rotation = QQuaternion::fromAxisAndAngle(n, 2) * m_rotation;
// Update scene
updateGL();
}
else if (e->buttons() & Qt::MiddleButton)
{
QVector2D diff = (QVector2D(e->localPos()) - m_lastMousePosition) / 100;
m_lastMousePosition = QVector2D(e->localPos());
QVector3D n = QVector3D(-diff.x(), diff.y(), 0);
m_camera.setViewCenter(m_camera.viewCenter() + n);
updateGL();
}
}
示例7: SegmentIntersection
bool SegmentIntersection(QVector2D &result, QVector2D seg11, QVector2D seg12, QVector2D seg21, QVector2D seg22)
{
// Store the values for fast access and easy
// equations-to-code conversion
double x1 = seg11.x(), x2 = seg12.x(), x3 = seg21.x(), x4 = seg22.x();
double y1 = seg11.y(), y2 = seg12.y(), y3 = seg21.y(), y4 = seg22.y();
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
// If d is zero, there is no intersection
if (d == 0) return NULL;
// Get the x and y
double pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4);
double x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;
double y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d;
// Check if the x and y coordinates are within both lines
if ( x < std::min(x1, x2) || x > std::max(x1, x2) ||
x < std::min(x3, x4) || x > std::max(x3, x4) ) return false;
if ( y < std::min(y1, y2) || y > std::max(y1, y2) ||
y < std::min(y3, y4) || y > std::max(y3, y4) ) return false;
// Return the point of intersection
result.setX(x);
result.setY(y);
return true;
}
示例8: isSelected
bool GLWidget::isSelected(const QVector3D &vertex, const QVector2D &min, const QVector2D &max)
{
QVector2D result;
fromWorldToScreen(&result, vertex);
//if point on screen is inside rectangle, it's selected
return result.x() > min.x() && result.x() < max.x() && result.y() > min.y() && result.y() < max.y();
}
示例9: toolMouseReleaseEvent
// TODO: second plane
void SliceAdjustmentTool::toolMouseReleaseEvent(QMouseEvent *ev)
{
voxie::data::SliceImage& currentImg = (currentSlice == 0) ? this->sv->sliceImageFirst() : this->sv->sliceImageSecond();
voxie::data::SliceImage& otherImg = (currentSlice == 1) ? this->sv->sliceImageFirst() : this->sv->sliceImageSecond();
voxie::data::Slice* otherSlice = (currentSlice == 0) ? this->sv->slices().at(0) : this->sv->slices().at(1);
if(this->ctrlDown){
if(this->rotatingInProgress){
this->rotatingInProgress = false;
QVector2D cursorOnPlane = QVector2D(currentImg.pixelToPlanePoint(ev->pos(), true)).normalized();
float angle = (float) qAcos(QVector3D::dotProduct(this->rotationHypotenuse, cursorOnPlane));
// check clockwise or counterclockwise rotation
float sign = 1;
{
/* to know if cursor is left of hypotenuse rotate their coordinatesystem so that
* hypotenuse is points in xAxis direction and check if cursor.y is positive.
* Rotation matrix for this can be obtained from hypotenuse since its normalized
* counterclockwise clockwise
* cos(a) -sin(a) cos(a)/det sin(a)/det
* sin(a) cos(a) -sin(a)/det cos(a)/det
*
* with cos(a) = hypotenuse.x , sin(a) = hypotenuse.y , det = determinant(clockwise rotMat)
*/
qreal cos = this->rotationHypotenuse.x();
qreal sin = this->rotationHypotenuse.y();
qreal det = cos*cos + sin*sin;
// y-part of matrix multiplication (clockwise*cursor)
qreal rotCursorY = -sin/det * cursorOnPlane.x() + cos/det * cursorOnPlane.y();
sign = rotCursorY > 0 ? 1:-1;
}
if(this->selectedBoth)
{
QVector2D cursorOnPlane = QVector2D(otherImg.pixelToPlanePoint(ev->pos(), true)).normalized();
float angle = (float) qAcos(QVector3D::dotProduct(this->rotationHypotenuse2, cursorOnPlane));
// check clockwise or counterclockwise rotation
float sign = 1;
{
/* to know if cursor is left of hypotenuse rotate their coordinatesystem so that
* hypotenuse is points in xAxis direction and check if cursor.y is positive.
* Rotation matrix for this can be obtained from hypotenuse since its normalized
* counterclockwise clockwise
* cos(a) -sin(a) cos(a)/det sin(a)/det
* sin(a) cos(a) -sin(a)/det cos(a)/det
*
* with cos(a) = hypotenuse.x , sin(a) = hypotenuse.y , det = determinant(clockwise rotMat)
*/
qreal cos = this->rotationHypotenuse2.x();
qreal sin = this->rotationHypotenuse2.y();
qreal det = cos*cos + sin*sin;
// y-part of matrix multiplication (clockwise*cursor)
qreal rotCursorY = -sin/det * cursorOnPlane.x() + cos/det * cursorOnPlane.y();
sign = rotCursorY > 0 ? 1:-1;
}
rotateSlice(otherSlice, otherSlice->normal(), ((angle)/3.1415f) * 180 * sign);
}
rotateSlice(this->slice, this->slice->normal(), ((angle)/3.1415f) * 180 * sign);
}
}
}
示例10: PointLineCompare
int PointLineCompare(QVector2D pointm, QVector2D dir, QVector2D quarrypoint)//returns 1 if point is on right, -1 if point is on left
{
//double MAx = (quarrypoint.x() - pointm.x());
//double MAy = (quarrypoint.y() - pointm.y());
double position = (dir.x()*(quarrypoint.y() - pointm.y())) - (dir.y()*(quarrypoint.x() - pointm.x()));
return -int(ceil(position));
}
示例11: PointLineCompare
int PointLineCompare(QVector2D pointm, QVector2D dir, QVector2D quarrypoint)//如果点在右则返回1,如果点在左,则返回-1
{
//double MAx = (quarrypoint.x() - pointm.x());
//double MAy = (quarrypoint.y() - pointm.y());
double position = (dir.x()*(quarrypoint.y() - pointm.y())) - (dir.y()*(quarrypoint.x() - pointm.x()));
return -int(ceil(position));
}
示例12: PointsShare
bool PointsShare(QVector2D point1, QVector2D point2, double tolerance)
{
if(IsZero(point2.x() - point1.x(), tolerance) && IsZero(point2.y() - point1.y(),tolerance))
{
return true;
}
return false;
}
示例13:
bool BBox2D::contains(const QVector2D &p) {
if (p.x() < corner0.x()) return false;
if (p.y() < corner0.y()) return false;
if (p.x() > corner1.x()) return false;
if (p.y() > corner1.y()) return false;
return true;
}
示例14: Property
PropertyGroup::PropertyGroup(QVector2D min, QVector2D max, QVector2D t, QString name)
{
createBox(name);
properties.emplace_back(new Property(min.x(), max.x(), t.x(), box));
properties.emplace_back(new Property(min.y(), max.y(), t.y(), box));
config();
}
示例15: loadScene
void GameApplication::loadScene()
{
disconnect(&m_window, &QWindow::activeChanged, this, &GameApplication::loadScene);
CaveGenerator cgen(MAP_SIZE, MAP_SIZE, 10);
m_map = cgen.GetCaveMap();
ObjectsGenerator ogen(m_map);
m_map = ogen.GenerateObj();
std::shared_ptr<BaseScene> scene = std::make_shared<BaseScene>();
scene->camera().setViewport(m_window.size());
//new ColoredCube(scene.get(), {0, 0, 0}, ColoredCube::WallType::CaveGround);
new SkyBox(scene.get());
int x = 0;
int z = 0;
for (size_t i = 0; i < MAP_SIZE; i++, z += WALL_LEN)
{
x = 0;
for (size_t j = 0; j < MAP_SIZE; j++, x += WALL_LEN)
{
if (m_map[i][j] == WALL_CELL)
{
new ColoredCube(scene.get(), {z, 0, x}, ColoredCube::WallType::CaveWall);
}
else if (m_map[i][j] == ENTERANCE_CELL)
{
m_player = new PlayerNode(scene.get(), QVector2D(z, x));
new ColoredCube(scene.get(), {z, 0, x}, ColoredCube::WallType::CaveGround);
}
else if (m_map[i][j] == SIDE_EXIT_CELL)
{
m_exit = new ExitNode(scene.get(), QVector2D(z, x));
}
else if (m_map[i][j] == GROUND_EXIT_CELL)
{
}
else if (m_map[i][j] == FREE_CELL)
{
new ColoredCube(scene.get(), {z, 0, x}, ColoredCube::WallType::CaveGround);
}
}
}
scene->setPlayer(m_player);
scene->setExit(m_exit);
QVector2D pos = m_player->GetCoords();
scene->camera().lookAt(QVector3D(pos.x(), CAM_UP, pos.y() - CAM_RANGE), QVector3D(pos.x(), CAM_UP_ANGLE, pos.y()), QVector3D(0, 0, 1));
CollisionHandler colHandler;
colHandler.SetMap(m_map);
colHandler.SetCoord(pos);
m_window.SetCollisionHandler(colHandler);
m_window.pushScene(scene);
}