Beispiel #1
0
//-----------------------------------------------------------------------------------------
bool CBillboardSetEditor::load(bool async)
{
    if(mLoaded->get())
        return true;
    
    if(CNodeEditor::load())
    {
        mBillboardSetHandle = mOgitorsRoot->GetSceneManager()->createBillboardSet(mName->get());
        mHandle->attachObject(mBillboardSetHandle);
        
        mBillboardSetHandle->setBillboardType((Ogre::BillboardType)mBillboardType->get());
        mBillboardSetHandle->setSortingEnabled(mSorting->get());
        mBillboardSetHandle->setBillboardOrigin((Ogre::BillboardOrigin)mOrigin->get());
        mBillboardSetHandle->setBillboardRotationType((Ogre::BillboardRotationType)mRotation->get());
        mBillboardSetHandle->setDefaultWidth(mDefaultWidth->get());
        mBillboardSetHandle->setDefaultHeight(mDefaultHeight->get());
        mBillboardSetHandle->setVisibilityFlags(1 << mLayer->get());
        if(mMaterial->get() != "")
            mBillboardSetHandle->setMaterialName(mMaterial->get());
        
        mBillboardSetHandle->setPointRenderingEnabled(mPointRendering->get());
        mBillboardSetHandle->setRenderingDistance(mRenderDistance->get());

        Ogre::Vector2 v2val;
        Ogre::Vector3 v3val;
        Ogre::Vector4 v4val;
        Ogre::ColourValue cval;
        Ogre::Real rval;
        int ival;
        Ogre::String propname;

        int count = mBillboardCount->get();
        for(int ix = 0;ix < count;ix++)
        {
            propname = "billboard" + Ogre::StringConverter::toString(ix);

            Ogre::Billboard *pBillboard = mBillboardSetHandle->createBillboard(Ogre::Vector3::ZERO);
            mProperties.getValue(propname + "::position", v3val);
            pBillboard->setPosition(v3val);
            mProperties.getValue(propname + "::colour", cval);
            pBillboard->setColour(cval);
            mProperties.getValue(propname + "::dimensions", v2val);
             pBillboard->setDimensions(v2val.x, v2val.y);
            mProperties.getValue(propname + "::rotation", rval);
            pBillboard->setRotation(Ogre::Degree(rval));
            mProperties.getValue(propname + "::texcoordindex", ival);
            pBillboard->setTexcoordIndex(ival);
            mProperties.getValue(propname + "::texrect", v4val);
            pBillboard->setTexcoordRect(v4val.x, v4val.y, v4val.z, v4val.w);
        }

    }
    else
        return false;

    return true;
}
Beispiel #2
0
void JumpTape::updateStateFrame(double simulation_frame_time) {
    mRuntime += simulation_frame_time;
    mKeyboard = dt::InputManager::get()->getKeyboard();
    double field_speed = mRuntime/1000; 
    
    // Move each tile. 
    for(uint8_t i=0; i<TILES; ++i) {
        Ogre::Billboard* tile = mTiles->getBillboard(i);
        tile->setPosition(tile->getPosition() - Ogre::Vector3(field_speed, 0, 0));
    }
    
    // Wheater the next tile should be blank or present.
    bool blank = _GetTileType();
    
    // Move the first tile at the end of the group if it went beyond left margin.
    static uint8_t i = 0; //  index for selecting the right tile.
    Ogre::Billboard* tile = mTiles->getBillboard(i);
    if(tile->getPosition().x < (-GAME_WITDH/2)-4) {
        // Get position of the last (precedent) tile.
        double last_tile_x = mTiles->getBillboard((i+TILES-1) % TILES)->getPosition().x;
        // Append billboard to end.
        tile->setPosition(last_tile_x+TILE_X, dt::Random::get(-3, 3), 0);
        tile->setTexcoordIndex(blank);
        i++; // Switch to next tile...
        i %= TILES; // ...in a cicle.
    }
    
    // Move player.
    // Player and tile variables.
    tile = mTiles->getBillboard((i+2) % TILES); // The tile on which the player is.
    static float jump_height = 0; // The height of each jump.
    static bool jump_allowed = false; // Jump is not allowed when the player is already on air.
    bool blank_tile = tile->getTexcoordIndex(); // Wheater the tile under the player is blank.
    Ogre::Vector3 player_pos = mPlayer->getPosition();
    Ogre::Vector3 tile_pos = tile->getPosition(); // Position of the tile under the player.
    
    // Jump.
    if(mKeyboard->isKeyDown(OIS::KC_SPACE) 
        && (jump_height < MAX_JUMP_HEIGHT) && jump_allowed) {
        player_pos += Ogre::Vector3(0, JUMP_POWER, 0);
        mPlayer->setPosition(player_pos);
        jump_height += JUMP_POWER;
    }
    else {
        jump_allowed = false; // Once the player release space he can't go up anymore.
    }
    
    
    float tile_top = tile_pos.y + TILE_Y * 2; // Top of the tile.
    // Wheater the player is running on the tile.
    bool on_tile = (player_pos.y <= tile_top+0.1) && (player_pos.y >= tile_top-0.1); 
    
    // Gravity.
    if((blank_tile || !on_tile) && !jump_allowed) {
        player_pos -= Ogre::Vector3(0, G_POWER, 0);
        mPlayer->setPosition(player_pos);
    }
    
    // Evaluate if jump is allowed.
    if(on_tile && !blank_tile) {
        jump_height = 0;
        jump_allowed = true;
        // The player is running, change animation.
        mPlayer->setTexcoordIndex(static_cast<uint8_t>(mRuntime*10) % PLAYER_FRAME);
    }
    
    // Reset game.
    if(mKeyboard->isKeyDown(OIS::KC_N)) {
        mRuntime=0;
        mPlayer->setPosition(mPlayer->getPosition().x, tile_pos.y+4, 0);
        tile->setTexcoordIndex(0);
    }
    
    // Show reset game info.
    static QString time;
    if(player_pos.y < -4) {
        mGameInfo->setText("You ran for " + time + " seconds, press N for a new game");
    }
    else {
        time = dt::Utils::toString(static_cast<uint32_t>(mRuntime));
        mGameInfo->setText("You ran for " + time + " seconds");
    }
}