void RotateInteraction::snapMouseReleaseEvent(QMouseEvent * anEvent, Feature* /*Closer*/)
{
    Q_UNUSED(anEvent);

    if (Angle != 0.0 && Rotating.size() && !panning())
    {
        CommandList* theList;
        theList = new CommandList(MainWindow::tr("Rotate Feature").arg(Rotating[0]->id().numId), Rotating[0]);
        for (int i=0; i<Rotating.size(); ++i)
        {
            if (NodeOrigin && Rotating[i] == OriginNode)
                continue;
            Rotating[i]->setPosition(OriginalPosition[i]);
            if (Rotating[i]->layer()->isTrack())
                theList->add(new MoveNodeCommand(Rotating[i],rotatePosition(OriginalPosition[i], Angle), Rotating[i]->layer()));
            else
                theList->add(new MoveNodeCommand(Rotating[i],rotatePosition(OriginalPosition[i], Angle), document()->getDirtyOrOriginLayer(Rotating[i]->layer())));
        }


        document()->addHistory(theList);
        view()->invalidate(true, false);
    }
    Angle = 0.0;
    Rotating.clear();
    OriginalPosition.clear();
    clearNoSnap();
}
void RotateInteraction::snapMouseMoveEvent(QMouseEvent* anEvent, Feature* /*Closer*/)
{
    if (Rotating.size() && !panning())
    {
        Angle = calculateNewAngle(anEvent);
        for (int i=0; i<Rotating.size(); ++i) {
            if (NodeOrigin && Rotating[i] == OriginNode)
                continue;
            Rotating[i]->setPosition(rotatePosition(OriginalPosition[i], Angle));
        }
        view()->invalidate(true, false);
    }
}
Mat TrackingAndDetection::createAppearance(Mat frame, Location location, int width, int height)
{
    int xStart, yStart;
    location.getCornerPoint(&xStart, &yStart, frame);
    Mat appearance(height, width, frame.type());
    for(int x = 0; x < width; x++)
    {
        for(int y = 0; y < height; y++)
        {
            int locX = x + xStart;
            int locY = y + yStart;
            rotatePosition(location.getRotation(), &locX, &locY, frame.size().width / 2, frame.size().height / 2);
            appearance.at<Vec3b>(Point(x,y)) = frame.at<Vec3b>(Point(locX, locY));
        }
    }
    return appearance;
}
示例#4
0
Float RotateGameObject(Script * script)
{
	if (script->VerifyArguments(3) == true)
	{
		Word * rotatePosWord = script->GetNextWord();
		Point2D rotatePosition(0, 0);
		Point2D * rotatePos = (Point2D *)(uint32)rotatePosWord->value;
		if (rotatePos != NULL)
		{
			rotatePosition.SetValues(rotatePos->GetX(), rotatePos->GetY());
		}

		Word * angleWord = script->GetNextWord();

		Word * directionWord = script->GetNextWord();
		Vector3D direction(0, 0, 0);
		Point2D * dirVector = (Point2D *)(uint32)directionWord->value;
		if (dirVector != NULL)
		{
			direction.SetValues(dirVector->GetX(), dirVector->GetY(), 0);
		}

		GameObject * source = (GameObject *)script->GetSource();
		Shape * shape = source->GetShape();
		
		if ((rotatePos != NULL) && (source != NULL) && (source->CheckType(OBJ_TYPE_GAME_OBJECT) == true) && (shape != NULL))
		{
			Float distance = CalculateDistance(rotatePosition, source->GetPosition());
			if (angleWord->value != NULL)
			{
				Vector3D sourceDirection(rotatePosition, source->GetPosition());
				Float angle = sourceDirection.GetZeroAngleD() + angleWord->value;
				
				source->SetPosition(rotatePosition.GetX() + (distance * CosD(angle)),
									rotatePosition.GetY() + (distance * SinD(angle)));

				direction.SetValues(rotatePosition, source->GetPosition());
				direction.SetUnitVector();
			}
			else if (dirVector != NULL)
			{
				direction -= rotatePosition;
				direction.SetUnitVector();

				source->SetPosition(rotatePosition.GetX() + (direction.GetX() * distance),
									rotatePosition.GetY() + (direction.GetY() * distance));
			}
			else
			{
				return false;
			}

			if ((shape->GetType() == SHAPE_TYPE_LINE) || (shape->GetType() == SHAPE_TYPE_LINE_SEGMENT))
			{
				Line * line = (Line *)shape;
				Line * newLine = (Line *)line->CreateInstance();
				newLine->Translate(source->GetPosition());	

				Vector3D v1(rotatePosition, newLine->GetPoint1());
				Vector3D v2(rotatePosition, newLine->GetPoint2());

				Float baseAngle = direction.GetZeroAngleD();

				Float v1Length = v1.GetLength();
				Float v2Length = v2.GetLength();
				Float angle1 = v1.GetZeroAngleD() - baseAngle;
				Float angle2 = v2.GetZeroAngleD() - baseAngle;

				Point2D p1((v1Length * CosD(angle1)),
						   (v1Length * SinD(angle1)));
				Point2D p2((v2Length * CosD(angle2)),
						   (v2Length * SinD(angle2)));

				line->SetValues(p1 + rotatePosition, p2 + rotatePosition);

				line->Translate(!source->GetPosition());

				delete newLine;
			}
			else if (shape->GetType() == SHAPE_TYPE_CONE)
			{
				Cone * cone = (Cone *)shape;
				cone->SetValues(cone->GetVertex(), Vector3D(dirVector->GetX(), dirVector->GetY(), 0), cone->GetHeight(), cone->GetAngle());
			}
			return true;
		}
	}
	return false;
}