Пример #1
2
void Player::setPlayerCord(int xI, int yI, int lengthTile, double xCord, double zCord)
{
    playerX = xI;
    playerY = yI;
    startPlayerX = playerX;
    startPlayerY = playerY;
    Ogre::Vector3 newPos(xCord + (yI * lengthTile), position.y + (length()/2), zCord+ (xI * lengthTile));
    position = newPos;
    endPos = position;
    this->create();
    rootNode->setPosition(newPos);
}
Пример #2
0
//==============================================================================
// This timer periodically checks whether any of the filter's parameters have changed...
void FilterAudioProcessorEditor::timerCallback()
{
	FilterAudioProcessor* ourProcessor = getProcessor();

	AudioPlayHead::CurrentPositionInfo newPos(ourProcessor->lastPosInfo);

	//if (lastDisplayedPosition != newPos)
		//displayPositionInfo(newPos);

	gainSlider.setValue(ourProcessor->gain, dontSendNotification);
	delaySlider.setValue(ourProcessor->delay, dontSendNotification);
}
Пример #3
0
void kingStep(std::queue<Coor> &kill, std::queue<Coor> &wave, Mat board, Coor &start, Coor &shift)
{
	Coor newPos(start.ln + shift.ln, start.col + shift.col);
	if (board[newPos.ln][newPos.col] > -4 && board[newPos.ln][newPos.col] <= 0)
	{
		if (board[newPos.ln][newPos.col] == 0)
			wave.push(newPos);
		else
			kill.push(newPos);
		board[newPos.ln][newPos.col] = board[start.ln][start.col] + 1;
	}
}
Пример #4
0
void UpdateCursorOverlay()
{
  if (mouse_cursor_overlay != NULL && mouse_scares == 0) {
    gfx::Point newPos(m_x[0]-mouse_cursor->getFocus().x,
                      m_y[0]-mouse_cursor->getFocus().y);

    if (newPos != mouse_cursor_overlay->getPosition()) {
      mouse_cursor_overlay->moveOverlay(newPos);
      dirty_display_flag = true;
    }
  }
}
Пример #5
0
void UIYabause::leaveEvent( QEvent* e )
{
	if (emulateMouse && mouseCaptured)
	{
		// lock cursor to center
		int midX = geometry().x()+(width()/2); // widget global x
		int midY = geometry().y()+menubar->height()+toolBar->height()+(height()/2); // widget global y

		QPoint newPos(midX, midY);
		this->cursor().setPos(newPos);
	}
}
Пример #6
0
void Screen::flushImage(ImageFrame *frame, const Common::Point &pt, Common::Rect &newBounds, int scaleVal) {
	Common::Point newPos(newBounds.left, newBounds.top);
	Common::Point newSize(newBounds.width(), newBounds.height());

	if (scaleVal == SCALE_THRESHOLD)
		flushImage(frame, pt, &newPos.x, &newPos.y, &newSize.x, &newSize.y);
	else
		flushScaleImage(frame, pt, &newPos.x, &newPos.y, &newSize.x, &newSize.y, scaleVal);

	// Transfer the pos and size amounts into a single bounds rect
	newBounds = Common::Rect(newPos.x, newPos.y, newPos.x + newSize.x, newPos.y + newSize.y);
}
Пример #7
0
void KeywordItem::execute(KTextEditor::View* view, const KTextEditor::Range& word)
{
    KTextEditor::Document *document = view->document();
    if ( !m_replacement.isEmpty() ) {
        QString replacement = m_replacement;
        replacement = replacement.replace('\n', '\n' + getIndendation(document->line(word.start().line())));
        replacement = replacement.replace(QLatin1String("%INDENT%"), indentString(document));

        int cursorPos = replacement.indexOf(QStringLiteral("%CURSOR%"));
        int selectionEnd = -1;
        if ( cursorPos != -1 ) {
            replacement.remove(QStringLiteral("%CURSOR%"));
        } else {
            cursorPos = replacement.indexOf(QStringLiteral("%SELECT%"));
            if ( cursorPos != -1 ) {
                replacement.remove(QStringLiteral("%SELECT%"));
                selectionEnd = replacement.indexOf(QStringLiteral("%ENDSELECT%"), cursorPos + 1);
                if ( selectionEnd == -1 ) {
                    selectionEnd = replacement.length();
                }
                replacement.remove(QStringLiteral("%ENDSELECT%"));
            }
        }

        document->replaceText(word, replacement);

        if ( cursorPos != -1 ) {
            if (view) {
                replacement = replacement.left(cursorPos);
                KTextEditor::Cursor newPos(
                    word.start().line() + replacement.count('\n'),
                    word.start().column() + replacement.length() - replacement.lastIndexOf('\n') - 1
                );
                view->setCursorPosition(newPos);
                if ( selectionEnd != -1 ) {
                    ///TODO: maybe we want to support multi-line selections in the future?
                    view->setSelection(
                        KTextEditor::Range(
                            newPos,
                            KTextEditor::Cursor(
                                newPos.line(),
                                newPos.column() + selectionEnd - cursorPos
                            )
                        )
                    );
                }
            }
        }
    } else {
        document->replaceText(word, m_keyword + ' ');
    }
}
Пример #8
0
Файл: map.cpp Проект: Ra8/RAP
void Map::centerMap(){
    Person* person;
    if(role==0) // police
        person=robber;
    else
        person=polices[role-1];
        

    QPointF realPos=person->scenePos();
    QPointF center(650/2,650/2);
    QPointF newPos(pos()+(center-realPos));
    setPos(newPos);
}
Пример #9
0
void FloorLocator::snapToFloor ( void )
{
	if(!isAttached()) return;

	float floorHeight = getFloorTri().getHeightAt(m_position.x,m_position.z);

	float newOffset = m_offset + m_position.y - floorHeight;

	Vector newPos(m_position.x,floorHeight,m_position.z);

	setPosition_l(newPos);
	setOffset(newOffset);
}
Пример #10
0
    void MapUpdateVisitor::visitGroup(GroupElement* e) {
        gmtl::Vec2f newPos(e->pos);

        if (_property == "x") {
            newPos[0] = atof(_newValue.c_str());
        } else if (_property == "y") {
            newPos[1] = atof(_newValue.c_str());
        }

        Editor::getMainFrame()->handleCommand(
            new UpdateMapElementCommand(e, newPos)
            );
    }
Пример #11
0
void QmlWebViewWidget::updateGeometry()
{
    QPointF newPos(0, 0);
    newPos = mapToItem(0, newPos);
    qDebug() << "QmlWebViewWidget::updateGeometry, top left mapped to window: " << newPos;

    if(this->window()){
    newPos += this->window()->position();
    qDebug() << "QmlWebViewWidget::updateGeometry, top left mapped to screen: " << newPos;
    }
    QRectF absRect(newPos, contentsBoundingRect().size());
    m_widget->setGeometry(absRect.toRect());
}
Пример #12
0
//==============================================================================
// This timer periodically checks whether any of the filter's parameters have changed...
void PlugTestAudioProcessorEditor::timerCallback()
{
	PlugTestAudioProcessor* ourProcessor = getProcessor();

	AudioPlayHead::CurrentPositionInfo newPos(ourProcessor->lastPosInfo);

	if (lastDisplayedPosition != newPos)
		displayPositionInfo(newPos);

	gainSlider.setValue(ourProcessor->gain, dontSendNotification);
	freqSlider.setValue(ourProcessor->freq, dontSendNotification);
	distortionSlider.setValue(ourProcessor->distortion, dontSendNotification);
}
Пример #13
0
void Projectile::onSnap(const NetProjectileSnapshot &netshot) {
  NetProjectileSnapshot snapshot;
  snapshot.x = ntohs(netshot.x);
  snapshot.y = ntohs(netshot.y);

  //const vec2 lastPos = position;
  vec2 newPos(snapshot.x, snapshot.y);
  //if (length(newPos - position) >= 2.0) {
    position = newPos;
    //}

  velocity = vec2::FromDegrees(ntohs(netshot.dir) - 180.0) * 1000.0;
}
Пример #14
0
bool ChessPiece::isOpponentPieceEnPassant(const int boardPos) const
{
    Q_ASSERT(!m_parentPlayer.isNull());

    auto opponentPlayer(m_parentPlayer.toStrongRef()->opponentPlayer());
    Q_ASSERT(!opponentPlayer.isNull());

    if (opponentPlayer->lastMove())
    {
        auto oppMove = opponentPlayer->lastMove();
        if (oppMove->moveStates() & ChessTypes::MoveEnPassant &&
                oppMove->newPos().col() == ChessPos::col(boardPos))
        {
            const int boardMiddlePos = (oppMove->oldPos() + oppMove->newPos()) / 2;
            if (boardMiddlePos == boardPos &&
                    opponentPlayer->chessPieceAt(oppMove->newPos()))
                return true;
        }
    }

    return false;
}
Пример #15
0
void PlayerCameraOgre::adjustDistance()
{
	const mp::Vector3f &playerPos = mPlayer->model()->getPosition();
	mp::Vector3f pivotPoint(playerPos.getX(), playerPos.getY() + mPivotHeight, playerPos.getZ());
	mp::Vector3f pivotToPos = mRealPosition - pivotPoint;
	pivotToPos.normalize();

	mp::Vector3f newPos(pivotPoint + pivotToPos * mCameraDistance);
	mRealPosition = newPos;
	if (newPos.getY() <= 0)
		newPos.y() = 0.01f;
	setPosition(newPos);
}
void PhysicsObject::attachObject(boost::shared_ptr<PhysicsObject> po,
                                 const v3& position,
                                 const qv4& orientation)
{
	po->mBodyOffset = position;

	GeomMapT::const_iterator it = po->mGeometry.begin();
	for (; it != po->mGeometry.end(); ++it)
	{
		// Calculate new relative position
		dGeomID geom = it->second.geomId;
		const dReal* offset = dGeomGetOffsetPosition(geom);
		
		v3 newPos(offset);
		newPos += position;

		// Attach
		dGeomSetBody(geom, mOdeBody);
		dGeomSetOffsetPosition(geom, newPos.x, newPos.y, newPos.z);
		dSpaceRemove(po->mSpaceId, geom);
		dSpaceAdd(mSpaceId, geom);
	}
	
	// add the two masses
	dMass otherMass; 
	dBodyGetMass(po->mOdeBody, &otherMass);

// 	dbglog << "OtherMass: " << otherMass.mass;
// 	dbglog << "OtherCenter: " << odeVectorOut(otherMass.c);
// 	dbglog << "OtherInertia: " << odeMatrixOut(otherMass.I);

	dBodyGetMass(mOdeBody, &mOriginalMass);

// 	dbglog << "OwnMass: " << mOriginalMass.mass;
// 	dbglog << "OwnCenter: " << odeVectorOut(mOriginalMass.c);
// 	dbglog << "OwnInertia: " << odeMatrixOut(mOriginalMass.I);

	dMassAdd(&mOriginalMass, &otherMass);

	dMassTranslate(&mOriginalMass, -mOriginalMass.c[0], -mOriginalMass.c[1], -mOriginalMass.c[2]);
	dBodySetMass(mOdeBody, &mOriginalMass);

// 	dbglog << "NewMass: " << mOriginalMass.mass;
// 	dbglog << "NewCenter: " << odeVectorOut(mOriginalMass.c);
// 	dbglog << "NewInertia: " << odeMatrixOut(mOriginalMass.I);

	// Disable old body
	dBodyDisable(po->mOdeBody);
	
	notifyControlAboutChangeInMass();
}
Пример #17
0
	void SoundRipple::update(float p_fDeltaTime)
	{
		if (!m_bIsUpdating)
			return;

		m_fCurrentDuration += p_fDeltaTime;

		float fMinMaxRadDelta = m_fMaxRadious - m_fMinRadious;

		float fCurrentDurationDiff = m_fCurrentDuration / m_fMaxDuration;

		float fCurrentRadDiff = fMinMaxRadDelta * fCurrentDurationDiff;

		m_fCurrentRadious = fCurrentRadDiff + m_fMinRadious;

		sf::Vector2f newPos(m_v2fOriginPosition - sf::Vector2f(m_fCurrentRadious, m_fCurrentRadious));

		delete m_v2fCurrentPos;

		m_v2fCurrentPos = new sf::Vector2f(newPos);

		if (m_fCurrentDuration > m_fMaxDuration || m_fCurrentRadious > m_fMaxRadious)
			destroy();

		setSize(sf::Vector2f(m_fCurrentRadious * 2, m_fCurrentRadious * 2));

		setOrigin(sf::Vector2f(m_fCurrentRadious, m_fCurrentRadious));

		delete m_xRipple;
		m_xRipple = nullptr;

		m_xRipple = new sf::CircleShape;

		m_xRipple->setRadius(m_fCurrentRadious);
		m_xRipple->setOutlineThickness(3.f);

		sf::Color fadingColor = sf::Color::Green;
		fadingColor.a = 1 - 255 * (m_fCurrentRadious) / m_fMaxRadious;

		m_xRipple->setOutlineColor(fadingColor);
		m_xRipple->setFillColor(sf::Color(0, 0, 0, 0));
		m_xRipple->setPointCount(100);

		float offset = sqrtf((m_fCurrentRadious * m_fCurrentRadious) / 2);

		m_v2fRipplePosition = sf::Vector2f(m_v2fOriginPosition - sf::Vector2f(m_fCurrentRadious, m_fCurrentRadious));

		m_xRipple->setPosition(m_v2fRipplePosition);
		
	}
Пример #18
0
void CPlayerRotation::ProcessLean()
{
	float leanAmt(0.0f);

	if(m_stats.isOnLadder)
		return;

	if(!m_stats.inZeroG || m_stats.inAir<0.1f)
	{
		if(float sLean = m_player.GetSpeedLean())
			leanAmt = std::min(1.0f, sLean * 0.05f);
		else if((m_actions & (ACTION_LEANLEFT|ACTION_LEANRIGHT)) != 0)
			leanAmt = ((m_actions & ACTION_LEANLEFT)?-1.0f:0.0f) + ((m_actions & ACTION_LEANRIGHT)?1.0f:0.0f);
		else if(fabsf(m_desiredLeanAmount) > 0.01f)
			leanAmt = m_desiredLeanAmount;
	}

	EStance stance = m_player.GetStance();

	if(stance == STANCE_PRONE)
		leanAmt *= 0.65f;

	m_leanAmount = leanAmt;

	//check if its possible
	if(m_leanAmount*m_leanAmount > 0.01f)
	{
		float noLean(0.0f);
		Vec3 headPos(m_player.GetEntity()->GetWorldPos() + m_baseQuat * m_player.GetStanceViewOffset(stance,&noLean));
		Vec3 newPos(m_player.GetEntity()->GetWorldPos() + m_baseQuat * m_player.GetStanceViewOffset(stance,&m_leanAmount));

		/*gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(headPos, 0.05f, ColorB(0,0,255,255) );
		gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(newPos, 0.05f, ColorB(0,0,255,255) );
		gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(headPos, ColorB(0,0,255,255), newPos, ColorB(0,0,255,255));*/

		ray_hit hit;
		int rayFlags(rwi_stop_at_pierceable|rwi_colltype_any);//COLLISION_RAY_PIERCABILITY & rwi_pierceability_mask);
		IPhysicalEntity *pSkip(m_player.GetEntity()->GetPhysics());

		float distMult(3.0f);

		if(gEnv->pPhysicalWorld->RayWorldIntersection(headPos + m_viewQuat.GetColumn1() * 0.25f, (newPos - headPos)*distMult, ent_terrain|ent_static|ent_rigid|ent_sleeping_rigid, rayFlags, &hit, 1, &pSkip, 1))
		{
			float dist((headPos - newPos).len2() * distMult);
			m_leanAmount *= ((hit.pt - headPos).len2() / dist) / distMult;

			//gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(hit.pt, 0.05f, ColorB(0,255,0,255) );
		}
	}
}
Пример #19
0
void UIYabause::mouseMoveEvent( QMouseEvent* e )
{ 
	int midX = geometry().x()+(width()/2); // widget global x
	int midY = geometry().y()+menubar->height()+toolBar->height()+(height()/2); // widget global y

	int x = (e->x()-(width()/2))*mouseXRatio;
	int y = ((menubar->height()+toolBar->height()+(height()/2))-e->y())*mouseYRatio;
	int minAdj = mouseSensitivity/100;

	// If minimum movement is less than x, wait until next pass to apply	
	if (abs(x) < minAdj) x = 0;
	if (abs(y) < minAdj) y = 0;

	if (mouseCaptured)
		PerAxisMove((1 << 30), x, y);

	VolatileSettings* vs = QtYabause::volatileSettings();

	if (!isFullScreen())
	{
		if (emulateMouse && mouseCaptured)
		{
			// lock cursor to center
			QPoint newPos(midX, midY);
			this->cursor().setPos(newPos);
			this->setCursor(Qt::BlankCursor);
			return;
		}
		else
			this->setCursor(Qt::ArrowCursor);
	}
	else
	{
		if (emulateMouse && mouseCaptured)
		{
			this->setCursor(Qt::BlankCursor);
			return;
		}
		else if (vs->value( "View/Menubar" ).toInt() == BD_SHOWONFSHOVER)
		{
			if (e->y() < showMenuBarHeight)
				menubar->show();
			else
				menubar->hide();
		}

		hideMouseTimer->start(3 * 1000);
		this->setCursor(Qt::ArrowCursor);
	}
}
Пример #20
0
void PathTile::create(std::string material)
{
    std::string name = patch::to_string(xIndex) + "y" + patch::to_string(yIndex);
    Ogre::MeshManager::getSingleton().create("cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    ent = mgr->createEntity(Ogre::MeshManager::getSingleton().getByName(
     "cube.mesh", 
     Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME));
    Ogre::Vector3 newPos(position.x, position.y - (length()/2), position.z);
    Ogre::SceneNode* rootNode = mgr->getRootSceneNode()->createChildSceneNode(name, newPos);
    rootNode->setScale(length()/100.0, length()/100.0, length()/100.0);
    rootNode->attachObject(ent);
    // rootNode->setScale(.6, .6, .6); 
    ent->setMaterialName(material);
}
Пример #21
0
void EditFrame::SetPos(const QPoint &pos)
{
	QWidget *pParent = parentWidget();
	if( pParent )
	{
		QWidget *pGrandParent = pParent->parentWidget();
		if( pGrandParent )
		{
			QPoint newPos(pos);
			ClipPos(newPos);
			pParent->move( newPos );
		}
	}
}
Пример #22
0
void generate_init_values(int number_of_stars, struct star* star_array)
{
  time_t t;
  srand((unsigned) time(&t));
  for(int i = 0; i < number_of_stars; ++i){
    star_array[i] = makeStar();
    prec angle = 360 * newRand();
    prec radius = 100 * newRand();
    newPos(&star_array[i],  radius * cos(angle) + 350, 0.5 * radius * sin(angle) + 350);
    newSpeed(&star_array[i], 0.4*(star_array[i].ypos - 350), (-0.4)*(star_array[i].xpos - 350));
    newMass(&star_array[i], 2*newRand() + 2);
  }

}
Пример #23
0
    void MapUpdateVisitor::visitGeometry(GeometryElement* e) {
        std::string tex(e->material ? e->material->texture : "");
        gmtl::Vec2f newPos(e->pos);

        if (_property == "x") {
            newPos[0] = atof(_newValue.c_str());
        } else if (_property == "y") {
            newPos[1] = atof(_newValue.c_str());
        } else if (_property == "Texture") {
            //tex = _newValue;
        }

        Editor::getMainFrame()->handleCommand(
            new UpdateGeometryElementCommand(e, newPos, /*tex*/ ""));
    }
Пример #24
0
static void update_position(struct star* str, prec time_unit)
{
  prec xacc = readXForce(str) / readMass(str);
  prec xSpeedIncrease = xacc * time_unit;
  prec yacc = readYForce(str) / readMass(str);
  prec ySpeedIncrease = yacc * time_unit;
  prec newXSpeed = readXSpeed(str) + xSpeedIncrease;
  prec newYSpeed = readYSpeed(str) + ySpeedIncrease;
  newSpeed(str, newXSpeed, newYSpeed);
  prec xPosIncrease = readXSpeed(str) * time_unit + yacc * pow(time_unit, 2.0)/2;
  prec yPosIncrease = readYSpeed(str) * time_unit + yacc * pow(time_unit, 2.0)/2;
  prec newXPos = readXPos(str) + xPosIncrease;
  prec newYPos = readYPos(str) + yPosIncrease;
  newPos(str, newXPos, newYPos);
}
Пример #25
0
    void Particle::update(float dt, const Vec3f& accel, const std::vector<Segment>& segs) {
        // Reduce the time to live, and if dead or not updating positions automatically return
        _lifeLeft -= dt;
        if (!isAlive()) {
            return;
        }

        // Update the position
        _oldPosition = _position;
        _position += _velocity * dt;

        // Update the velocity
        _oldVelocity = _velocity;
        _velocity += accel * dt;

        Vec2f entPos(31, 3); /// @todo HACK FOR DEMO
        Vec2f oldPos(_oldPosition[0], _oldPosition[1]);
        Vec2f newPos(_position[0],    _position[1]);
        Segment pline(oldPos + entPos, newPos + entPos);

        for (size_t i = 0; i < segs.size(); ++i) {
            const Segment& s = segs[i];
            // need the normal of this segment.
            Vec2f n = perp(s.v2 - s.v1);
            if (dot(n, Vec2f(_oldVelocity[0], _oldVelocity[1])) > 0) {
                n = -n;
            }
            normalize(n);

            Vec2f p;
            float t = intersectLine(p, pline, s);
            if (t >= 0 && t <= 1) {
                Vec2f I = pline.v2 - pline.v1;
                Vec2f R = I - 2 * dot(n, I) * n;
                Vec2f p = pline.v1 + I * t + R * (1 - t);
                Vec2f v = normal(R) * length(_velocity) * 0.5f;
                p -= entPos;

                _position[0] = p[0];
                _position[1] = p[1];
                _velocity[0] = v[0];
                _velocity[1] = v[1];
                _oldPosition = _position;
                _oldVelocity = _velocity;
                break;
            }
        }
    }
Пример #26
0
// liefert den Punkt neben dem Segment (links oder rechts, siehe 'left'), der orthogonal von
// 'p' die Entfernung 'newLen' von diesem Segment hat.
static DPoint leftOfSegment(const DLine &segment, const DPoint &p, double newLen, bool left = true)
{
	DVector v;
	if (p == segment.start())
		v = segment.end() - p;
	else
		v = p - segment.start();

	DVector newPos(v.orthogonal());
	if (!left) newPos *= -1;

	// newPos has nonzero length
	newPos = (newPos * newLen) / newPos.length();

	return p + newPos;
}
Пример #27
0
void AbstractCubester::create(std::string material)
{
    Ogre::MeshManager::getSingleton().create("cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    ent = mgr->createEntity(Ogre::MeshManager::getSingleton().getByName(
        "cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME));
    name = patch::to_string((int)(position.x)) + "enemy" + patch::to_string((int)(position.z));
    Ogre::Vector3 newPos(position.x, position.y + length()/2, position.z);
    position = newPos;
    endPos = newPos;
    rootNode = mgr->getRootSceneNode()->createChildSceneNode(name, position);
    rootNode->setScale(length()/100.0, length()/100.0, length()/100.0);
    rootNode->attachObject(ent);
    // rootNode->setScale(.6, .6, .6);
    ent->setMaterialName(material); 
    startPosition = position;
}
Пример #28
0
/**
 * Moves the point or line if active.
 */
void AssociationLine::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    UMLScene* scene = m_associationWidget->umlScene();

    QPointF oldPos = event->scenePos();
    QPointF newPos(
        scene->snappedX(oldPos.x()),
        scene->snappedY(oldPos.y())
    );

    // Prevent the moving vertex from disappearing underneath a widget
    // (else there's no way to get it back.)
    UMLWidget *onW = scene->widgetAt(newPos);
    if (onW && onW->baseType() != WidgetBase::wt_Box) {  // boxes are transparent
        const qreal pX = newPos.x();
        const qreal pY = newPos.y();
        const qreal wX = onW->x();
        const qreal wY = onW->y();
        const qreal wWidth = onW->width();
        const qreal wHeight = onW->height();
        if (pX > wX && pX < wX + wWidth) {
            const qreal midX = wX + wWidth / 2.0;
            if (pX <= midX)
                newPos.setX(wX);
            else
                newPos.setX(wX + wWidth);
        }
        if (pY > wY && pY < wY + wHeight) {
            const qreal midY = wY + wHeight / 2.0;
            if (pY <= midY)
                newPos.setY(wY);
            else
                newPos.setY(wY + wHeight);
        }
    }

    if (m_activePointIndex != -1) {
        // Move a single point (snap behaviour)
        setPoint(m_activePointIndex, newPos);
    }
    else if (m_activeSegmentIndex != -1 && !isEndSegmentIndex(m_activeSegmentIndex)) {
        // Move a segment (between two points, snap behaviour not implemented)
        QPointF delta = event->scenePos() - event->lastScenePos();
        setPoint(m_activeSegmentIndex, m_points[m_activeSegmentIndex] + delta);
        setPoint(m_activeSegmentIndex + 1, m_points[m_activeSegmentIndex + 1] + delta);
    }
}
Пример #29
0
void Chart::plotPickerSelected(const QPointF &pos) {
    double xScale = ui->chart->axisScaleDiv(QwtPlot::xBottom).range();
    double yScale = ui->chart->axisScaleDiv(QwtPlot::yLeft).range();
    double minSquareDistance = ((curve->maxYValue() - curve->minYValue()) / yScale) * ((curve->maxYValue() - curve->minYValue()) / yScale) + ((curve->maxXValue() - curve->minXValue()) / xScale) * ((curve->maxXValue() - curve->minXValue()) / xScale);
    int minIndex = -1;
    for (unsigned int i = 0; i < curve->dataSize(); i++) {
        double newSquareDistance = ((curve->data()->sample(i).y() - pos.y()) / yScale) * ((curve->data()->sample(i).y() - pos.y()) / yScale) + ((curve->data()->sample(i).x() - pos.x()) / xScale) * ((curve->data()->sample(i).x() - pos.x()) / xScale);
        if (newSquareDistance < minSquareDistance) {
            minSquareDistance = newSquareDistance;
            minIndex = i;
        }
    }
    QPointF newPos(curve->data()->sample(minIndex));
    marker->setValue(newPos);
    marker->setLabel(QwtText(QString::number(newPos.x()).append(", ").append(QString::number(newPos.y()))));
    ui->chart->replot();
}
Пример #30
0
void InfectedBunny::RefreshNewTargetPosition(float seconds)
{
	static Randomizer random;

	float distance = (m_targetPosition - m_position).GetLength();

	m_targetPositionRefreshColldown -= seconds;
	if (m_targetPositionRefreshColldown <= 0.0f || distance <= 0.4f)
	{
		m_targetPositionRefreshColldown = random.GetFloat(
			GameProps::RefreshNewTargetPositionFrom,
			GameProps::RefreshNewTargetPositionTo);

		sm::Vec3 newPos(random.GetFloat(-50.0f, 50.0f), 0.0f, random.GetFloat(-50.0f, 50.0f));
		SetDestinationPosition(newPos);
	}
}