示例#1
0
CardinalSplineTo* createCardinalSplineTo(Vec2 startPoint,Vec2 endPoint)
{
    float x1=startPoint.x;
    float y1=startPoint.y;
    float x2=endPoint.x;
    float y2=endPoint.y;
    
    float targetX=0.0f;
    float targetY=0.0f;
    float delta=(x2-x1)/10.0f;
    float p=(x2-x1)*(x2-x1)/(-2*(y2-y1));
    
    auto array = PointArray::create(10);
    for (int i = 1; i < 10; i++)
    {
        targetX=x1+i*delta;
        targetY=(targetX-x1)*(targetX-x1)/(-2*p)+y1;
        array->addControlPoint(Vec2(targetX,targetY));
    }
    array->addControlPoint(endPoint);
    
    float moveInterval=(endPoint-startPoint).length()/1300.0f;
    CardinalSplineTo* cardinalSplineTo=CardinalSplineTo::create(moveInterval,array,1.0f);
    return cardinalSplineTo;
}
void Boss::_dash()
{
    int neg = (CCRANDOM_0_1()>0.5)? -1: 1;
    
    auto array = PointArray::create(6);
    
    array->addControlPoint(Point(0,0));
    array->addControlPoint(Point(80*neg,-300));
    array->addControlPoint(Point(500*neg,-900));
    array->addControlPoint(Point(700*neg,-600));
    array->addControlPoint(Point(500*neg,400));
    array->addControlPoint(Point(0,0));
    
    auto action = CardinalSplineBy::create(5.5, array,0);
    runAction(Sequence::create(
                               DelayTime::create(0.5),
                               EaseSineOut::create(action)
                               ,nullptr)
              );
    runAction(
              Sequence::create(
                               EaseSineInOut::create(RotateBy::create(0.5, Vertex3F(0,30*neg,0))),
                               RotateBy::create(2.5, Vertex3F(-30,45*neg,-90*neg)),
                                RotateBy::create(1, Vertex3F(0,-35*neg,-200*neg)),
                               EaseSineInOut::create(RotateBy::create(1.5, Vertex3F(30,-40*neg,-70*neg))),
                               CallFunc::create(this, Boss::_next()),
              nullptr)
              );
}
示例#3
0
Curve::Curve(const float fMaxX, const Point& point) :
	m_pceEvaluator(NULL),
	m_bDirty(true),
	m_fMaxX(fMaxX),
	m_bWrap(false)
{
	addControlPoint(point);
}
void TerraceModule::read (utils::InStream &s)
{
	mControlPoints.clear ();
	mInvert = (s.readInt() != 0);
	int count = s.readInt ();
	for (int i=0;i<count;++i)
	{
		addControlPoint (s.readDouble());
	}
}
void CurveModule::read (utils::InStream &s)
{
	mControlPoints.clear ();
	int count = s.readInt ();
	for (int i=0;i<count;++i)
	{
		double inValue = s.readDouble ();
		double outValue = s.readDouble ();
		addControlPoint (inValue, outValue);
	}
}
void GLWidget::mouseReleaseEvent(QMouseEvent *event)
{
    // left click to add points
    if (!isPointMoving && event->button() == Qt::LeftButton) {
        QPoint mpos = event->pos();
        addControlPoint((float)mpos.x(), (float)mpos.y(), 0.0f);
    }

    isPointMoving = false;
    isPointSelected = false;
}
示例#7
0
void GameScene::initAction()
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    auto windowSize = Director::getInstance()->getWinSize();
    
    // Move the hero across the screen
    auto movePlayerUp = MoveBy::create(1, Point(0 , windowSize.height * 0.2));
    auto movePlayerDown = movePlayerUp->reverse();
    auto delay = DelayTime::create(0.25f);
   
	// Create a cardinal action
	auto trajectoryArray = PointArray::create(9);
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.9 + origin.x, visibleSize.height * 0.6 + origin.y));
    trajectoryArray->addControlPoint(Point(visibleSize.width * 0.8 + origin.x, visibleSize.height * 0.7 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.7 + origin.x, visibleSize.height * 0.6 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.6 + origin.x, visibleSize.height * 0.5 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.5 + origin.x, visibleSize.height * 0.6 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.6 + origin.x, visibleSize.height * 0.7 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.7 + origin.x, visibleSize.height * 0.6 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.8 + origin.x, visibleSize.height * 0.5 + origin.y));
	trajectoryArray->addControlPoint(Point(visibleSize.width * 0.9 + origin.x, visibleSize.height * 0.6 + origin.y));
    
	auto cardinalAction = CardinalSplineBy::create(3, trajectoryArray, 0);
	
    auto sequencePlayer = Sequence::create(movePlayerUp, delay, movePlayerDown, delay->clone(), NULL);
    playerSprite->runAction(RepeatForever::create(sequencePlayer));
    
}
示例#8
0
void BezierSpline::read_text(std::istream &is, int num_points)
{

    for (int j = 0; j < num_points; ++j)
    {
        Point point;
        is >> point[0] >> point[1] >> point[2];

        if (j == num_points-1 && (point-getControlPoint(0)).norm() < FLT_EPSILON)
            setClosed(true);
        else
            addControlPoint(point);
    }
}
示例#9
0
void BezierSpline::convertFromPolyline(const Polyline &polyline, int smooth_coefficient)
{
    float scale = 1.0/smooth_coefficient;
    int n = polyline.numPoints();

    assert(n >= 2);

    for (int i = 0; i < n; ++i)
        addControlPoint(polyline.getPoint(i));

//    for (int i = 0; i < n; ++i)
//    {
//        if (i == 0) // is first
//        {
//            Eigen::Vector3f p1 = polyline.getPoint(i);
//            Eigen::Vector3f p2 = polyline.getPoint(i+1);

//            Eigen::Vector3f tangent = (p2 - p1);
//            Eigen::Vector3f q1 = p1 + scale * tangent;

//            addControlPoint(p1);
//            addControlPoint(q1);
//        } else if (i == n - 1)
//        {
//            Eigen::Vector3f p0 = polyline.getPoint(i-1);
//            Eigen::Vector3f p1 = polyline.getPoint(i);
//            Eigen::Vector3f tangent = (p1 - p0);
//            Eigen::Vector3f q0 = p1 - scale * tangent;

//            addControlPoint(q0);
//            addControlPoint(p1);
//        } else
//        {
//            Eigen::Vector3f p0 = polyline.getPoint(i-1);
//            Eigen::Vector3f p1 = polyline.getPoint(i);
//            Eigen::Vector3f p2 = polyline.getPoint(i+1);
//            Eigen::Vector3f tangent = (p2 - p0).normalized();
//            Eigen::Vector3f q0 = p1 - scale * tangent * (p1 - p0).norm();
//            Eigen::Vector3f q1 = p1 + scale * tangent * (p2 - p1).norm();

//            addControlPoint(q0);
//            addControlPoint(p1);
//            addControlPoint(q1);
//        }
//    }

    setClosed(polyline.closed());
}
示例#10
0
/**
 * This method will sample the node at each frame to get any possible change
 * of position, rotation and scaling. The posible changes is inserted into an
 * OSG AnimationPath and returned.
 */
osg::AnimationPath* OSGExp::sampleNode(INode* node){

    // Create the animation path.
    osg::AnimationPath* animationPath = new osg::AnimationPath();
    animationPath->setLoopMode(osg::AnimationPath::LOOP);

	TimeValue start = _ip->GetAnimRange().Start();
	TimeValue end = _ip->GetAnimRange().End();
	int val;
	if (node->GetUserPropInt("startFrame",val))
		start= val;
	if (node->GetUserPropInt("endFrame",val))
		end= val;
	TimeValue t;
	int delta = GetTicksPerFrame();
	Matrix3 tm;
	AffineParts ap;

	for (t=start; t<=end; t+=delta) {
		tm = node->GetNodeTM(t) * Inverse(node->GetParentTM(t));
		decomp_affine(tm, &ap);
		Point3 pos = ap.t;
		Point3 sca = ap.k;

		// Note: OSG wants absolute rotations
		Quat rot = ap.q;

		// Convert from Max's left-handed rotation to right-handed
		float ang;
		Point3 axis;
		AngAxisFromQ(rot, &ang, axis);
		ang = -ang;
		rot = QFromAngAxis(ang, axis);
 
		// Insert the sample point into animation path
		addControlPoint(animationPath, (t/(float)TIME_TICKSPERSEC), pos, rot, sca);
	}
	return animationPath;
}
示例#11
0
void Spline::addControlPoint(real x, real y) {
    addControlPoint(vec2(x, y));
}
示例#12
0
PointArray * HelloWorld::getValidStep( Point coor )
{   
	auto arrary = PointArray::create(6);
	int x = coor.x;
	int y = coor.y;
	
	//left
	if (y - 1 >=0)
	{
		auto vcoor = Point(x,y - 1);
		if (!getSpriteFromCoor(vcoor)->IsSelect())
		{
			arrary->addControlPoint(vcoor);
		}
	}
	//right
	if (y + 1 < MAXCOLLUM)
	{
		auto vcoor = Point(x,y + 1);
		if (!getSpriteFromCoor(vcoor)->IsSelect())
		{
			arrary->addControlPoint(vcoor);
		}
	}
	if (x % 2 == 0)
	{
		//topleft
		if (y - 1 >= 0 && x + 1 < MAXROW)
		{
			auto vcoor = Point(x+1,y-1);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}
		//top right
		if (y < MAXCOLLUM && x + 1 < MAXROW)
		{
			auto vcoor = Point(x+1,y);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}
		
		//bottom  left

		if (y - 1 >= 0 && x - 1 >= 0)
		{
			auto vcoor = Point(x-1,y-1);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}
		
		//bottom right
		if (y  < MAXCOLLUM && x - 1 >= 0)
		{
			auto vcoor = Point(x-1,y);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}
	}
	else
	{
		//topleft
		if (y  >= 0 && x + 1 < MAXROW)
		{
			auto vcoor = Point(x+1,y);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}
		//top right
		if (y + 1< MAXCOLLUM && x + 1 < MAXROW)
		{
			auto vcoor = Point(x+1,y + 1);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}

		//bottom  left

		if (y  >= 0 && x - 1 >= 0)
		{
			auto vcoor = Point(x-1,y);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}

		//bottom right
		if (y + 1 < MAXCOLLUM && x - 1 >= 0)
		{
			auto vcoor = Point(x-1,y+1);
			if (!getSpriteFromCoor(vcoor)->IsSelect())
			{
				arrary->addControlPoint(vcoor);
			}
		}
	}
	return arrary;

}
示例#13
0
bool taskMgr::init()
{
    m_openSaml=false;
    m_openMain = false;
    initdata();
    PMission MainTask = GetMissCur(0);
    
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
	m_MainTaskICO = MenuItemImage::create("images/Scene/TaskScene/task_rookie_bg.png","images/Scene/TaskScene/task_rookie_bg.png",[&](Ref* Sender){
        ShowWin(0);
	
	 });
    m_samlinfo =MenuItemImage::create("images/Scene/TaskScene/task_bg.png","",[&](Ref* Sender){
        ShowWin(1);
    });
    
    m_popsaml =MenuItemImage::create("images/Scene/TaskScene/word_new.png","",[&](Ref* Sender){
        ShowSmlSample();
    });
    
    m_smlget = MenuItemImage::create("images/Scene/TaskScene/word_success.png","",[&](Ref* Sender){
        ShowWin(1);
    });
    
    
    
    m_samltask = Sprite::create("images/Scene/TaskScene/task_light.png");
    this->addChild(m_samltask);
    m_samltask->setPosition(100,450);
    m_samltask->setVisible(false);
	m_samltask->runAction(RepeatForever::create(Sequence::create(FadeOut::create(1), FadeIn::create(1), NULL)));
    m_smlico = Sprite::create();
    this->addChild(m_smlico,10);
    m_smlico->setVisible(false);
    m_smlico->setPosition(50,460);
    
    Vec2 Pos(100,350);
    auto Menu = Menu::create(m_MainTaskICO,m_samlinfo,m_popsaml,m_smlget,nullptr);
    this->addChild(Menu);
    Menu->setPosition(Pos);
    m_samlinfo->setPosition(0,100);
    m_popsaml->setPosition(-200,100);
    m_smlget->setPosition(0,100);
    
    m_smlget->setVisible(false);
    m_samlinfo->setVisible(false);
    
    m_samllab = Label::create("", "Arial", 20);
    this->addChild(m_samllab);
    m_samllab->setPosition(120,450);
    m_samllab->setVisible(false);
    
    m_MainTaskICO->setVisible(false);
    
    if(MainTask->missState != 999999)
    {
        m_MainTaskICO->setVisible(true);
        m_MainTaskLab = LabelAtlas::create("20000","images/Number/shop_coin_num.png",22,28,'0');
        this->addChild(m_MainTaskLab,1);
        m_MainTaskLab->setPosition(Vec2(80,320));
        m_maintmlab = Label::create("", "Arial", 24);
        this->addChild(m_maintmlab);
        m_maintmlab->setPosition(100,305);
        float r = 60;

        
        m_Partic=ParticleSystemQuad::create("particles/taskAward.plist");
        m_Partic->setPositionType(ParticleSystem::PositionType::FREE);
        m_Partic->setAutoRemoveOnFinish(true);
        this->addChild(m_Partic,1000);
        auto array2 = PointArray::create(360);
        
        for(int i = 0; i < 360; ++i)
        {
            Vec2 l(0,r);
            l.rotate(Vec2(0,0), i * 10);
            array2->addControlPoint(Pos + l);
        }
        auto action = CatmullRomTo::create(240, array2);
        m_Partic->setPosition(Pos);
        
        m_Partic->runAction(RepeatForever::create(action));
        
        m_taskfail = Sprite::create("images/Scene/TaskScene/word_fail.png");
        this->addChild(m_taskfail);
        m_taskfail->setPosition(100,450);
        m_taskfail->setVisible(false);
    }
    
	return true;
}
示例#14
0
void MapTool::
buttonCallback(int buttonSlotIndex,
               Vrui::InputDevice::ButtonCallbackData* cbData)
{
statsMan.start(StatsManager::EDITLINE);

    Geometry::Point<double,3> pos = getPosition();
    pos        = crusta->mapToUnscaledGlobe(pos);

    Shape*& curShape = crusta->getMapManager()->getActiveShape(toolId);

    if (cbData->newButtonState)
    {
        if (buttonSlotIndex==0)
        {
            switch (mode)
            {
                case MODE_IDLE:
                {
                    createShape(curShape, curControl, pos);
                    crusta->getMapManager()->updateActiveShape(toolId);
                    mode = MODE_DRAGGING;
                    break;
                }

                case MODE_SELECTING_CONTROL:
                {
                    selectControl(pos);
                    addControlPoint(curShape, curControl, pos);
                    mode = MODE_DRAGGING;
                    break;
                }

                case MODE_SELECTING_SHAPE:
                {
                    if (curShape != NULL)
                    {
                        deleteShape(curShape, curControl);
                    }
                    break;
                }

                default:
                    break;
            }
        }
        else
        {
            switch (mode)
            {
                case MODE_DRAGGING:
                {
                    removeControl(curShape, curControl);
                    //destroy empty shapes
                    if (curShape->getControlPoints().size()==0)
                    {
                        deleteShape(curShape, curControl);
                        mode = MODE_IDLE;
                    }
                    else
                        mode = MODE_SELECTING_CONTROL;
                    break;
                }

                case MODE_IDLE:
                case MODE_SELECTING_CONTROL:
                {
                    selectShape(pos);
                    mode = MODE_SELECTING_SHAPE;
                   break;
                }

                default:
                    break;
            }
        }
    }
    else
    {
        if (buttonSlotIndex==0)
        {
            switch (mode)
            {
                case MODE_DRAGGING:
                {
                    mode = MODE_SELECTING_CONTROL;
                    break;
                }

                default:
                    break;
            }
        }
        else
        {
            switch (mode)
            {
                case MODE_SELECTING_SHAPE:
                {
                    if (curShape != NULL)
                    {
                        mode = MODE_SELECTING_CONTROL;
                    }
                    else
                    {
                        mode = MODE_IDLE;
                    }
                    break;
                }

                default:
                    break;
            }
        }
    }

statsMan.stop(StatsManager::EDITLINE);
}
void
rce::gui::RImageMarkerScene::
mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if(mouseEvent->button() == Qt::LeftButton)
    {
        const QGraphicsView *eventView = NULL;
        if(mouseEvent->widget() != NULL)
        {
            eventView = dynamic_cast<const QGraphicsView*>(mouseEvent->widget()->parentWidget());
        }

        QTransform viewTransform;
        if(eventView != NULL)
        {
            viewTransform = eventView->transform();
        }

        itemEdited_ = false;
        switch(mode_)
        {
            case rce::gui::RImageMarkerScene::DrawPointMode:
                {
                    // check if there is handle under mouse
                    QList<QGraphicsItem *> itemsUnderMouse = items(rce::gui::getSceneRectAroundScreenPos(mouseEvent->screenPos(),
                                                                                                         mouseEvent->scenePos(),
                                                                                                         dynamic_cast<const QGraphicsView*>(mouseEvent->widget()->parentWidget())),
                                                                   Qt::IntersectsItemBoundingRect,
                                                                   Qt::DescendingOrder,
                                                                   viewTransform);
                    QGraphicsItem *handle = NULL;
                    for(int i = 0; i < itemsUnderMouse.size(); ++i)
                    {
                        if((itemsUnderMouse[i]->data(RCE_ITEM_TYPE_DATA_INDEX).toUInt() == HandleType)
                           && itemsUnderMouse[i]->boundingRect().contains(itemsUnderMouse[i]->mapFromScene(mouseEvent->scenePos())))
                        {
                            handle = itemsUnderMouse[i];
                            break;
                        }
                    }

                    if(handle != NULL)
                    { // there is handle, set is as active
                        activeHandleIdx_ = 0;
                    }
                    else
                    {
                        activeHandleIdx_ = -1;
                    }
                }
                break;
            case rce::gui::RImageMarkerScene::DrawPolygonMode:
            case rce::gui::RImageMarkerScene::DrawPolylineMode:
                {
                    // check if there is handle under mouse
                    QList<QGraphicsItem *> itemsUnderMouse = items(rce::gui::getSceneRectAroundScreenPos(mouseEvent->screenPos(),
                                                                                                         mouseEvent->scenePos(),
                                                                                                         dynamic_cast<const QGraphicsView*>(mouseEvent->widget()->parentWidget())),
                                                                   Qt::IntersectsItemBoundingRect,
                                                                   Qt::DescendingOrder,
                                                                   viewTransform);
                    QGraphicsItem *handle = NULL;
                    for(int i = 0; i < itemsUnderMouse.size(); ++i)
                    {
                        if((itemsUnderMouse[i]->data(RCE_ITEM_TYPE_DATA_INDEX).toUInt() == HandleType)
                           && itemsUnderMouse[i]->boundingRect().contains(itemsUnderMouse[i]->mapFromScene(mouseEvent->scenePos())))
                        {
                            handle = itemsUnderMouse[i];
                            break;
                        }
                    }

                    if(handle != NULL)
                    { // there is handle, set is as active
                        activeHandleIdx_ = handle->data(RCE_ITEM_ID_DATA_INDEX).toInt();
                    }
                    else
                    { // there is not handle - create new
                        addControlPoint(mouseEvent->scenePos());
                        itemEdited_ = true;
                        activeHandleIdx_ = handles_.size() - 1;
                    }
                }
                break;
            case rce::gui::RImageMarkerScene::PickPolygonMode:
            case rce::gui::RImageMarkerScene::PickPolylineMode:
            case rce::gui::RImageMarkerScene::PickPointMode:
            case rce::gui::RImageMarkerScene::PickAnyMode:
                {
                    QVector<quint32> polygons;
                    QVector<quint32> polylines;
                    QVector<quint32> points;

                    getItemsAtPosition(rce::gui::getSceneRectAroundScreenPos(mouseEvent->screenPos(),
                                                                             mouseEvent->scenePos(),
                                                                             dynamic_cast<const QGraphicsView*>(mouseEvent->widget()->parentWidget())),
                                       polygons,
                                       polylines,
                                       points,
                                       viewTransform);

                    if(polygons.size() + polylines.size() + points.size() > 1)
                    { // show menu

                        QMap<QAction *, quint32> actionToPolygon;
                        QMap<QAction *, quint32> actionToPolyline;
                        QMap<QAction *, quint32> actionToPoint;


                        QMenu *ctxMenu = new QMenu(mouseEvent->widget());
                        ctxMenu->setTitle(tr("Pick Item..."));

                        foreach(quint32 polygonID,
                                polygons)
                        {
                            actionToPolygon[ctxMenu->addAction(getPolygonDisplayName(polygonID))] = polygonID;
                        }
                        ctxMenu->addSeparator();

                        foreach(quint32 polylineID,
                                polylines)
                        {
                            actionToPolyline[ctxMenu->addAction(getPolylineDisplayName(polylineID))] = polylineID;
                        }
                        ctxMenu->addSeparator();

                        foreach(quint32 pointID,
                                points)
                        {
                            actionToPoint[ctxMenu->addAction(getPointDisplayName(pointID))] = pointID;
                        }


                        QAction *selectedAction = ctxMenu->exec(mouseEvent->screenPos());

                        if(actionToPolygon.contains(selectedAction))
                        {
                            pickedItem_ = polygonItems_[actionToPolygon[selectedAction]];
                            emit pickedPolygon(actionToPolygon[selectedAction]);
                        }
                        else if(actionToPolyline.contains(selectedAction))
                        {
                            pickedItem_ = polylineItems_[actionToPolyline[selectedAction]];
                            emit pickedPolyline(actionToPolyline[selectedAction]);
                        }
                        else if(actionToPoint.contains(selectedAction))
                        {
                            pickedItem_ = pointItems_[actionToPoint[selectedAction]];
                            emit pickedPoint(actionToPoint[selectedAction]);
                        }
                        else
                        {
                            pickedItem_ = NULL;
                            emit pickedNothing();
                        }

                        ctxMenu->deleteLater();
                    }
                    else
                    {
                        if(polygons.size() == 1)
                        {
                            pickedItem_ = polygonItems_[polygons[0]];
                            emit pickedPolygon(polygons[0]);
                        }
                        else if(polylines.size() == 1)
                        {
                            pickedItem_ = polylineItems_[polylines[0]];
                            emit pickedPolyline(polylines[0]);
                        }
                        else if(points.size() == 1)
                        {
                            pickedItem_ = pointItems_[points[0]];
                            emit pickedPoint(points[0]);
                        }
                        else
                        {
                            pickedItem_ = NULL;
                            emit pickedNothing();
                        }
                    }
                }
                break;
        }