本文整理汇总了C++中Vector2D::x方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector2D::x方法的具体用法?C++ Vector2D::x怎么用?C++ Vector2D::x使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2D
的用法示例。
在下文中一共展示了Vector2D::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleMovement
void Flying::handleMovement(Vector2D velocity)
{
Vector2D newPos = m_position;
newPos.y(newPos.y() + velocity.y());
// Check collisions in y axis
if (newPos.y() + getCollider().y <= 0
|| newPos.y() + getCollider().y + getCollider().h >= TheGame::Instance().getMapHeight()
|| checkCollideTile(newPos)
|| checkCollideObject(newPos))
{
m_bYCollision = !m_bYCollision;
}
else
{
m_position.y(newPos.y());
}
// Update new position
newPos = m_position;
newPos.x(m_position.x() + velocity.x());
// Check collisions in x axis
if (newPos.x() + getCollider().x <= 0
|| newPos.x() + getCollider().x + getCollider().w >= TheGame::Instance().getMapWidth()
|| checkCollideTile(newPos)
|| checkCollideObject(newPos))
{
// There have been a collision, so change direction
m_bXCollision = !m_bXCollision;
}
else
{
// Move to new x position
m_position.x(newPos.x());
}
}
示例2: paint
void MarkerMapObject::paint(QPainter &painter, QRect view, int scale) {
// Save the painter state for this paint session
// so that it can be restored after without influencing other objects
painter.save(); {
// Translate, scale, and rotate...
QTransform t;
t.scale(1.0/scale, 1.0/scale);
t.translate(x - view.x()*scale, view.height()*scale - y + view.y()*scale);
painter.setTransform(t);
for(int index = 0; index < transformationCount; index++) {
long arrowLength = 1000*scale;
long ballSize = 20*scale;
Vector2D a = transformation[index].trans();
Vector2D b = (transformation[index] * Trafo2D::trans(0, arrowLength)).trans();
painter.setPen(transformationColors[index]);
QPen pen = painter.pen();
pen.setWidth(2*scale);
painter.setPen(pen);
painter.drawLine(a.x(), -a.y(), b.x(), -b.y());
painter.setBrush(QBrush(transformationColors[index]));
painter.drawEllipse(a.x()-ballSize/2, -(a.y()+ballSize/2), ballSize, ballSize);
}
} painter.restore();
}
示例3: update
void BounceSystem::update() {
for (size_t i = 0; i < entityList.size(); i++) {
BaseEntity* current = entityList[i];
DimensionComponent *dim = (DimensionComponent*) current->getComponent("dimension");
SDL_Rect *rect = dim->getRect();
Vector2D *position = dim->getPosition();
int centerx = position->x() + (rect->w / 2);
int centery = position->y() + (rect->h / 2);
if (centerx >= mWidth) {
position->x() = 1.f;
}
if (centerx < 0) {
position->x() = mWidth - rect->w - 1;
}
if (centery >= mHeight) {
position->y() = 1.f;
}
if (centery < 0) {
position->y() = mHeight - 1.f;
}
}
}
示例4: getAngleForSplineAlignment
// Returns the rough angle in degrees the robot needs to turn in order to
// be properly aligned with the spline...
double SplineNavigation::getAngleForSplineAlignment() {
// Get two points, a and b, where a is the origin and b is very close to the origin node.
// The slope of the two will give us the angle
Vector2D a = Vector2D(navSplineX->getValue(0, 0.0), navSplineY->getValue(0, 0.0));
Vector2D b = Vector2D(navSplineX->getValue(0, 0.1), navSplineY->getValue(0, 0.1));
double angle = -Deg(std::atan2(b.x() - a.x(), b.y() - a.y()));
return angle;
}
示例5: draw
void VectorTest::draw(){
Vector2D u = t * Vector2D(0,0);
Vector2D v = t * Vector2D(1,0);
Vector2D w = t * Vector2D(0,1);
graph->draw(u.x(), u.y(), v.x(), v.y(), w.x(), w.y(), sliderScale->value());
}
示例6: computeBoundingBox
void RTreeLeaf::computeBoundingBox()
{
float lc_x = point.x();
float lc_y = point.y();
float hc_x = point.x();
float hc_y = point.y();
bounding_box = Rectangle(Vector2D(lc_x, lc_y), Vector2D(hc_x, hc_y));
bounding_box.ensureMinSideLength(MIN_BB_SIDE_LENGTH);
}
示例7: isPointOutside
bool StructureMap::isPointOutside(Vector2D p){
// If the StructureMap isn't finish, no Point can be calculated
if (!finish) return false;
// Init variables
double x1, x2;
int crossings = 0;
double eps = 0.000001;
// Check each line
for(int i = 0; i < collisions.count(); i++){
// Make sure that it doesn't depend on the direction left to right or right to left.
if ( collisions.at(i).x() < collisions.at( (i+1) % collisions.count() ).x() ){
x1 = collisions.at(i).x();
x2 = collisions.at( (i+1) % collisions.count() ).x();
}
else {
x1 = collisions.at( (i+1) % collisions.count() ).x();
x2 = collisions.at(i).x();
}
// Check if a line is in the range of the checking Point
if (p.x() > x1 && p.x() <= x2 && ( p.y() < collisions.at(i).y() || p.y() < collisions.at( (i+1)%collisions.count() ).y() )){
double dx = collisions.at( (i+1)%collisions.count() ).x() - collisions.at(i).x();
double dy = collisions.at( (i+1)%collisions.count() ).y() - collisions.at(i).y();
double k = 0;
if ( std::abs(dx) < eps ){
k = INT_MAX;
}
else {
k = dy/dx;
}
double m = collisions.at(i).y() - (k * collisions.at(i).x());
double y2 = k * p.x() + m;
if (p.y() <= y2){
crossings++;
}
}
}
if (crossings %2 == 1){
// Point p is inside the polygon
return false;
}
return true;
}
示例8: shrink
Polyangle Polyangle::shrink(const double l) const
{
int length = lesPoints.size();
QVector<Vector2D> newPoints;
newPoints.resize(length);
for(int cpt = 0; cpt <length ; cpt++)
{
Vector2D a = lesPoints.at((cpt-1+length)%length);
Vector2D b = lesPoints.at((cpt));
Vector2D c = lesPoints.at((cpt+1)%length);
Vector2D ab = b-a;
Vector2D bc = c-b;
Vector2D ca = c-a;
//calcul des vecteurs orthogonaux
Vector2D orthoAB = Vector2D(-ab.y(), ab.x());
Vector2D orthoBC = Vector2D(-bc.y(), bc.x());
//on l'inverse si il est dans le mauvais sens
if(orthoAB*bc < 0)
{
orthoAB = -orthoAB;
}
if(orthoBC*ca > 0)
{
orthoBC = -orthoBC;
}
orthoAB.normalize();
orthoBC.normalize();
//création des droites afin de récupérer le point d'intersection
Vector2D aPrime = a + orthoAB * l;
Vector2D bPrime = b + orthoAB * l;
Vector2D cPrime;
Droite aPrimeBPrime(aPrime, bPrime - aPrime);
bPrime = b + orthoBC * l;
cPrime = c + orthoBC * l;
Droite bPrimeCPrime(bPrime, cPrime - bPrime);
aPrimeBPrime.getIntersection(bPrimeCPrime, aPrime);
newPoints[cpt] = aPrime;
}
return Polyangle(newPoints);
}
示例9: cpBodySetPos
void
Flatland::Body::x( double value )
{
Vector2D tmp = position();
tmp.x( value );
return cpBodySetPos( _body, tmp );
}
示例10: process
void JoystickNavigationTask::process() {
if(!navigation) return;
Vector2D wheelSpeed = navigation->getWheelSpeed(0,0);
create->controller->setWheelSpeed((short)wheelSpeed.x(), (short)wheelSpeed.y());
}
示例11: norm
Vector3D Terrain::norm(const Vector2D &p) const
{
Vector2D px(p.x()+epsilon,p.y());
Vector2D pxminus(p.x()-epsilon, p.y());
Vector2D py(p.x(),p.y()+epsilon);
Vector2D pyminus(p.x(),p.y()-epsilon);
double hpx=getHauteur(px);
double hpxminus = getHauteur(pxminus);
double hpy=getHauteur(py);
double hpyminus = getHauteur(pyminus);
Vector3D resu(-(hpx-hpxminus),2*epsilon,-(hpy-hpyminus));
resu.normalize();
return resu;
}
示例12: printScreen
QImage Camera::printScreen(Terrain &t,const Vector2D& a, const Vector2D& b, const Vector3D& s, int l, int h)
{
QImage im(l,h,QImage::Format_ARGB32);
double min=t.getHauteurMin(a,b);
double max=t.getHauteurMax(a,b);
Vector3D aBox(a.x(),min,a.y());
Vector3D bBox(b.x(),max*1.5,b.y());
for(int i=0; i<l; ++i) {
for(int j=0; j<h; ++j) {
im.setPixel(i,h-1-j,ptScreen(t,aBox,bBox,s,i,j,l,h));
}
}
return im;
}
示例13: processAddNavPoint
void SplineNavigation::processAddNavPoint(Vector2D point) {
Navigation::processAddNavPoint(point);
// Append points to our spline datastructures
navSplineX->addNode(point.x());
navSplineY->addNode(point.y());
// Calculate points for wheel splines...
calculateLeftRightWheelSpline();
}
示例14: norm
Vector3D Terrain::norm(const Vector2D &p)
{
/* Vector2D px(p.x()+epsilon,p.y());
Vector2D py(p.x(),p.y()+epsilon);
double hp=getHauteur(p);
double hpx=getHauteur(px);
double hpy=getHauteur(py);
Vector3D vp(p.x(),p.y(),(double)hp);
Vector3D vpx(px.x(),px.y(),(double)hpx);
Vector3D vpy(py.x(),py.y(),(double)hpy);
Vector3D u=vpx-vp;
Vector3D v=vpy-vp;
Vector3D n(-u.z()/u.x(),1.0f,-v.z()/v.y());
n.normalize();
return n;*/
//std::cout<<p.x()<<" "<<p.x()+epsilon<<std::endl;
Vector2D px(p.x()+epsilon,p.y());
Vector2D pxminus(p.x()-epsilon, p.y());
Vector2D py(p.x(),p.y()+epsilon);
Vector2D pyminus(p.x(),p.y()-epsilon);
double hpx=getHauteur(px);
double hpxminus = getHauteur(pxminus);
double hpy=getHauteur(py);
double hpyminus = getHauteur(pyminus);
//std::cout<<hpx<<" "<<hpxminus<<std::endl;
Vector3D resu(-(hpx-hpxminus),2*epsilon,-(hpy-hpyminus));
resu.normalize();
return resu;
}
示例15: ensureMinSideLength
void Rectangle::ensureMinSideLength(float min_side_length)
{
float lc_x = low_corner.x();
float lc_y = low_corner.y();
float hc_x = high_corner.x();
float hc_y = high_corner.y();
float diff_x = hc_x - lc_x;
if (diff_x < min_side_length)
{
hc_x += 0.5f * (min_side_length - diff_x);
lc_x -= 0.5f * (min_side_length - diff_x);
}
float diff_y = hc_y - lc_y;
if (diff_y < min_side_length)
{
hc_y += 0.5f * (min_side_length - diff_y);
lc_y -= 0.5f * (min_side_length - diff_y);
}
low_corner = Vector2D(lc_x, lc_y);
high_corner = Vector2D(hc_x, hc_y);
}