当前位置: 首页>>代码示例>>C++>>正文


C++ QVector2D::setX方法代码示例

本文整理汇总了C++中QVector2D::setX方法的典型用法代码示例。如果您正苦于以下问题:C++ QVector2D::setX方法的具体用法?C++ QVector2D::setX怎么用?C++ QVector2D::setX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QVector2D的用法示例。


在下文中一共展示了QVector2D::setX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

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;
}
开发者ID:etcwilde,项目名称:computer_graphics,代码行数:29,代码来源:catmulrom.cpp

示例2: updatePosition

//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?
}
开发者ID:louen,项目名称:chmeup,代码行数:34,代码来源:GameObject.cpp

示例3: SegmentIntersection

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;
}
开发者ID:SHINOTECH,项目名称:B9Creator-QT5.X,代码行数:26,代码来源:geometricfunctions.cpp

示例4: rotOnZ

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;
}
开发者ID:guilhemheinrich,项目名称:MultiAgentSystem,代码行数:7,代码来源:tools.cpp

示例5: advance

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();
}
开发者ID:dragly,项目名称:particleflow,代码行数:32,代码来源:gamescene.cpp

示例6: pointSegmentDistanceXY

/**
 * エッジ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);
}
开发者ID:gnishida,项目名称:Morph,代码行数:35,代码来源:Util.cpp

示例7: maxPoint

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;
}
开发者ID:gnishida,项目名称:ExRoadDesigner,代码行数:30,代码来源:HoughTransform.cpp

示例8:

/**
 * 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);
}
开发者ID:gnishida,项目名称:StreetDesigner,代码行数:29,代码来源:GLWidget.cpp

示例9: rotate

/**
 * 指定された点を、反時計回りに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;
}
开发者ID:gnishida,项目名称:VHCMCMC,代码行数:11,代码来源:Util.cpp

示例10: rotVelToVec

/*-----------------------------------------------------------------------------
--  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;
}
开发者ID:KaraJ,项目名称:conpenguum,代码行数:31,代码来源:Physics.cpp

示例11: projLatLonToMeter

/**
 * 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 &centerLatLon) {
	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; 
}
开发者ID:gnishida,项目名称:FBCDesigner,代码行数:26,代码来源:Util.cpp

示例12: rayStar

/**
 * 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);
}
开发者ID:gnishida,项目名称:CityDesigner,代码行数:53,代码来源:GLWidget3D.cpp

示例13: recalculateCenter

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());
	
}
开发者ID:nayyden,项目名称:ZVector,代码行数:20,代码来源:Group.cpp

示例14: generateStack

    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) );
      }
    }
开发者ID:avilleret,项目名称:omnidome,代码行数:40,代码来源:Sphere.cpp

示例15: pointSegmentDistanceXY

/**
 * 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);
}
开发者ID:gnishida,项目名称:FBCDesigner,代码行数:42,代码来源:Util.cpp


注:本文中的QVector2D::setX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。