示例#1
0
    Player( XGame *g ) : Sprite(g) {
        frameTime = 3;
        color = alienColors[rand()%alienColors.size()];

        walkSpeed = 18;
        jumpStartSpeed = 60;
        alive = true;
        stretch = false;
        jumping = false;
        y = 400;
        x = 70*6;

        for( int i=0; i<0xFFFF; ++i ) keys[i]=false;

        texture = game->loadSpritesheet("aliens");
        stateIdle();

        XGameTexture *t = game->getTexture(texture);
        applyAnimation();
        h = t->cropHeight;
        w = t->cropWidth;

        g->onKeyDown = std::bind(&Player::onKeyDown, this, std::placeholders::_1);
        g->onKeyUp = std::bind(&Player::onKeyUp, this, std::placeholders::_1);
    }
示例#2
0
	void AnimatedModel::render(render::RenderQueue &queue,
	                          unsigned int instancecount,
	                          math::Mat4f *transmat)
	{
		core::MemoryPool *memory = queue.memory;
		// Create transformation matrix list
		unsigned int memsize = sizeof(math::Mat4f) * instancecount;
		math::Mat4f *matrices = (math::Mat4f*)memory->allocate(memsize);
		for (unsigned int i = 0; i < instancecount; i++)
			matrices[i] = transmat[i];
		// Compute animation data for all nodes
		std::vector<Model::Node> animatednodes = model->getNodes();
		applyAnimation(animatednodes);
			// Render mesh
		const std::vector<Model::Batch> &batches = model->getBatches();
		const std::vector<Model::BatchGeometry> &geometry = model->getGeometry();
		// TODO: Culling
		for (unsigned int i = 0; i < batches.size(); i++)
		{
			render::Batch *batch = model->prepareBatch(queue, i, true, true);
			if (!batch)
				continue;
			// Skinning
			if (batch->shader->skinning)
			{
				const Model::BatchGeometry *geom = &geometry[batches[i].geometry];
				unsigned int jointcount = geom->joints.size();
				void *ptr = memory->allocate(sizeof(float) * 16 * jointcount);
				float *skinmatrices = (float*)ptr;
				for (unsigned int j = 0; j < jointcount; j++)
				{
					int jointnode = geom->joints[j].node;
					if (jointnode == -1)
					{
						// TODO
						std::cout << "Invalid joint node." << std::endl;
					}
					else
					{
						math::Mat4f jointmat = animatednodes[jointnode].abstrans * geom->joints[j].jointmat;
						memcpy(&skinmatrices[j * 16], jointmat.m, 16 * sizeof(float));
					}
				}
				batch->skinmat = skinmatrices;
				batch->skinmatcount = jointcount;
				batch->transmat = math::Mat4f::Identity();
				batch->transmatcount = instancecount;
				batch->transmatlist = matrices;
			}
			else
			{
				batch->transmat = animatednodes[batches[i].node].abstrans;
				batch->transmatcount = instancecount;
				batch->transmatlist = matrices;
			}
			// Add batch to the render queue
			tbb::mutex::scoped_lock lock(queue.batchmutex);
			queue.batches.push_back(batch);
		}
	}
slideShowEngine::State slideShowEngine::runEngine()
{
int ret,x,y;
QPixmap pix;
QModelIndex index;
QVariant val;
node itemNode;
Pixmap *item;
effect e;


    if(m_currentState!=Running)
        return m_currentState;

    ret=applyAnimation();

    if(ret==EndAnimation)
    {
        //m_stepCurrentTime=0;
        if(step()==EnterAnimation)
        {
            setStep(DisplayAnimation);
            //m_timerAnimation.restart();
            m_stepCurrentTime=0;
            //qDebug() << "enter->display";
        }
        else
        {
            if(step()==DisplayAnimation)
            {
                setStep(ExitAnimation);
                //m_timerAnimation.restart();
                m_stepCurrentTime=0;
                //qDebug() << "display->exit";
                // if(m_showType==IN)
                // remove_old_items...

                if(m_currentSlideIndex+1<m_sequence->rowCount())
                {
                    index=m_sequence->index(m_currentSlideIndex+1);
                    if(index.isValid())
                    {
                        //if(m_showType==OUT)
                        val=index.data(Qt::UserRole);
                        itemNode=val.value<node>();

                        if(m_exportToMovie)
                        {
                            pix.load(itemNode.nodePath());
                        }
                        else
                        {
                            pix=itemNode.nodePixmap();
                        }

                        m_currentNode=itemNode;

                        if(pix.width()>m_size.width() || pix.height()>m_size.height())
                            pix=pix.scaled(m_size,Qt::KeepAspectRatio,Qt::SmoothTransformation);
                        item = new Pixmap(pix);

                        if(m_exportToMovie)
                            item->setTransformationMode(Qt::SmoothTransformation);

                        m_PixmapList.append(item); // serve questa lista?
                        if(m_size.width()>pix.width())
                        {
                            x=(m_size.width()-pix.width())/2;
                        }
                        else
                        {
                            x=0;
                        }


                        if(m_size.height()>pix.height())
                        {
                            y=(m_size.height()-pix.height())/2;
                        }
                        else
                        {
                            y=0;
                        }

                        item->setPos(qreal(x), qreal(y));
                        item->setZValue(qreal(m_sequence->rowCount()-m_currentSlideIndex-1));
                        m_scene->addItem(item);
                        //applyAnimation();
                    }

                }
                else
                {
                    qDebug()<<"index out of range";
                }

            }
            else
            {
                if(step()==ExitAnimation)
                {
                    item=m_PixmapList[m_currentSlideIndex];
                    m_scene->removeItem(item);

                    m_currentSlideIndex++;
                    if(m_currentSlideIndex<m_sequence->rowCount())
                    {

                     /*   index=m_sequence->index(m_currentSlideIndex);
                        if(index.isValid())
                        {
                            //if(m_showType==OUT)
                            val=index.data(Qt::UserRole);
                            itemNode=val.value<node>();
                            pix=itemNode.nodePixmap();
                            item = new Pixmap(pix);
                            m_PixmapList.append(item); // serve questa lista?
                            item->setPos(0.0, 0.0);
                            //item->setZValue(qreal(m_sequence->rowCount()-m_currentSlideIndex));
                            m_scene->addItem(item);
                            applyAnimation();
                        }*/

                        setStep(EnterAnimation);
                        //m_timerAnimation.restart();
                        m_stepCurrentTime=0;
                    }
                    else
                    {
                        // end
                        //endOfSlideShow();
                        return Finished;
                    }


                } // if(step()==ExitAnimation)
                else
                {



                } // else if(step()==ExitAnimation)



            } // else if(step()==DisplayAnimation)



        } // else if(step()==EnterAnimation)



    } // if(ret==EndAnimation)
    //m_stepCurrentTime++;
    //m_totalCurrentTime++;


    if(m_exportToMovie)
    {        
        QImage frame(m_size,QImage::Format_RGB32);
        QPainter p(&frame);
        m_scene->render(&p);
        p.end();

        //QString frameName=QString("./tmp/f%1").arg(m_frame_number++);
        //frameName.append(".jpg");
        //frame.save(frameName);
        //encoder.encodeImage(frame);

        QByteArray dati;
        QBuffer buffer(&dati);
        buffer.open(QIODevice::WriteOnly);        
        frame.save(&buffer, "JPG");
        m_ffmpegProcess.write(buffer.buffer());
        m_ffmpegProcess.waitForBytesWritten();

        //QString command;
        ////m_ffmpegProcess.start("/usr/bin/ffmpeg", QStringList() << "-y -f image2pipe -i pipe:.jpg -target ntsc-dvd my.mpg");

        //command=QString("/usr/bin/ppmtoy4m -v 0 -n 1 -F 25:1 -S 420jpeg");


        //m_ffmpegProcess.write(EOF);
        //command.append(" -F 25:1 -S 420jpeg ");
        //command.append(buffer.buffer());


       //qDebug() << command;



        //dati=m_ffmpegProcess.readAllStandardOutput();


        //m_ffmpegProcess.write(buffer.buffer());
        //frame.save(m_ffmpegProcess);
        //m_ffmpegProcess << frameName;
        //ffmpeg -y -f image2pipe -i pipe:.jpg -target ntsc-dvd my.mpg



    }



    return Running;

}
void slideShowEngine::start()
{
int x,y;

QPixmap pix;
QModelIndex index;
QVariant val;
node itemNode;
//QPropertyAnimation *enterAnimation,*displayAnimation,*exitAnimation;
Pixmap *item;
effect e;
//QParallelAnimationGroup *parallelAnim;
//QSequentialAnimationGroup *seqAnim;


    if(state()==Paused)
        resume();

    if(state()==Running)
        return;


    //QList <QGraphicsView *> views=m_scene->views();
    //m_size=views.at(0)->size();
    //int s=views.size();

    m_frame_number=0;
    m_scene->clear();    
    m_scene->setSceneRect(0.0,0.0,qreal(m_size.width()),qreal(m_size.height()));
    m_currentSlideIndex=0;
    index=m_sequence->index(m_currentSlideIndex);
    if(index.isValid())
    {
        m_currentState=Running;
        m_currentStep=EnterAnimation;
        //m_totalCurrentTime=0;
        //m_stepCurrentTime=0;

        val=index.data(Qt::UserRole);
        itemNode=val.value<node>();

        if(m_exportToMovie)
        {
            pix.load(itemNode.nodePath());
        }
        else
        {
            pix=itemNode.nodePixmap();
        }

        m_currentNode=itemNode;
        if(pix.width()>m_size.width() || pix.height()>m_size.height())
            pix=pix.scaled(m_size,Qt::KeepAspectRatio,Qt::SmoothTransformation);

        item = new Pixmap(pix);
        if(m_exportToMovie)
            item->setTransformationMode(Qt::SmoothTransformation);
        m_PixmapList.append(item); // serve questa lista?
        if(m_size.width()>pix.width())
        {
            x=(m_size.width()-pix.width())/2;
        }
        else
        {
            x=0;
        }


        if(m_size.height()>pix.height())
        {
            y=(m_size.height()-pix.height())/2;
        }
        else
        {
            y=0;
        }

        item->setPos(qreal(x), qreal(y));
        item->setZValue(qreal(m_sequence->rowCount()-m_currentSlideIndex));
        m_scene->addItem(item);
        applyAnimation();
        //m_timerId=startTimer(TIMER_ANIMATION);
    }



    m_totalCurrentTime=0;
    m_stepCurrentTime=0;

    /*int width=m_sequence->movieResolution().width();
    int height=m_sequence->movieResolution().height();
    int bitrate=m_sequence->movieBitRate();*/
    int frameRate=m_sequence->movieFrameRate();
    //int gop = 20;

    if(m_exportToMovie)
    {
        //encoder.createFile(m_movieName,width,height,bitrate,gop,frameRate);
        QEventLoop evt;
        int frames=0;

        while(m_currentState!=Finished && m_currentState!=Stopped)
        {
           m_currentState=runEngine();
           if(m_currentState==Running)
            emit refresh(m_totalCurrentTime);
           evt.processEvents();


           if(m_currentState==Running)
           {
               //int elapsed=m_timerAnimation.elapsed();
               //qDebug() << elapsed;
               int period=1000/frameRate;
               m_totalCurrentTime+=period;
               m_stepCurrentTime+=period;
               m_timerAnimation.start();
           }
           frames++;

        }
        qDebug() << "frames:" << frames;
        endOfSlideShow();

     }
    else
    {
        startSound();
        m_timerId=startTimer(25); // TIMER_ANIMATION
        m_timerAnimation.start();        
    }

    //State state=Running;
    //m_timerAnimation.start();
    //m_totalTime.start();       
    //qDebug("Time elapsed: %d ms", t.elapsed());
}