예제 #1
0
	//--------------------------------------------------------------------------------
	static void setTextureAndTexAniFPS(const MaterialPtr& _material, const String& _texture, Real _texAniFPS)
	{
		Technique* technique = _material->getTechnique(0);
		Pass* pass = technique->getPass(0);
		if(_texture.empty())
		{
			pass->removeAllTextureUnitStates();
		}
		else
		{
			TextureManager& tmgr = TextureManager::getSingleton();
			Ogre::TextureUnitState* tus = pass->getNumTextureUnitStates() ? pass->getTextureUnitState(0) : pass->createTextureUnitState();
			if(_texAniFPS == 0)
			{
				TexturePtr ogreTexture = tmgr.createOrRetrieve(_texture).first;
				const String& ogreTexName = ogreTexture->getName();
				tus->setTextureName(ogreTexName);
			}
			else
			{
				vector<String>::type ogreTexNames;
				TexturePtr ogreTexture = tmgr.createOrRetrieve(_texture).first;
				ogreTexNames.push_back(ogreTexture->getName());

				size_t dotpos = _texture.rfind('.');
				if(dotpos != String::npos && dotpos >= 1 
					&& '0' <= _texture[dotpos-1]  && _texture[dotpos-1] < '9')
				{
					String tmpname = _texture;
					char& dig0 = tmpname[dotpos - 1];
					++dig0;
					while(!tmgr.getByName(tmpname).isNull() || tmgr.canLoadResource(tmpname, TextureManager::GROUP_NAME))
					{
						TexturePtr ogreTexture = tmgr.createOrRetrieve(tmpname).first;
						ogreTexNames.push_back(ogreTexture->getName());
						++dig0;
						if(dig0 > '9')
						{
							if(dotpos >= 2 && '0' <= _texture[dotpos-2]  && _texture[dotpos-2] < '9')
							{
								char& dig1 = tmpname[dotpos-2];
								++dig1;
								dig0 = '0';
							}
							else
								break;
						}
					}
				}
				Real duration = ogreTexNames.size() / _texAniFPS;
				tus->setAnimatedTextureName(&ogreTexNames[0], ogreTexNames.size(), duration);
			}
		}
	}
예제 #2
0
void OgreCPP::createNewCrowdMember( float animationTime )
{
    char buffer[ 512 ];
    uint32_t numCrowdMembers = mCrowdMembers.size();

    // Create a new crowd member
    Ogre::TextureManager* pTextureMgr = Ogre::TextureManager::getSingletonPtr();
    Ogre::String frameTexNames[ 2*NUM_FRAMES_TO_RECORD ];
    Ogre::String lowResFrameTexNames[ 2*NUM_FRAMES_TO_RECORD ];
    for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ )
    {
        Ogre::Image image;
        image.loadDynamicImage( mpImageData + frameIdx*SMALL_FRAME_WIDTH*SMALL_FRAME_HEIGHT,
            SMALL_FRAME_WIDTH, SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );

        sprintf( buffer, "RecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx );
        frameTexNames[ frameIdx ] = buffer;

        Ogre::TexturePtr pTexture = pTextureMgr->loadImage( frameTexNames[ frameIdx ],
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, image );

        sprintf( buffer, "LowResRecordedSequenceTex_%i_%i", numCrowdMembers, frameIdx );
        lowResFrameTexNames[ frameIdx ] = buffer;

        Ogre::Image lowResImage;
        lowResImage.loadDynamicImage( mpLowResImageData + frameIdx*LOW_RES_SMALL_FRAME_WIDTH*LOW_RES_SMALL_FRAME_HEIGHT,
            LOW_RES_SMALL_FRAME_WIDTH, LOW_RES_SMALL_FRAME_HEIGHT, 1, Ogre::PF_A4L4 );

        pTextureMgr->loadImage( lowResFrameTexNames[ frameIdx ],
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, lowResImage );
    }

    for ( uint32_t frameIdx = 0; frameIdx < NUM_FRAMES_TO_RECORD; frameIdx++ )
    {
        frameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = frameTexNames[ frameIdx ];
        lowResFrameTexNames[ (2*NUM_FRAMES_TO_RECORD - 1) - frameIdx ] = lowResFrameTexNames[ frameIdx ];
    }

    // Create materials for the crowd member
    sprintf( buffer, "RecordedSequenceMat_%i", numCrowdMembers );
    Ogre::String matName = buffer;

    Ogre::MaterialManager* pMatMgr = Ogre::MaterialManager::getSingletonPtr();
    Ogre::MaterialPtr pSrcMat = (Ogre::MaterialPtr)pMatMgr->getByName( "Template/CutOut",
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    Ogre::MaterialPtr pMat = pSrcMat->clone( matName );

    pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
    Ogre::TextureUnitState* pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
    pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );

    pTex->setAnimatedTextureName( frameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime );

    pMat->setCullingMode( Ogre::CULL_NONE );
    pMat->compile();

    sprintf( buffer, "LowResRecordedSequenceMat_%i", numCrowdMembers );
    Ogre::String lowResMatName = buffer;

    pMat = pSrcMat->clone( lowResMatName );

    pMat->getTechnique( 0 )->getPass( 0 )->removeAllTextureUnitStates();
    pTex = pMat->getTechnique( 0 )->getPass( 0 )->createTextureUnitState();
    pMat->getTechnique( 0 )->getPass( 0 )->addTextureUnitState( pTex );

    pTex->setAnimatedTextureName( lowResFrameTexNames, 2*NUM_FRAMES_TO_RECORD, 2.0*animationTime );

    pMat->setCullingMode( Ogre::CULL_NONE );
    pMat->compile();

    CrowdMember newCrowdMember;
    newCrowdMember.mMaterialName = matName;
    newCrowdMember.mLowResMaterialName = lowResMatName;
    newCrowdMember.mFrameIdx = 0;
    newCrowdMember.mColourIdx = rand()%NUM_COLOURS;
    newCrowdMember.mbReversing = false;

    num = mCrowdMembers.size()%11;

	
	/** POSITION CROWD MEMBER HERE **/
    float x = (num*(5.0/11.0))-2.25;
    float y = 1.5;


    /* centre is 0,0, extremes are -3,+3 */
    newCrowdMember.mPos = Ogre::Vector3( x, y, 5.0 );
    newCrowdMember.mRow = 0;

    newCrowdMember.mpBillboard = OGRE_NEW PersonBillboard();
    newCrowdMember.mpBillboard->setMaterial( newCrowdMember.mMaterialName );
    newCrowdMember.mpBillboard->setCorners(
        Ogre::Vector3( -0.5f, -0.375f, 0.0f ),
        Ogre::Vector3( 0.5f, -0.375f, 0.0f ),
        Ogre::Vector3( -0.5f, 0.375f, 0.0f ),
        Ogre::Vector3( 0.5f, 0.375f, 0.0f )
    );

    // Make sure that the front row is drawn in front of everything else
    newCrowdMember.mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE );

    newCrowdMember.mpSceneNode = mpDiscoNode->createChildSceneNode(
        newCrowdMember.mPos, Ogre::Quaternion::IDENTITY );
    newCrowdMember.mpSceneNode->attachObject( newCrowdMember.mpBillboard );

    mCrowdMembers.push_back( newCrowdMember );


    /* PLACING RT USER IN CROWD HERE */
    if(USER_IN_CROWD){
        float userX = (((num+1)%CROWD_WIDTH)*(12.0/(float)CROWD_WIDTH))-5.5;
        mUserNode->setPosition(userX,3.45,9.5);
    }

	

	/** PUSH ROW UP **/
    if (num >= CROWD_WIDTH-1) {
        // push last row up
        for(int j = 0; j < mCrowdMembers.size(); j++)
        {
            mCrowdMembers[j].mPos.z += CROWD_PUSH_BACK;
            mCrowdMembers[j].mPos.y += CROWD_PUSH_UP;

            mCrowdMembers[j].mpSceneNode->setPosition( mCrowdMembers[j].mPos );
            mCrowdMembers[j].mRow++;

            if ( FIRST_LOW_RES_ROW_IDX == mCrowdMembers[j].mRow )
            {
                mCrowdMembers[j].mpBillboard->setMaterial( mCrowdMembers[j].mLowResMaterialName );
            }

            if ( mCrowdMembers[j].mRow > MAX_VISIBLE_ROW_IDX )
            {
            	mCrowdMembers[j].mpBillboard->setVisible( false );
            	mCrowdMembers[j].mpBillboard->setMaterial( "BaseWhiteNoLighting" );
            }
            else
            {
            	mCrowdMembers[j].mpBillboard->setRenderQueueGroup( CROWD_FRONT_RENDER_QUEUE - mCrowdMembers[j].mRow );
            }
        }
    }
}