Ejemplo n.º 1
0
//---------------------------------------------------------------------------
void CRenderWidget::mouseMoveEvent(QMouseEvent *event)
{
    if (mIsLeftMouseDown && mSelectedItems.size() > 0)
    {
        // Lookup the entity
        CEntity* entity = Globals::getCurrentScene()->getEntityFromGraphicsView(mSelectedItems.first());

        if (!entity)
        {
            QMessageBox::critical(this, "Erreur!", "Impossible de retrouver l'entité attachée au graphique sélectionné!");
            return;
        }

        QPoint delta = event->pos() - mMouseDownPosition;

        if (mDoCopySelection)
        {
            // Hep, stop right there! We want to duplicate the selection, and switch our current pick to the copied
            // entity, and move it.
            entity = Globals::getCurrentScene()->cloneEntity(entity);
            selectEntity(entity->getSceneItem());

            mDoCopySelection = false;
        }

        // Move the entity
        QPoint gridDelta = delta;//QPoint(ceil(delta.x() / 16.f) * 16.f, ceil(delta.y() / 16.f) * 16.f);
        Vector2D finalPos = mOriginalPosition + Vector2D(gridDelta.x(), gridDelta.y());

        entity->setPosition(finalPos);

        emit itemChanged();

        // Move selection rects
        for (QList<QGraphicsItem*>::iterator it = mSelectionRects.begin(); it != mSelectionRects.end(); ++it)
        {
            QGraphicsItem* rect = (*it);
            rect->setPos(gridDelta);
        }
    }
}
Ejemplo n.º 2
0
		bool CCollisionManager::update()
		{
			CEntity *entity;
					

			for (entityIter=T_entities.begin(); entityIter!=T_entities.end(); ++entityIter)
			{
				entity = *entityIter;
				/*	
					Check entities with terrain end make proper response, 
					all 4 must be checked since we ce be in the corner.
				*/
				if (entity->isActive())
				{
					// 1. get logical position
					vector2i pos = CConversions::realToLogical(entity->getPosition());

					// 2. extract proper planes of nearby block					
					check(entity,pos+vector2i(0,-1));
					check(entity,pos+vector2i(0,1));
					check(entity,pos+vector2i(-1,0));
					check(entity,pos+vector2i(1,0));

					/* ? check(entity,pos+vector2i(1,1));
					check(entity,pos+vector2i(1,-1));
					check(entity,pos+vector2i(-1,-1));
					check(entity,pos+vector2i(-1,1)); ? */

					// just clamp entity to the bottom if we are below min level
					vector3f ePos = entity->getPosition();

					if (ePos[1]<CV_CAMERA_MIN_FPS_Y_POS)
					{
						ePos[1] = CV_CAMERA_MIN_FPS_Y_POS;
						entity->setPosition(ePos);
					}
				}
			}

			return true;
		}