本文整理汇总了C++中setX函数的典型用法代码示例。如果您正苦于以下问题:C++ setX函数的具体用法?C++ setX怎么用?C++ setX使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setX函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: planRoute
void TREnemy::moveAlongPath(){
planRoute(false);
if(path.empty()){
return;
}
int topX = path.front().first;
int topY = path.front().second;
int curX = getX();
int curY = getY();
if(!undoed && curX != topX){
if(std::abs(curX - topX) < vel){
if(curX > topX){
setDirection(TRDirectionLeft);
curX = topX;
}else{
setDirection(TRDirectionRight);
curX = topX;
}
}else{
if (curX > topX) {
setDirection(TRDirectionLeft);
curX -= vel;
}else{
setDirection(TRDirectionRight);
curX += vel;
}
}
if(curX == topX && curY == topY){
path.pop();
}
setX(curX);
return;
}
if(curY != topY){
undoed = false;
if(std::abs(curY - topY) < vel){
if(curY > topY){
setDirection(TRDirectionUp);
curY = topY;
}else{
setDirection(TRDirectionDown);
curY = topY;
}
}else{
if (curY > topY) {
setDirection(TRDirectionUp);
curY -= vel;
}else{
setDirection(TRDirectionDown);
curY += vel;
}
}
if(curX == topX && curY == topY){
path.pop();
}
setY(curY);
return;
}
if(curX == topX && curY == topY){
path.pop();
}
return;
}
示例2: setX
void Coordinate::operator+=(const Coordinate& coord)
{
setX(_x + coord.x());
setY(_y + coord.y());
}
示例3: QSizeF
//.........这里部分代码省略.........
_maxSubW = 0.0;
_maxSubH = setting->rubyFontSize();
QList<HelperKaraokeLabel*> subList;
for (int i = 0; i < rubyCount; i++)
{
HelperKaraokeLabel* sub = new HelperKaraokeLabel(this);
sub->_isRuby = true;
sub->setRubyHidden(_isRubyHidden);
subList.append(sub);
sub->setText(ruby[i].ruby());
sub->_textColor = _textColor;
sub->_strokeColor = _strokeColor;
// set font
QFont f;
f.setFamily(setting->fontName());
f.setWeight(99);
f.setPixelSize(setting->rubyFontSize());
f.setLetterSpacing(QFont::SpacingType::AbsoluteSpacing, 1);
sub->setFont(f);
QSizeF subsize = sub->minimumSizeHint();
if (_maxSubW < subsize.width())
{
_maxSubW = subsize.width();
}
// should be even!!
/*
if (_maxSubH < subsize.height())
{
_maxSubH = subsize.height();
}*/
}
// rearrange size
_maxSubH += 1.0; // shadow
// /--/ // _rubyOffset > 0
// /<--->/ // _maxSubW
// |--|a|----|b|----|c|--|
// AAAAAAAAAAAAAAAAA
//
// |a|b|c|
// ---A---
// /--/ // _rubyOffset < 0
size.setHeight(size.height() + _maxSubH + setting->rubyVSpace());
if (rubyCount > 0)
{
qreal subTotalW = _maxSubW*rubyCount;
qreal oWidth = size.width();
if (oWidth < subTotalW)
{
size.setWidth(_maxSubW*rubyCount);
_rubyOffset = (oWidth - subTotalW) / 2.0;
}
else
{
auto oMaxSubW = _maxSubW;
/*
_maxSubW = ((qreal)(oWidth)) / rubyCount;
_rubyOffset = oMaxSubW/2;
*/
_rubyOffset = (oWidth - rubyCount*oMaxSubW) / rubyCount / 2.0;
_maxSubW = oMaxSubW + _rubyOffset * 2.0;
}
for (int i = 0; i < rubyCount; i++)
{
subList[i]->setFixedSize(QSize(_maxSubW, _maxSubH+setting->rubyVSpace()));
subList[i]->_maxSubW = _maxSubW;
subList[i]->_maxSubH = _maxSubH;
auto geo = subList[i]->geometry();
geo.setX(geo.x() + i*_maxSubW + (_rubyOffset>0 ? _rubyOffset : 0));
subList[i]->setGeometry(geo);
}
/*
auto geo = this->geometry();
geo.setY(maxSubH + subSpaceH);
this->setGeometry(geo);
*/
}
setFixedSize(size.toSize());
// render to image
pimage = new QImage(size.toSize(), QImage::Format_ARGB32);
QPainter painter(pimage);
pimage->fill(qRgba(0, 0, 0, 0));
render(&painter, QPoint(), QRegion(), QWidget::DrawChildren);
// assign return value
*ppimage = pimage;
return size;
}
示例4: swap
void OpticalFlowTransitionModel::predict(vector<Sample>& samples, const Mat& image, const optional<Sample>& target) {
points.clear();
forwardPoints.clear();
backwardPoints.clear();
forwardStatus.clear();
error.clear();
squaredDistances.clear();
correctFlowCount = 0;
// build pyramid of the current image
cv::buildOpticalFlowPyramid(makeGrayscale(image), currentPyramid, windowSize, maxLevel, true, BORDER_REPLICATE, BORDER_REPLICATE);
if (previousPyramid.empty() || !target) { // optical flow cannot be computed if there is no previous pyramid or no current target
swap(previousPyramid, currentPyramid);
return fallback->predict(samples, image, target);
}
// compute grid of points at target location
for (auto point = templatePoints.begin(); point != templatePoints.end(); ++point)
points.push_back(Point2f(target->getWidth() * point->x + target->getX(), target->getHeight() * point->y + target->getY()));
// compute forward and backward optical flow
cv::calcOpticalFlowPyrLK(previousPyramid, currentPyramid, points, forwardPoints, forwardStatus, error, windowSize, maxLevel);
cv::calcOpticalFlowPyrLK(currentPyramid, previousPyramid, forwardPoints, backwardPoints, backwardStatus, error, windowSize, maxLevel);
swap(previousPyramid, currentPyramid);
// compute flow and forward-backward-error
vector<Point2f> flows;
flows.reserve(points.size());
squaredDistances.reserve(points.size());
for (unsigned int i = 0; i < points.size(); ++i) {
flows.push_back(forwardPoints[i] - points[i]);
if (forwardStatus[i] && backwardStatus[i]) {
Point2f difference = backwardPoints[i] - points[i];
squaredDistances.push_back(make_pair(difference.dot(difference), i));
}
}
if (squaredDistances.size() < points.size() / 2) // the flow for more than half of the points could not be computed
return fallback->predict(samples, image, target);
// find the flows with the least forward-backward-error (not more than 1 pixel)
float maxError = 1 * 0.5f;
vector<float> xs, ys;
sort(squaredDistances.begin(), squaredDistances.end(), [](pair<float, int> lhs, pair<float, int> rhs) { return lhs.first < rhs.first; });
xs.reserve(squaredDistances.size());
ys.reserve(squaredDistances.size());
for (correctFlowCount = 0; correctFlowCount < squaredDistances.size(); ++correctFlowCount) {
if (squaredDistances[correctFlowCount].first > maxError)
break;
int index = squaredDistances[correctFlowCount].second;
xs.push_back(flows[index].x);
ys.push_back(flows[index].y);
}
if (correctFlowCount < points.size() / 2) // to little correct correspondences
return fallback->predict(samples, image, target);
// compute median flow (only change in position for now)
sort(xs.begin(), xs.end());
sort(ys.begin(), ys.end());
float medianX = xs[xs.size() / 2];
float medianY = ys[ys.size() / 2];
Point2f medianFlow(medianX, medianY);
// compute ratios of point distances in previous and current image
vector<float> squaredRatios;
squaredRatios.reserve(correctFlowCount * (correctFlowCount - 1) / 2);
for (unsigned int i = 0; i < correctFlowCount; ++i) {
for (unsigned int j = i + 1; j < correctFlowCount; ++j) {
Point2f point1 = points[squaredDistances[i].second];
Point2f forwardPoint1 = forwardPoints[squaredDistances[i].second];
Point2f point2 = points[squaredDistances[j].second];
Point2f forwardPoint2 = forwardPoints[squaredDistances[j].second];
Point2f differenceBefore = point1 - point2;
Point2f differenceAfter = forwardPoint1 - forwardPoint2;
float squaredDistanceBefore = differenceBefore.dot(differenceBefore);
float squaredDistanceAfter = differenceAfter.dot(differenceAfter);
squaredRatios.push_back(squaredDistanceAfter / squaredDistanceBefore);
}
}
// compute median ratio to complete the median flow
sort(squaredRatios.begin(), squaredRatios.end());
float medianRatio = sqrt(squaredRatios[squaredRatios.size() / 2]);
// predict samples according to median flow and random noise
for (auto sample = samples.begin(); sample != samples.end(); ++sample) {
int oldX = sample->getX();
int oldY = sample->getY();
float oldSize = sample->getSize();
// change position according to median flow
double newX = oldX + medianX;
double newY = oldY + medianY;
double newSize = oldSize * medianRatio;
// add noise to position
double positionDeviation = scatter * sample->getSize();
newX += positionDeviation * generator();
newY += positionDeviation * generator();
newSize *= pow(2, scatter * generator());
// round to integer
sample->setX((int)(newX + 0.5));
sample->setY((int)(newY + 0.5));
sample->setSize((int)(newSize + 0.5));
//.........这里部分代码省略.........
示例5: Hexagon
HexagonGrid::HexagonGrid()
{
// Creating 200x200 hexagonal map
unsigned int index = 0;
for (unsigned int q = 0; q != 200; ++q)
{
for (unsigned int p = 0; p != 200; ++p, ++index)
{
auto hexagon = new Hexagon(index);
int x = 48*100 + 16*(q+1) - 24*p;
int y = (q+1)*12 + 6*p + 12;
if (p&1)
{
x -= 8;
y -= 6;
}
hexagon->setCubeX(q - (p + (p&1))/2);
hexagon->setCubeZ(p);
hexagon->setCubeY(-hexagon->cubeX() - hexagon->cubeZ());
hexagon->setX(x);
hexagon->setY(y);
_hexagons.push_back(hexagon);
}
}
// Creating links between hexagons
for (index = 0; index != 200*200; ++index)
{
auto hexagon = _hexagons.at(index);
unsigned int q = index/200; // hexagonal y
unsigned int p = index%200; // hexagonal x
unsigned index1 = (q + 1)*200 + p;
unsigned index4 = (q-1)*200 + p;
unsigned int index2, index3, index5, index6;
if (index&1)
{
index2 = q*200 + p-1;
index3 = (q-1)*200 + p-1;
index5 = (q-1)*200 + p+1;
index6 = q*200 + p+1;
}
else
{
index2 = (q+1)*200 + p-1;
index3 = q*200 + p-1;
index5 = q*200 + p+1;
index6 = (q+1)*200 + p+1;
}
if (index1 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index1));
if (index2 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index2));
if (index3 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index3));
if (index4 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index4));
if (index5 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index5));
if (index6 < _hexagons.size()) hexagon->neighbors()->push_back(_hexagons.at(index6));
}
}
示例6: setPosition
void BossLaser::setMissedPosition()
{
setPosition(VECTOR2(GAME_WIDTH/2, GAME_HEIGHT/5));
setX(Entity::getPositionX());
setY(Entity::getPositionY());
}
示例7: setX
Point::Point()
{
setX(0.0);
setY(0.0);
setY(0.0);
}
示例8: Location
Location(unsigned long int _size, T _x, T _y) : size(_size) {
setX(_x);
setY(_y);
}
示例9: setX
void Entity::setPosition(float x, float y)
{
setX(x);
setY(y);
}
示例10: Surface
//.........这里部分代码省略.........
// Sum of all character lengths in the current line.
int linePixels = 0;
for (auto &c : line)
{
linePixels += islower(c) ? lowerCharWidth : upperCharWidth;
}
// Check against the current longest line.
if (linePixels > longestLength)
{
longestLength = linePixels;
}
}
// In pixels.
return longestLength;
}(this->textLines, upperCharWidth, lowerCharWidth);
const int newHeight = static_cast<int>(this->textLines.size()) * upperCharHeight;
// Resize the surface with the proper dimensions for fitting all the text.
SDL_FreeSurface(this->surface);
this->surface = [](int width, int height, int colorBits)
{
return SDL_CreateRGBSurface(0, width, height, colorBits, 0, 0, 0, 0);
}(newWidth, newHeight, Surface::DEFAULT_BPP);
// Make this surface transparent.
this->setTransparentColor(Color::Transparent);
this->fill(Color::Transparent);
// Blit each character surface in at the right spot.
auto point = Int2();
auto fontSurface = textureManager.getSurface(font.getFontTextureName());
int upperCharOffsetWidth = font.getUpperCharacterOffsetWidth();
int upperCharOffsetHeight = font.getUpperCharacterOffsetHeight();
int lowerCharOffsetWidth = font.getLowerCharacterOffsetWidth();
int lowerCharOffsetHeight = font.getLowerCharacterOffsetHeight();
for (auto &line : this->textLines)
{
for (auto &c : line)
{
int width = islower(c) ? lowerCharWidth : upperCharWidth;
int height = islower(c) ? lowerCharHeight : upperCharHeight;
auto letterSurface = [&]()
{
auto cellPosition = Font::getCharacterCell(c);
int offsetWidth = islower(c) ? lowerCharOffsetWidth : upperCharOffsetWidth;
int offsetHeight = islower(c) ? lowerCharOffsetHeight : upperCharOffsetHeight;
// Make a copy surface of the font character.
auto pixelPosition = Int2(
cellPosition.getX() * (width + offsetWidth),
cellPosition.getY() * (height + offsetHeight));
auto clipRect = Rectangle(pixelPosition.getX(), pixelPosition.getY(),
width, height);
auto surface = Surface(width, height);
fontSurface.blit(surface, Int2(), clipRect);
return surface;
}();
// Set the letter surface to have transparency.
letterSurface.setTransparentColor(Color::Magenta);
// Set the letter colors to the desired color.
auto letterPixels = static_cast<unsigned int*>(letterSurface.getSurface()->pixels);
auto mappedColor = SDL_MapRGBA(letterSurface.getSurface()->format,
textColor.getR(), textColor.getG(), textColor.getB(), textColor.getA());
int area = letterSurface.getWidth() * letterSurface.getHeight();
for (int i = 0; i < area; ++i)
{
auto pixel = &letterPixels[i];
// If transparent, then color it? I dunno, but it works.
if ((*pixel) == 0)
{
*pixel = mappedColor;
}
}
// Draw the letter onto this texture.
letterSurface.blit(*this, point);
// Move drawing position to the right of the current character.
point.setX(point.getX() + width);
}
// Move drawing point back to the left and down by one capital character size.
point.setX(0);
point.setY(point.getY() + upperCharHeight);
}
assert(this->surface->w > 1);
assert(this->surface->h > 1);
assert(this->textLines.size() > 0);
assert(this->fontName == fontName);
}
示例11: setX
void EllipseObject::setObjectCenterX(qreal centerX)
{
setX(centerX);
}
示例12: setX
void VESPERSEXAFSScanConfiguration::setPosition(QPair<double, double> pos)
{
setX(pos.first);
setY(pos.second);
}
示例13: setX
void Point::set(std::shared_ptr<Point> data)
{
setX (data->getX());
setY (data->getY());
}
示例14: setX
void Transform::subToX(int x)
{
setX(getX()-x);
}
示例15: setX
void Dynamite::onTick()
{
setX(getX()-speed);
setY(getY()+rand()%21-10);
}