void GameScene::advance() { currentTime = time.elapsed(); if(firstStep) { _dt = 0; firstStep = false; } else { _dt = (currentTime - lastFrameTime) / 1000.0; } lastFrameTime = currentTime; particlesToAdd += _dt * particlesPerSecond; // Activate the next not yet active particle if(currentParticleNumber < level()*100000 ) { int particlesToAddNow = (int)particlesToAdd; // how many particles (integer number) to add this frame for(int i = 0; i < particlesToAddNow; i++) { Particle* particle = new Particle(); _particles.append(particle); addItem(particle); // always add items before adjusting position (because they need a gameScene) particle->setActive(true); QVector2D particlePosition = generatorPosition; particlePosition.setY(particlePosition.y() + random()*0.001); particle->setPosition(particlePosition); QVector2D particleVelocity = generatorVelocityDirection * generatorVelocityMagnitude; particleVelocity.setX(particleVelocity.x() + random()*0.001); particleVelocity.setY(particleVelocity.y() + random()*0.001); particle->setVelocity(particleVelocity); currentParticleNumber++; // Increase the global counter particlesToAdd--; // For each added particle, remove one from the queue } } QGraphicsScene::advance(); }
QVector2D CatmulRom::map_to_2D(QVector3D axis, QVector3D vec) { QVector2D ret; // axis.normalize(); // Looking along z axis if (axis.x() != 0 && axis.y() != 0 && axis.z() == 0) { ret.setX(vec.x() * axis.x()); ret.setY(vec.y() * axis.y()); } // Looking along y axis else if (axis.x() != 0 && axis.y() == 0 && axis.z() != 0) { ret.setX(vec.x() * axis.x()); ret.setY(vec.z() * axis.z()); } // Looking along x axis else if (axis.x() == 0 && axis.y() != 0 && axis.z() != 0) { ret.setX(vec.z() * axis.z()); ret.setY(vec.y() * axis.y()); } else { // Arbitrary axis } return ret; }
//Default implementation void GameObject::updatePosition(float timeElapsed) { //For each frame, compute the new speed and position regarding the acceleration value //and the time elapsed since the last computation //Compute new position, with speed threshold, to avoid shaking effect of the sprite on low speeds QVector2D tempSpeed = speed ; if(abs(tempSpeed.x())<=4) tempSpeed.setX(0); if(abs(tempSpeed.y())<=4) tempSpeed.setY(0); position += (tempSpeed*timeElapsed + (1/2)*acceleration*timeElapsed*timeElapsed).toPointF(); //Compute new speed, with frictional resistance (typically 0.995) FIXME : the game seems laggy with a coeff friction... speed = frictionCoef*speed + acceleration*timeElapsed; if(speed.length()>=m_maxSpeed) speed = m_maxSpeed*speed.normalized(); //Adjust position with the window borders //WARN: Modulus operator does not work for floats position.setX( position.x() - (float)((int)(position.x()/screenWidthGlobal))*screenWidthGlobal ); if(position.x()<0) position.setX(position.x() + (float)screenWidthGlobal) ; position.setY( position.y() - (float)((int)(position.y()/screenHeightGlobal))*screenHeightGlobal ); if(position.y()<0) position.setY(position.y() + (float)screenHeightGlobal); //Donatien: Is there a nicer way to saturate speed and acceleration? //Same values for every objects or a configurable one? }
bool SegmentIntersection(QVector2D &result, QVector2D seg11, QVector2D seg12, QVector2D seg21, QVector2D seg22) { // 保存这个数值以便快速访问并简化公式到代码的转换 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); //如果d是零,没有交集 if (d == 0) return NULL; // 获取x和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; // 检查,x和y坐标是否都在两条轴线内里 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; // 返回交点坐标 result.setX(x); result.setY(y); return true; }
void SceneTransformTool::mouseDragged(QMouseEvent *e) { QVector2D deltaMousePos = QVector2D( e->localPos() ) - m_mousePressPosition; deltaMousePos.setY( -deltaMousePos.y() ); switch( m_toolMode ) { case ToolMode::SCN_ROTATE: m_sceneTransform.m_rotation_x *= QQuaternion::fromEulerAngles( QVector3D( 0.f, deltaMousePos.x(), 0.f ) ); m_sceneTransform.m_rotation_y *= QQuaternion::fromEulerAngles( QVector3D( - deltaMousePos.y(), 0.f, 0.f ) ); break; case ToolMode::SCN_TRANSLATE: m_sceneTransform.m_position += deltaMousePos / 40; break; case ToolMode::SCN_SCALE: m_sceneTransform.m_scale += deltaMousePos.y() * m_sceneTransform.m_scale / 100.f; m_sceneTransform.m_scale = qMax( 0.f, m_sceneTransform.m_scale ); break; } }
void Tools::rotOnZ(QVector2D &x, float angle) { QVector2D tmp; tmp.setX(cos(angle)*x.x() - sin(angle)*x.y()); tmp.setY(sin(angle)*x.x() + cos(angle)*x.y()); x = tmp; }
/** * エッジABと頂点Cの距離を計算して返却する。さらに、エッジAB上で最も頂点Cに近い点をclosestPtInABに格納する。 */ float Util::pointSegmentDistanceXY(const QVector2D& a, const QVector2D& b, const QVector2D& c, QVector2D& closestPtInAB) { float dist; float r_numerator = (c.x()-a.x())*(b.x()-a.x()) + (c.y()-a.y())*(b.y()-a.y()); float r_denomenator = (b.x()-a.x())*(b.x()-a.x()) + (b.y()-a.y())*(b.y()-a.y()); float r = r_numerator / r_denomenator; // float px = a.x() + r*(b.x()-a.x()); float py = a.y() + r*(b.y()-a.y()); // float s = ((a.y()-c.y())*(b.x()-a.x())-(a.x()-c.x())*(b.y()-a.y()) ) / r_denomenator; float distanceLine = fabs(s)*sqrt(r_denomenator); // エッジAB上で最も頂点Cに近い点をclosestPtInABに格納する。 closestPtInAB.setX(px); closestPtInAB.setY(py); if ((r >= 0) && (r <= 1)) { dist = distanceLine; } else { float dist1 = (c.x()-a.x())*(c.x()-a.x()) + (c.y()-a.y())*(c.y()-a.y()); float dist2 = (c.x()-b.x())*(c.x()-b.x()) + (c.y()-b.y())*(c.y()-b.y()); if (dist1 < dist2) { dist = sqrt(dist1); } else { dist = sqrt(dist2); } } return abs(dist); }
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; }
QVector2D HoughTransform::maxPoint() const { QVector2D ret; float max_value = 0.0f; for (int v = 0; v < htSpace.rows; v++) { for (int u = 0; u < htSpace.cols; u++) { if (htSpace.at<float>(v, u) > max_value) { max_value = htSpace.at<float>(v, u); ret.setX(u + 0.5f); ret.setY(v + 0.5f); } } } std::cout << "max_value: " << max_value << std::endl; // 投票結果を画像として保存する cv::Mat m; cv::flip(htSpace, m, 0); m /= (max_value / 255.0f); m.convertTo(m, CV_8U); cv::imwrite(QString("result%1.jpg").arg(scale).toUtf8().data(), m); ret /= scale; ret += bbox.minPt; return ret; }
/** * Convert the screen space coordinate (x, y) to the model space coordinate. */ void GLWidget::mouseTo2D(int x,int y, QVector2D &result) { GLint viewport[4]; GLdouble modelview[16]; GLdouble projection[16]; // retrieve the matrices glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, viewport); // retrieve the projected z-buffer of the origin GLdouble origX, origY, origZ; gluProject(0, 0, 0, modelview, projection, viewport, &origX, &origY, &origZ); // set up the projected point GLfloat winX = (float)x; GLfloat winY = (float)viewport[3] - (float)y; GLfloat winZ = origZ; // unproject the image plane coordinate to the model space GLdouble posX, posY, posZ; gluUnProject(winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ); result.setX(posX); result.setY(posY); }
/** * 指定された点を、反時計回りにrad回転させた位置を返却する。 */ QVector2D Util::rotate(const QVector2D &pt, float rad) { QVector2D ret; ret.setX(cosf(rad) * pt.x() - sinf(rad) * pt.y()); ret.setY(sinf(rad) * pt.x() + cosf(rad) * pt.y()); return ret; }
/*----------------------------------------------------------------------------- -- FUNCTION: rotVelToVec -- -- DATE: February 18, 2010 -- -- REVISIONS: v0.1 -- -- DESIGNER: Gameplay/Physics Team -- -- PROGREMMER: Gameplay/Physics Team -- -- INTERFACE: rotVelToVec(int rot, int velocity) -- -- NOTES: Takes a rotation value and a velocity and returns the correct -- vector. TASK: needs to be made more efficient. -- -- RETURNS: Qpoint style vector. -- ------------------------------------------------------------------------------*/ QVector2D rotVelToVec(int rot, double velocity) { QVector2D vector; //correcting the function here and removing the magic number double radians = DEGTORAD(rot); double x, y; y = sin(radians) * velocity; x = cos(radians) * velocity; vector.setX(x); vector.setY(y); return vector; }
/** * Project latitude/longitude coordinate to world coordinate. * Mercator projection cannot be used for this purpose, becuase * it deforms the area especially in the high latitude regions. * Hubeny's theorum should be used for this purpose, but not yet implemented yet. * * @param lat latitude * @param lon longitude * @param centerLat latitude of the center of the map * @param centerLon longitude of the center of the map * @return the world coordinate (Z coordinate is dummy.) */ QVector2D Util::projLatLonToMeter(const QVector2D &latLon, const QVector2D ¢erLatLon) { QVector2D result; double y = latLon.y() / 180 * M_PI; double dx = (latLon.x() - centerLatLon.x()) / 180 * M_PI; double dy = (latLon.y() - centerLatLon.y()) / 180 * M_PI; double radius = 6378137; result.setX(radius * cos(y) * dx); result.setY(radius * dy); return result; }
/** * Convert the screen space coordinate (x, y) to the model space coordinate. */ void GLWidget3D::mouseTo2D(int x,int y, QVector2D &result) { updateCamera(); updateGL(); GLint viewport[4]; // retrieve the matrices glGetIntegerv(GL_VIEWPORT, viewport); // retrieve the projected z-buffer of the origin GLfloat winX,winY,winZ; winX = (float)x; winY = (float)viewport[3] - (float)y; /*glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); GLdouble posX, posY, posZ; gluUnProject( winX, winY, winZ, camera->mvMatrix.data(), camera->pMatrix.data(), viewport, &posX, &posY, &posZ); // unproject the image plane coordinate to the model space float znear=10.0f,zFar= 10.0f*2000.0f; GLdouble posXFar, posYFar, posZFar; gluUnProject( winX, winY, zFar, camera->mvMatrix.data(), camera->pMatrix.data(), viewport, &posXFar, &posYFar, &posZFar); QVector3D rayStar(posX,posY,posZ); QVector3D rayEnd(posXFar,posYFar,posZFar); double t; QVector3D q1(0,0,1.0f); QVector3D q2(0,0,0); QVector3D result3D; printf("mouse %d %d win %f %f z1 %f z2 %f Pos %f %f %f PosF %f %f %f\n",x,y,winX,winY,winZ,zFar,posX,posY,posZ,posXFar,posYFar,posZFar); if(Util::planeIntersectWithLine(rayStar,rayEnd,q1,q2,t,result3D)!=0){ result->setX(result3D.x()); result->setY(result3D.y()); }else{ printf("fail hit\n"); } //return; result->setX(posX); result->setY(posY);*/ GLdouble wx, wy, wz; /* returned world x, y, z coords */ GLdouble wx2, wy2, wz2; /* returned world x, y, z coords */ gluUnProject( winX, winY, 0.0f, camera->mvMatrix.data(), camera->pMatrix.data(), viewport, &wx, &wy, &wz); gluUnProject( winX, winY, 1.0f, camera->mvMatrix.data(), camera->pMatrix.data(), viewport, &wx2, &wy2, &wz2); double f = wz / ( wz2 - wz ); double x2d = wx - f * (wx2 - wx ); double y2d = wy - f * (wy2 - wy ); result.setX(x2d); result.setY(y2d); //printf("Mouse %d %d\n",x,y); }
void Group::recalculateCenter() { double* m = m_mat.data(); QVector2D center; QVector3D bounds[2]; getBoundingBox4dv(bounds); center.setX((bounds[1].x() - bounds[0].x())/2); center.setY((bounds[1].y() - bounds[0].y())/2); translate(center.x() - m[12], center.y() - m[13]); m[12] -= center.x(); m[13] -= center.y(); rotationCenter.setX((bounds[1].x() - bounds[0].x())/2 + bounds[0].x()); rotationCenter.setY((bounds[1].y() - bounds[0].y())/2 + bounds[0].y()); }
void Sphere::generateStack(float _top, float _bottom, float _topRadius, float _bottomRadius) { size_t _startIndex = vertices_.size(); for (size_t i = 0; i <= slices_; ++i) { /// Generate vertices float _m = 2.0 * M_PI * float(i) / slices_; float _cos = cos(_m), _sin = sin(_m); QVector3D _topPoint(_cos * _topRadius,_sin * _topRadius,_top); QVector3D _bottomPoint(_cos * _bottomRadius,_sin * _bottomRadius,_bottom); QVector3D _normalTop(_topPoint.normalized()); QVector3D _normalBottom(_bottomPoint.normalized()); auto getTexCoord = [&](QVector3D const& _v) -> QVector2D { QVector2D texCoords; QVector3D uvw = _v.normalized(); texCoords.setX(i / float(slices_)); texCoords.setY(1.0 - acos(uvw.z()) / M_PI); return texCoords; }; QVector2D _texCoordTop(getTexCoord(_topPoint)); QVector2D _texCoordBottom(getTexCoord(_bottomPoint)); vertices_.emplace_back(_topPoint,_normalTop,_texCoordTop);//QVector2D(float(i)/slices_,1.0 - acos(_normalTop.z()) / M_PI)); vertices_.emplace_back(_bottomPoint,_normalBottom,_texCoordBottom);//QVector2D(float(i)/slices_,1.0 - acos(_normalBottom.z()) / M_PI)); /// Top triangle indices_.push_back(_startIndex + 2 * i); indices_.push_back(_startIndex + 2 * i + 1); indices_.push_back(_startIndex + 2 * (i + 1) ); /// Bottom triangle indices_.push_back(_startIndex + 2 * i + 1); indices_.push_back(_startIndex + 2 * (i + 1) +1 ); indices_.push_back(_startIndex + 2 * (i + 1) ); } }
/** * Compute the distance between the edge A-B and the edge C-D. Store the coordinate of the closest point in closestPtInAB. */ float Util::pointSegmentDistanceXY(const QVector2D& a, const QVector2D& b, const QVector2D& c, QVector2D& closestPtInAB) { float dist; float r_numerator = (c.x()-a.x())*(b.x()-a.x()) + (c.y()-a.y())*(b.y()-a.y()); float r_denomenator = (b.x()-a.x())*(b.x()-a.x()) + (b.y()-a.y())*(b.y()-a.y()); // For the case that the denominator is 0. if (r_denomenator <= 0.0f) { closestPtInAB = a; return (a - c).length(); } float r = r_numerator / r_denomenator; // float px = a.x() + r*(b.x()-a.x()); float py = a.y() + r*(b.y()-a.y()); // float s = ((a.y()-c.y())*(b.x()-a.x())-(a.x()-c.x())*(b.y()-a.y()) ) / r_denomenator; float distanceLine = fabs(s)*sqrt(r_denomenator); closestPtInAB.setX(px); closestPtInAB.setY(py); if ((r >= 0) && (r <= 1)) { dist = distanceLine; } else { float dist1 = (c.x()-a.x())*(c.x()-a.x()) + (c.y()-a.y())*(c.y()-a.y()); float dist2 = (c.x()-b.x())*(c.x()-b.x()) + (c.y()-b.y())*(c.y()-b.y()); if (dist1 < dist2) { dist = sqrt(dist1); } else { dist = sqrt(dist2); } } return abs(dist); }
void MTT::findBoundaryVertices(RoadGraph* roads, RoadVertexDesc &v1_desc, RoadVertexDesc &v2_desc) { PCA pca; doPCA(roads, pca); QVector2D evector; evector.setX(pca.evectors.at<double>(0, 0)); evector.setY(pca.evectors.at<double>(1, 0)); float min_score = std::numeric_limits<float>::max(); float max_score = -std::numeric_limits<float>::max(); int min_pt_id, max_pt_id; for (int i = 0; i < pca.score.rows; i++) { float score = pca.score.at<double>(i, 0); if (score < min_score) { min_score = score; min_pt_id = i; } if (score > max_score) { max_score = score; max_pt_id = i; } } int count = 0; RoadVertexIter vi, vend; for (boost::tie(vi, vend) = boost::vertices(roads->graph); vi != vend; ++vi) { if (!roads->graph[*vi]->valid) continue; if (count == min_pt_id) { v1_desc = *vi; } if (count == max_pt_id) { v2_desc = * vi; } count++; } }
QVector2D Graph::graphToNode(QVector2D graph) { QVector2D ret; ret.setX(graphToNodeX(graph.x())); ret.setY(graphToNodeY(graph.y())); return ret; }
void PropertyGroup::getValue(QVector2D & v) { v.setX(properties.at(0)->getValue()); v.setY(properties.at(1)->getValue()); }
bool PropertyMatrixModel::setData(const QModelIndex &index, const QVariant &data, int role) { if (!index.isValid()) return false; if (role != Qt::EditRole) return false; bool ok = false; float floatData = data.toFloat(&ok); if (!ok) return false; switch (m_matrix.type()) { case QVariant::Vector2D: { QVector2D value = m_matrix.value<QVector2D>(); switch (index.row()) { case 0: value.setX(floatData); break; case 1: value.setY(floatData); break; } m_matrix = value; break; } case QVariant::Vector3D: { QVector3D value = m_matrix.value<QVector3D>(); switch (index.row()) { case 0: value.setX(floatData); break; case 1: value.setY(floatData); break; case 2: value.setZ(floatData); break; } m_matrix = value; break; } case QVariant::Vector4D: { QVector4D value = m_matrix.value<QVector4D>(); switch (index.row()) { case 0: value.setX(floatData); break; case 1: value.setY(floatData); break; case 2: value.setZ(floatData); break; case 3: value.setW(floatData); break; } m_matrix = value; break; } #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) case QVariant::Quaternion: { float pitch, yaw, roll; const QQuaternion value = m_matrix.value<QQuaternion>(); value.getEulerAngles(&pitch, &yaw, &roll); switch (index.row()) { case 0: pitch = floatData; break; case 1: yaw = floatData; break; case 2: roll = floatData; break; } m_matrix = QQuaternion::fromEulerAngles(pitch, yaw, roll); break; } #endif case QVariant::Matrix: { QMatrix value = m_matrix.value<QMatrix>(); switch (index.row() << 4 | index.column()) { case 0x00: value.setMatrix(floatData, value.m12(), value.m21(), value.m22(), value.dx(), value.dy()); break; case 0x01: value.setMatrix(value.m11(), floatData, value.m21(), value.m22(), value.dx(), value.dy()); break; case 0x10: value.setMatrix(value.m11(), value.m12(), floatData, value.m22(), value.dx(), value.dy()); break; case 0x11: value.setMatrix(value.m11(), value.m12(), value.m21(), floatData, value.dx(), value.dy()); break; case 0x20: value.setMatrix(value.m11(), value.m12(), value.m21(), value.m22(), floatData, value.dy()); break; case 0x21: value.setMatrix(value.m11(), value.m12(), value.m21(), value.m22(), value.dx(), floatData); break; } m_matrix = value; break; } case QVariant::Transform: { QTransform value = m_matrix.value<QTransform>(); switch (index.row() << 4 | index.column()) { case 0x00: value.setMatrix(floatData, value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break; case 0x01: value.setMatrix(value.m11(), floatData, value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break; case 0x02: value.setMatrix(value.m11(), value.m12(), floatData, value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break; case 0x10: value.setMatrix(value.m11(), value.m12(), value.m13(), floatData, value.m22(), value.m23(), value.m31(), value.m32(), value.m33()); break; case 0x11: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), floatData, value.m23(), value.m31(), value.m32(), value.m33()); break; case 0x12: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), floatData, value.m31(), value.m32(), value.m33()); break; case 0x20: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), floatData, value.m32(), value.m33()); break; case 0x21: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), floatData, value.m33()); break; case 0x22: value.setMatrix(value.m11(), value.m12(), value.m13(), value.m21(), value.m22(), value.m23(), value.m31(), value.m32(), floatData); break; } m_matrix = value; break; } case QVariant::Matrix4x4: { QMatrix4x4 value = m_matrix.value<QMatrix4x4>(); value(index.row(), index.column()) = floatData; m_matrix = value; break; } } emit dataChanged(index, index); return true; }
void CALLBACK tessVertexCB(const GLvoid *data, void *user_data) { GLdouble* vertData = (GLdouble*)data; QVector2D vert; vert.setX(vertData[0]); vert.setY(vertData[1]); B9Tesselator* tess = (B9Tesselator*)user_data; if(tess->currentEnumType == GL_TRIANGLES) { tess->GetTrangleStrip()->push_back(vert); } else if(tess->currentEnumType == GL_TRIANGLE_FAN) { if(tess->fanFirstTri) { tess->fanOriginVertex = vert; tess->fanFirstTri = false; tess->fanSecondTri = true; return; } else if(tess->fanSecondTri) { tess->fanFirstTri = false; tess->fanSecondTri = false; tess->prevVertex = vert; } else { tess->GetTrangleStrip()->push_back(tess->fanOriginVertex); tess->GetTrangleStrip()->push_back(tess->prevVertex); tess->GetTrangleStrip()->push_back(vert); tess->prevVertex = vert; } } else if(tess->currentEnumType == GL_TRIANGLE_STRIP) { if(tess->stripFirstTri) { tess->prevPrevVertex = vert; tess->stripFirstTri = false; tess->stripSecondTri = true; return; } else if(tess->stripSecondTri) { tess->prevVertex = vert; tess->stripFirstTri = false; tess->stripSecondTri = false; } else { if(tess->stripCount%2)//odd { tess->GetTrangleStrip()->push_back(tess->prevVertex); tess->GetTrangleStrip()->push_back(tess->prevPrevVertex); tess->GetTrangleStrip()->push_back(vert); } else { tess->GetTrangleStrip()->push_back(tess->prevPrevVertex); tess->GetTrangleStrip()->push_back(tess->prevVertex); tess->GetTrangleStrip()->push_back(vert); } tess->prevPrevVertex = tess->prevVertex; tess->prevVertex = vert; } tess->stripCount++; } else { qDebug() << "B9Tesselator: WARNING! un-implemented OpenGl Triangle Enum!"; } }
void OpenGLWidget::getKeys() { if (rendermodeLR != ALL) { if (keys[Qt::Key::Key_W]) { origin.y += (ORIGIN_MOVE / zoom); offset.setY(offset.y() + PIXEL_MOVE); fractal.computeVariables.at(0)->setValue(); } if (keys[Qt::Key::Key_S]) { origin.y -= (ORIGIN_MOVE / zoom); offset.setY(offset.y() - PIXEL_MOVE); fractal.computeVariables.at(0)->setValue(); } if (keys[Qt::Key::Key_A]) { origin.x -= (ORIGIN_MOVE / zoom); offset.setX(offset.x() - PIXEL_MOVE); fractal.computeVariables.at(0)->setValue(); } if (keys[Qt::Key::Key_D]) { origin.x += (ORIGIN_MOVE / zoom); offset.setX(offset.x() + PIXEL_MOVE); fractal.computeVariables.at(0)->setValue(); } } if (keys[Qt::Key::Key_L]) fill = false; if (keys[Qt::Key::Key_F]) fill = true; if (offset.x() >= BLOCK_WIDTH) { majorOffset.setX(majorOffset.x() + BLOCK_WIDTH); rendermodeLR = RIGHT; offset.setX(offset.x() - BLOCK_WIDTH); } else if (offset.x() < 0) { majorOffset.setX(majorOffset.x() - BLOCK_WIDTH); rendermodeLR = LEFT; offset.setX(offset.x() + BLOCK_WIDTH); } if (offset.y() >= BLOCK_HEIGHT) { majorOffset.setY(majorOffset.y() + BLOCK_HEIGHT); rendermodeTB = TOP; offset.setY(offset.y() - BLOCK_HEIGHT); } else if (offset.y() < 0) { majorOffset.setY(majorOffset.y() - BLOCK_HEIGHT); rendermodeTB = BOTTOM; offset.setY(offset.y() + BLOCK_HEIGHT); } if (keys[Qt::Key::Key_R]) { origin = vec2(0.0, 0.0); fractal.computeVariables.at(0)->setValue(); zoom = 1.f; fractal.computeVariables.at(fractal.computeVariables.size() - 1)->setValue(); maxIterations = 100; fractal.computeVariables.at(1)->setValue(); rendermodeLR = ALL; } if (keys[Qt::Key::Key_C]) rendermodeLR = ALL; if (majorOffset.x() >= IMAGE_WIDTH) majorOffset.setX(majorOffset.x() - IMAGE_WIDTH); else if (majorOffset.x() < 0) majorOffset.setX(majorOffset.x() + IMAGE_WIDTH); if (majorOffset.y() >= IMAGE_HEIGHT) majorOffset.setY(majorOffset.y() - IMAGE_HEIGHT); else if (majorOffset.y() < 0) majorOffset.setY(majorOffset.y() + IMAGE_HEIGHT); }
QVector2D Graph::nodeToGraph(QVector2D node) { QVector2D ret; ret.setX(nodeToGraphX(node.x())); ret.setY(nodeToGraphY(node.y())); return ret; }
void TileDownloader::downloadTiles(){ //get all the values: double longLeft = ui->doubleSpinBoxLeftLong->value(); double longRight = ui->doubleSpinBoxRightLong->value(); double latTop = ui->doubleSpinBoxTopLat->value(); double latBottom = ui->doubleSpinBoxBottomLat->value(); int level = ui->spinBoxLevel->value(); QString outputPath = ui->lineEditOutputPath->text(); if(longLeft >= longRight){ QMessageBox msgBox; msgBox.setWindowTitle("Tile Downloader"); msgBox.setText("Error."); msgBox.setIcon(QMessageBox::Critical); msgBox.setInformativeText("Left Long is bigger than Right Long (or equal)."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); int ret = msgBox.exec(); return; } if(latBottom >= latTop){ QMessageBox msgBox; msgBox.setWindowTitle("Tile Downloader"); msgBox.setText("Error."); msgBox.setIcon(QMessageBox::Critical); msgBox.setInformativeText("Bottom Lat is bigger than Top Lat (or equal)."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); int ret = msgBox.exec(); return; } //try to create the output path if not existing QDir dir; if(!dir.mkpath(outputPath)){ QMessageBox msgBox; msgBox.setWindowTitle("Tile Downloader"); msgBox.setText("Error."); msgBox.setIcon(QMessageBox::Critical); msgBox.setInformativeText("Couldn't create output path."); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); int ret = msgBox.exec(); return; } ///////////////////////////////////////////////////////////////////////////////////// //work it tiles_to_load.clear(); current_tile_index = 0; current_tile_index_1 = 0; current_tile_index_2 = 0; current_tile_index_3 = 0; current_tile_index_4 = 0; current_outputPath = outputPath; current_level = level; image_buffer.clear(); path_buffer.clear(); //get topLeft tile QVector2D topLeftTile; { int pixelX; int pixelY; int tileX; int tileY; MapUtils::LatLongToPixelXY(latTop,longLeft,level,pixelX,pixelY); MapUtils::PixelXYToTileXY(pixelX,pixelY,tileX,tileY); topLeftTile.setX(tileX); topLeftTile.setY(tileY); } //get bottomRight tile QVector2D bottomRightTile; { int pixelX; int pixelY; int tileX; int tileY; MapUtils::LatLongToPixelXY(latBottom,longRight,level,pixelX,pixelY); MapUtils::PixelXYToTileXY(pixelX,pixelY,tileX,tileY); bottomRightTile.setX(tileX); bottomRightTile.setY(tileY); } qDebug() << topLeftTile; qDebug() << MapUtils::TileXYToQuadKey(topLeftTile.x(),topLeftTile.y(),level); qDebug() << bottomRightTile; qDebug() << MapUtils::TileXYToQuadKey(bottomRightTile.x(),bottomRightTile.y(),level); //fill the list with all TILES TO LOAD for(int x_coord = topLeftTile.x(); x_coord <= bottomRightTile.x(); x_coord++){ for(int y_coord = topLeftTile.y(); y_coord <= bottomRightTile.y(); y_coord++){ tiles_to_load.append(QVector2D(x_coord,y_coord)); } } qDebug() << tiles_to_load.size(); startImgDownloader_1(); startImgDownloader_2(); startImgDownloader_3(); startImgDownloader_4(); }
foreach (ViewWidget *view, _linkedViews) { GeographicalViewWidget *gw = (GeographicalViewWidget*)view->mapWidget(); QVector2D r = gw->getScalarRange(); range.setX(std::min(range.x(), r.x())); range.setY(std::max(range.y(), r.y())); }