bool WindowsManager::addSquareFace (const char* faceNameCorba,
            const value_type* posCorba1,
            const value_type* posCorba2,
            const value_type* posCorba3,
            const value_type* posCorba4,
            const value_type* colorCorba)
    {
        std::string faceName (faceNameCorba);
        if (nodes_.find (faceName) != nodes_.end ()) {
            std::cout << "You need to chose an other name, \"" << faceName
                << "\" already exist." << std::endl;
            return false;
        }
        else {
            mtx_.lock();
            osgVector3 pos1 (posCorba1[0], posCorba1[1], posCorba1[2]);
            osgVector3 pos2 (posCorba2[0], posCorba2[1], posCorba2[2]);
            osgVector3 pos3 (posCorba3[0], posCorba3[1], posCorba3[2]);
            osgVector3 pos4 (posCorba4[0], posCorba4[1], posCorba4[2]);
            LeafNodeFacePtr_t face = LeafNodeFace::create
                (faceName, pos1, pos2, pos3, pos3, getColor (colorCorba));
            WindowsManager::initParent (faceName, face);
            addNode (faceName, face);
	    mtx_.unlock();
            return true;
        }
    }
Esempio n. 2
0
void test_panning_sine_mix() {
	Sine vox1(431);				// sine osc
	Sine pos1(0.5);				// sine LFO for panner
//	Panner pan1(&vox1, -1.0, 0.1);	// scaling panner
	Panner pan1(vox1, pos1, 0.1);		// scaling panner
	Sine vox2(170);
	Sine pos2(0.3);
//	Panner pan2(&vox2, -0.3, 0.1);
	Panner pan2(vox2, pos2, 0.1);
	Sine vox3(267);
	Sine pos3(0.4);
//	Panner pan3(&vox3, 0.3, 0.1);
	Panner pan3(vox3, pos3, 0.1);
	Sine vox4(224);
	Sine pos4(0.7);
//	Panner pan4(&vox4, 1.0, 0.1);
	Panner pan4(vox4, pos4, 0.1);
	Mixer mix(2);				// create a stereo mixer
	mix.add_input(pan1);			// add the panners to the mixer
	mix.add_input(pan2);
	mix.add_input(pan3);
	mix.add_input(pan4);
	logMsg("playing panning mix of 4 sines...");
	run_test(mix, 9);
	logMsg("mix done.");
}
Esempio n. 3
0
TEST(ALPose2DTest, getAngle)
{
  const float eps = 1e-4f;
  AL::Math::Pose2D pos1(1.5f, 0.0f, 0.0f);
  EXPECT_NEAR(pos1.getAngle(), 0.0f, eps);

  AL::Math::Pose2D pos2(1.5f, 0.0f, 2.0f);
  EXPECT_NEAR(pos2.getAngle(), 0.0f, eps);

  AL::Math::Pose2D pos3(1.0f, -1.0f, 2.0f);
  EXPECT_NEAR(pos3.getAngle(), -AL::Math::PI_4, eps);

  AL::Math::Pose2D pos4(0.0f, 1.0f, 1.0f);
  EXPECT_NEAR(pos4.getAngle(), AL::Math::PI_2, eps);

  AL::Math::Pose2D pos5(-2.0f, 1.0f, 2.0f);
  EXPECT_NEAR(pos5.getAngle(), 2.67792f, eps);
}
/**
 * This test does round-trip testing (format -> parse -> format -> parse -> etc.) of
 * NumberFormat.
 */
void IntlTestNumberFormatAPI::testAPI(/* char* par */)
{
    UErrorCode status = U_ZERO_ERROR;

// ======= Test constructors

    logln("Testing NumberFormat constructors");

    NumberFormat *def = NumberFormat::createInstance(status);
    if(U_FAILURE(status)) {
        errln("ERROR: Could not create NumberFormat (default)");
    }

    status = U_ZERO_ERROR;
    NumberFormat *fr = NumberFormat::createInstance(Locale::getFrench(), status);
    if(U_FAILURE(status)) {
        errln("ERROR: Could not create NumberFormat (French)");
    }

    NumberFormat *cur = NumberFormat::createCurrencyInstance(status);
    if(U_FAILURE(status)) {
        errln("ERROR: Could not create NumberFormat (currency, default)");
    }

    status = U_ZERO_ERROR;
    NumberFormat *cur_fr = NumberFormat::createCurrencyInstance(Locale::getFrench(), status);
    if(U_FAILURE(status)) {
        errln("ERROR: Could not create NumberFormat (currency, French)");
    }

    NumberFormat *per = NumberFormat::createPercentInstance(status);
    if(U_FAILURE(status)) {
        errln("ERROR: Could not create NumberFormat (percent, default)");
    }

    status = U_ZERO_ERROR;
    NumberFormat *per_fr = NumberFormat::createPercentInstance(Locale::getFrench(), status);
    if(U_FAILURE(status)) {
        errln("ERROR: Could not create NumberFormat (percent, French)");
    }

// ======= Test equality
    if (per_fr != NULL && cur_fr != NULL)
    {
        logln("Testing equality operator");

        if( *per_fr == *cur_fr || ! ( *per_fr != *cur_fr) ) {
            errln("ERROR: == failed");
        }
    }

// ======= Test various format() methods
    if (cur_fr != NULL)
    {
        logln("Testing various format() methods");

        double d = -10456.0037;
        int32_t l = 100000000;
        Formattable fD(d);
        Formattable fL(l);

        UnicodeString res1, res2, res3, res4, res5, res6;
        FieldPosition pos1(0), pos2(0), pos3(0), pos4(0);

        res1 = cur_fr->format(d, res1);
        logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res1);

        res2 = cur_fr->format(l, res2);
        logln((UnicodeString) "" + (int32_t) l + " formatted to " + res2);

        res3 = cur_fr->format(d, res3, pos1);
        logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res3);

        res4 = cur_fr->format(l, res4, pos2);
        logln((UnicodeString) "" + (int32_t) l + " formatted to " + res4);

        status = U_ZERO_ERROR;
        res5 = cur_fr->format(fD, res5, pos3, status);
        if(U_FAILURE(status)) {
            errln("ERROR: format(Formattable [double]) failed");
        }
        logln((UnicodeString) "" + (int32_t) fD.getDouble() + " formatted to " + res5);

        status = U_ZERO_ERROR;
        res6 = cur_fr->format(fL, res6, pos4, status);
        if(U_FAILURE(status)) {
            errln("ERROR: format(Formattable [long]) failed");
        }
        logln((UnicodeString) "" + fL.getLong() + " formatted to " + res6);
    }

// ======= Test parse()
    if (fr != NULL)
    {
        logln("Testing parse()");

        double d = -10456.0037;
        UnicodeString text("-10,456.0037");
        Formattable result1, result2, result3;
        ParsePosition pos(0), pos01(0);
        fr->parseObject(text, result1, pos);
        if(result1.getType() != Formattable::kDouble && result1.getDouble() != d) {
            errln("ERROR: Roundtrip failed (via parse()) for " + text);
        }
        logln(text + " parsed into " + (int32_t) result1.getDouble());

        fr->parse(text, result2, pos01);
        if(result2.getType() != Formattable::kDouble && result2.getDouble() != d) {
            errln("ERROR: Roundtrip failed (via parse()) for " + text);
        }
        logln(text + " parsed into " + (int32_t) result2.getDouble());

        status = U_ZERO_ERROR;
        fr->parse(text, result3, status);
        if(U_FAILURE(status)) {
            errln("ERROR: parse() failed");
        }
        if(result3.getType() != Formattable::kDouble && result3.getDouble() != d) {
            errln("ERROR: Roundtrip failed (via parse()) for " + text);
        }
        logln(text + " parsed into " + (int32_t) result3.getDouble());
    }

// ======= Test getters and setters
    if (fr != NULL && def != NULL)
    {
        logln("Testing getters and setters");

        int32_t count = 0;
        const Locale *locales = NumberFormat::getAvailableLocales(count);
        logln((UnicodeString) "Got " + count + " locales" );
        for(int32_t i = 0; i < count; i++) {
            UnicodeString name(locales[i].getName(),"");
            logln(name);
        }

        fr->setParseIntegerOnly( def->isParseIntegerOnly() );
        if(fr->isParseIntegerOnly() != def->isParseIntegerOnly() ) {
            errln("ERROR: setParseIntegerOnly() failed");
        }

        fr->setGroupingUsed( def->isGroupingUsed() );
        if(fr->isGroupingUsed() != def->isGroupingUsed() ) {
            errln("ERROR: setGroupingUsed() failed");
        }

        fr->setMaximumIntegerDigits( def->getMaximumIntegerDigits() );
        if(fr->getMaximumIntegerDigits() != def->getMaximumIntegerDigits() ) {
            errln("ERROR: setMaximumIntegerDigits() failed");
        }

        fr->setMinimumIntegerDigits( def->getMinimumIntegerDigits() );
        if(fr->getMinimumIntegerDigits() != def->getMinimumIntegerDigits() ) {
            errln("ERROR: setMinimumIntegerDigits() failed");
        }

        fr->setMaximumFractionDigits( def->getMaximumFractionDigits() );
        if(fr->getMaximumFractionDigits() != def->getMaximumFractionDigits() ) {
            errln("ERROR: setMaximumFractionDigits() failed");
        }

        fr->setMinimumFractionDigits( def->getMinimumFractionDigits() );
        if(fr->getMinimumFractionDigits() != def->getMinimumFractionDigits() ) {
            errln("ERROR: setMinimumFractionDigits() failed");
        }
    }

// ======= Test getStaticClassID()

    logln("Testing getStaticClassID()");

    status = U_ZERO_ERROR;
    NumberFormat *test = new DecimalFormat(status);
    if(U_FAILURE(status)) {
        errln("ERROR: Couldn't create a NumberFormat");
    }

    if(test->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
        errln("ERROR: getDynamicClassID() didn't return the expected value");
    }

    delete test;
    delete def;
    delete fr;
    delete cur;
    delete cur_fr;
    delete per;
    delete per_fr;
}
Esempio n. 5
0
void UpgradeUILayer::createWeaponUI()
{
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    auto bk = Scale9Sprite::create("helpCellBG.png");
    auto bkSize = panelSize - Size(30,150);
    bk->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    bk->setPosition(Point(panelSize.width/2,panelSize.height-70));
    bk->setContentSize(bkSize);
    _panel->addChild(bk);
    
    Point pos1(60,bkSize.height/2+95);
    Point pos2(220,bkSize.height/2+95);
    Point pos3(350,bkSize.height/2+95);
    Point pos4(400,bkSize.height/2+95);
    Point offset(0,-50);
    
    auto level_text = TextSprite::create(s_gameStrings.base->upgradeLevel,GameConfig::defaultFontName,fontSize);
    level_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_text->setPosition(pos1);
    bk->addChild(level_text);
    
    auto level_before = TextSprite::create(Value(s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1).asString(),GameConfig::defaultFontName,fontSize);
    level_before->setColor(infoColor);
    level_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_before->setPosition(pos2);
    bk->addChild(level_before);
    
    auto arrow_upgrade_0 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_0->setPosition(pos3);
    bk->addChild(arrow_upgrade_0);
    
    auto level_after = TextSprite::create(Value(s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+2).asString(),GameConfig::defaultFontName,fontSize);
    level_after->setColor(infoColor);
    level_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_after->setPosition(pos4);
    bk->addChild(level_after);
    
    auto attack_text = TextSprite::create(s_gameStrings.base->upgradeAtt,GameConfig::defaultFontName,fontSize);
    attack_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_text->setPosition(pos1+offset);
    bk->addChild(attack_text);
    
    auto attack_before = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_before->setColor(infoColor);
    attack_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_before->setPosition(pos2+offset);
    bk->addChild(attack_before);
    
    auto arrow_upgrade_1 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_1->setPosition(pos3+offset*1);
    bk->addChild(arrow_upgrade_1);
    
    auto attack_after = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_after->setColor(infoColor);
    attack_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_after->setPosition(pos4+offset);
    bk->addChild(attack_after);
    
    auto duration_text = TextSprite::create(s_gameStrings.base->upgradeDuration,GameConfig::defaultFontName,fontSize);
    duration_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    duration_text->setPosition(pos1+offset*2);
    bk->addChild(duration_text);
    
    char p[30];
    float duration_before_data = s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].duration;
    sprintf(p, "%.2f",duration_before_data);
    auto duration_before = TextSprite::create(p,GameConfig::defaultFontName,fontSize);
    duration_before->setColor(infoColor);
    duration_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    duration_before->setPosition(pos2+offset*2);
    bk->addChild(duration_before);
    
    auto arrow_upgrade_2 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_2->setPosition(pos3+offset*2);
    bk->addChild(arrow_upgrade_2);
    
    float duration_after_data = s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].duration;
    sprintf(p, "%.2f",duration_after_data);
    auto duration_after = TextSprite::create(p,GameConfig::defaultFontName,fontSize);
    duration_after->setColor(infoColor);
    duration_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    duration_after->setPosition(pos4+offset*2);
    bk->addChild(duration_after);
    
    auto buyusegem_text = TextSprite::create(s_gameStrings.base->buyusegem,GameConfig::defaultFontName,fontSize);
    buyusegem_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buyusegem_text->setPosition(pos1+offset*3);
    bk->addChild(buyusegem_text);
    
    auto buyusegem_before = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].costGem).asString(),GameConfig::defaultFontName,fontSize);
    buyusegem_before->setColor(infoColor);
    buyusegem_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buyusegem_before->setPosition(pos2+offset*3);
    bk->addChild(buyusegem_before);
    
    auto arrow_upgrade_3 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_3->setPosition(pos3+offset*3);
    bk->addChild(arrow_upgrade_3);
    
    auto buyusegem_after = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].costGem).asString(),GameConfig::defaultFontName,fontSize);
    buyusegem_after->setColor(infoColor);
    buyusegem_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buyusegem_after->setPosition(pos4+offset*3);
    bk->addChild(buyusegem_after);
    
    auto buymax_text = TextSprite::create(s_gameStrings.base->buymax,GameConfig::defaultFontName,fontSize);
    buymax_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buymax_text->setPosition(pos1+offset*4);
    bk->addChild(buymax_text);
    
    auto buymax_before = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]].capacity).asString(),GameConfig::defaultFontName,fontSize);
    buymax_before->setColor(infoColor);
    buymax_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buymax_before->setPosition(pos2+offset*4);
    bk->addChild(buymax_before);
    
    auto arrow_upgrade_4 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_4->setPosition(pos3+offset*4);
    bk->addChild(arrow_upgrade_4);
    
    auto buymax_after = TextSprite::create(Value(s_weaponConfigs[_index-FIGHTER_MAX][s_playerConfig.weaponslevel[_index-FIGHTER_MAX]+1].capacity).asString(),GameConfig::defaultFontName,fontSize);
    buymax_after->setColor(infoColor);
    buymax_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    buymax_after->setPosition(pos4+offset*4);
    bk->addChild(buymax_after);

}
Esempio n. 6
0
void UpgradeUILayer::createFlightUI()
{
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    auto bk = Scale9Sprite::create("helpCellBG.png");
    auto bkSize = panelSize - Size(30,150);
    bk->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    bk->setPosition(Point(panelSize.width/2,panelSize.height-70));
    bk->setContentSize(bkSize);
    _panel->addChild(bk);
    
    Point pos1(80,bkSize.height/2+120);
    Point pos2(260,bkSize.height/2+120);
    Point pos3(360,bkSize.height/2+120);
    Point pos4(400,bkSize.height/2+120);
    Point offset(0,-40);
    
    auto level_text = TextSprite::create(s_gameStrings.base->upgradeLevel,GameConfig::defaultFontName,fontSize);
    level_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_text->setPosition(pos1);
    bk->addChild(level_text);
    
    auto level_before = TextSprite::create(Value(s_playerConfig.fighterslevel[_index]+1).asString(),GameConfig::defaultFontName,fontSize);
    level_before->setColor(infoColor);
    level_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_before->setPosition(pos2);
    bk->addChild(level_before);
    
    auto arrow_upgrade_0 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_0->setPosition(pos3);
    bk->addChild(arrow_upgrade_0);
    
    auto level_after = TextSprite::create(Value(s_playerConfig.fighterslevel[_index]+2).asString(),GameConfig::defaultFontName,fontSize);
    level_after->setColor(infoColor);
    level_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_after->setPosition(pos4);
    bk->addChild(level_after);
    
    auto life_text = TextSprite::create(s_gameStrings.base->upgradeLife,GameConfig::defaultFontName,fontSize);
    life_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    life_text->setPosition(pos1+offset);
    bk->addChild(life_text);
    
    auto life_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].life).asString(),GameConfig::defaultFontName,fontSize);
    life_before->setColor(infoColor);
    life_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    life_before->setPosition(pos2+offset);
    bk->addChild(life_before);
    
    auto arrow_upgrade_1 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_1->setPosition(pos3+offset);
    bk->addChild(arrow_upgrade_1);
    
    auto life_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].life).asString(),GameConfig::defaultFontName,fontSize);
    life_after->setColor(infoColor);
    life_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    life_after->setPosition(pos4+offset);
    bk->addChild(life_after);
    
    auto attack_text = TextSprite::create(s_gameStrings.base->upgradeAtt,GameConfig::defaultFontName,fontSize);
    attack_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_text->setPosition(pos1+offset*2);
    bk->addChild(attack_text);
    
    auto attack_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_before->setColor(infoColor);
    attack_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_before->setPosition(pos2+offset*2);
    bk->addChild(attack_before);
    
    auto arrow_upgrade_2 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_2->setPosition(pos3+offset*2);
    bk->addChild(arrow_upgrade_2);
    
    auto attack_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].attack).asString(),GameConfig::defaultFontName,fontSize);
    attack_after->setColor(infoColor);
    attack_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    attack_after->setPosition(pos4+offset*2);
    bk->addChild(attack_after);
    
    auto defense_text = TextSprite::create(s_gameStrings.base->upgradeDef,GameConfig::defaultFontName,fontSize);
    defense_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    defense_text->setPosition(pos1+offset*3);
    bk->addChild(defense_text);
    
    auto defense_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].defense).asString(),GameConfig::defaultFontName,fontSize);
    defense_before->setColor(infoColor);
    defense_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    defense_before->setPosition(pos2+offset*3);
    bk->addChild(defense_before);
    
    auto arrow_upgrade_3 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_3->setPosition(pos3+offset*3);
    bk->addChild(arrow_upgrade_3);
    
    auto defense_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].defense).asString(),GameConfig::defaultFontName,fontSize);
    defense_after->setColor(infoColor);
    defense_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    defense_after->setPosition(pos4+offset*3);
    bk->addChild(defense_after);
    
    auto speed_text = TextSprite::create(s_gameStrings.base->upgradeSpd,GameConfig::defaultFontName,fontSize);
    speed_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    speed_text->setPosition(pos1+offset*4);
    bk->addChild(speed_text);
    
    auto speed_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].speed).asString(),GameConfig::defaultFontName,fontSize);
    speed_before->setColor(infoColor);
    speed_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    speed_before->setPosition(pos2+offset*4);
    bk->addChild(speed_before);
    
    auto arrow_upgrade_4 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_4->setPosition(pos3+offset*4);
    bk->addChild(arrow_upgrade_4);
    
    auto speed_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].speed).asString(),GameConfig::defaultFontName,fontSize);
    speed_after->setColor(infoColor);
    speed_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    speed_after->setPosition(pos4+offset*4);
    bk->addChild(speed_after);

    auto range_text = TextSprite::create(s_gameStrings.base->upgradeRange,GameConfig::defaultFontName,fontSize);
    range_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    range_text->setPosition(pos1+offset*5);
    bk->addChild(range_text);
    
    auto range_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].range).asString(),GameConfig::defaultFontName,fontSize);
    range_before->setColor(infoColor);
    range_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    range_before->setPosition(pos2+offset*5);
    bk->addChild(range_before);
    
    auto arrow_upgrade_5 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_5->setPosition(pos3+offset*5);
    bk->addChild(arrow_upgrade_5);
    
    auto range_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].range).asString(),GameConfig::defaultFontName,fontSize);
    range_after->setColor(infoColor);
    range_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    range_after->setPosition(pos4+offset*5);
    bk->addChild(range_after);
    
    auto usestone_text = TextSprite::create(s_gameStrings.base->useStone,GameConfig::defaultFontName,fontSize);
    usestone_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    usestone_text->setPosition(pos1+offset*6);
    bk->addChild(usestone_text);
    
    auto usestone_before = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]].sparForMake).asString(),GameConfig::defaultFontName,fontSize);
    usestone_before->setColor(infoColor);
    usestone_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    usestone_before->setPosition(pos2+offset*6);
    bk->addChild(usestone_before);
    
    auto arrow_upgrade_6 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_6->setPosition(pos3+offset*6);
    bk->addChild(arrow_upgrade_6);
    
    auto usestone_after = TextSprite::create(Value(s_plainConfigs[_index][s_playerConfig.fighterslevel[_index]+1].sparForMake).asString(),GameConfig::defaultFontName,fontSize);
    usestone_after->setColor(infoColor);
    usestone_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    usestone_after->setPosition(pos4+offset*6);
    bk->addChild(usestone_after);
}
Esempio n. 7
0
void UpgradeUILayer::createStoneMaxUI()
{
    std::string fontFile = "DS-Digital.ttf";//"arial.ttf";
    int fontSize = 25;
    auto infoColor = DIY_COLOR_BLUE5;
    
    auto bk = Scale9Sprite::create("helpCellBG.png");
    auto bkSize = panelSize - Size(30,150);
    bk->setAnchorPoint(Point::ANCHOR_MIDDLE_TOP);
    bk->setPosition(Point(panelSize.width/2,panelSize.height-70));
    bk->setContentSize(bkSize);
    _panel->addChild(bk);
    
    Point pos1(60,bkSize.height/2+80);
    Point pos2(260,bkSize.height/2+80);
    Point pos3(360,bkSize.height/2+80);
    Point pos4(400,bkSize.height/2+80);
    Point offset(0,-70);
    
    auto level_text = TextSprite::create(s_gameStrings.base->upgradeLevel,GameConfig::defaultFontName,fontSize);
    level_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_text->setPosition(pos1);
    bk->addChild(level_text);
    
    auto level_before = TextSprite::create(Value(s_playerConfig.stonecapacitylevel+1).asString(),GameConfig::defaultFontName,fontSize);
    level_before->setColor(infoColor);
    level_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_before->setPosition(pos2);
    bk->addChild(level_before);
    
    auto arrow_upgrade_0 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_0->setPosition(pos3);
    bk->addChild(arrow_upgrade_0);
    
    auto level_after = TextSprite::create(Value(s_playerConfig.stonecapacitylevel+2).asString(),GameConfig::defaultFontName,fontSize);
    level_after->setColor(infoColor);
    level_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    level_after->setPosition(pos4);
    bk->addChild(level_after);
    
    auto init_text = TextSprite::create(s_gameStrings.base->stoneinit,GameConfig::defaultFontName,fontSize);
    init_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    init_text->setPosition(pos1+offset);
    bk->addChild(init_text);
    
    auto init_before = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel].initstone).asString(),GameConfig::defaultFontName,fontSize);
    init_before->setColor(infoColor);
    init_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    init_before->setPosition(pos2+offset);
    bk->addChild(init_before);
    
    auto arrow_upgrade_1 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_1->setPosition(pos3+offset);
    bk->addChild(arrow_upgrade_1);
    
    auto init_after = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel+1].initstone).asString(),GameConfig::defaultFontName,fontSize);
    init_after->setColor(infoColor);
    init_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    init_after->setPosition(pos4+offset);
    bk->addChild(init_after);
    
    auto max_text = TextSprite::create(s_gameStrings.base->stonemax,GameConfig::defaultFontName,fontSize);
    max_text->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    max_text->setPosition(pos1+offset*2);
    bk->addChild(max_text);
    
    auto max_before = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel].maxstone).asString(),GameConfig::defaultFontName,fontSize);
    max_before->setColor(infoColor);
    max_before->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    max_before->setPosition(pos2+offset*2);
    bk->addChild(max_before);
    
    auto arrow_upgrade_2 = Sprite::create("upgrade_arrow.png");
    arrow_upgrade_2->setPosition(pos3+offset*2);
    bk->addChild(arrow_upgrade_2);
    
    auto max_after = TextSprite::create(Value(s_stoneCapacity[s_playerConfig.stonecapacitylevel+1].maxstone).asString(),GameConfig::defaultFontName,fontSize);
    max_after->setColor(infoColor);
    max_after->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
    max_after->setPosition(pos4+offset*2);
    bk->addChild(max_after);

}
void EntryExitEvaluator::process(FrameList &frames)
{
    frameCount++;
    if (frameCount > numberOfFrames) {
        return;
    }

    std::vector<inOutEvent> inOut;
    for (std::vector<CameraObject>::size_type i = 0; i < frames.getCurrent().getCameras().size(); i++) {
        inOutEvent temp;
        temp.in = 0;
        temp.out = 0;
        inOut.push_back(temp);
    }

    // Save the values for entry and exit
    for (std::vector<CameraObject>::size_type i = 0; i < frames.getCurrent().getCameras().size(); i++) {
        // getEntered/getExited is the sum of all entrys and exits.
        inOut[i].in = frames.getCurrent().getCameras()[i].getEntered() - prevEntered[i];
        inOut[i].out = frames.getCurrent().getCameras()[i].getExited() - prevExited[i];

        // Save current values for next iteration
        prevEntered[i] = frames.getCurrent().getCameras()[i].getEntered();
        prevExited[i] = frames.getCurrent().getCameras()[i].getExited();



        // Sum ground truth enties and exits
        sumEntryGT[i] = sumEntryGT[i] + groundTruth[i][frameCount].in;
        sumExitGT[i] = sumExitGT[i] + groundTruth[i][frameCount].out;

        //---------- Save data -----------
        if(save == 10) {
        saveAccuracyToFile(prevEntered[i], "/Users/erikfall/Desktop/entMeas.csv");
        saveAccuracyToFile(prevExited[i], "/Users/erikfall/Desktop/exiMeas.csv");

        saveAccuracyToFile(sumEntryGT[i], "/Users/erikfall/Desktop/entryGT.csv");
        saveAccuracyToFile(sumExitGT[i], "/Users/erikfall/Desktop/exitGT.csv");
        //--------------------------------
        }


        //Accuracy computation
        if(sumEntryGT[i] != 0 && sumExitGT[i] != 0){
            accuracyTot = 1 - float(std::abs(frames.getCurrent().getCameras()[i].getEntered()-
                                             frames.getCurrent().getCameras()[i].getExited()-
                                             (sumEntryGT[i]-sumExitGT[i])))/(sumEntryGT[i]+sumExitGT[i]);
            accuracyIn  = 1 - float(std::abs(frames.getCurrent().getCameras()[i].getEntered()-sumEntryGT[i])) / sumEntryGT[i];
            accuracyOut = 1 - float(std::abs(frames.getCurrent().getCameras()[i].getExited()-sumExitGT[i])) / sumExitGT[i];

            diffEntries[i]       = sumEntryGT[i] - frames.getCurrent().getCameras()[i].getEntered();
            diffExits[i]         = sumExitGT[i] - frames.getCurrent().getCameras()[i].getExited();
            diffTotalOfPeople[i] = (sumEntryGT[i] - sumExitGT[i])-
                    (frames.getCurrent().getCameras()[i].getEntered() - frames.getCurrent().getCameras()[i].getExited());


            // Debug, print entry and exit information on the image.
            if(frames.getCurrent().getCameras()[i].hasImage("debugImage"))
            {
                cv::Mat debugIm = frames.getCurrent().getCameras()[i].getImage("debugImage");
                std::string accIn = "";
                std::string accOut = "";
                std::string accTotDiff = "";
                std::string GTIn = "";
                std::string GTOut = "";
                std::string GTTotal = "";

                int fontFace     = cv::FONT_HERSHEY_PLAIN;
                double fontScale = 1;
                int thickness    = 1;

                cv::Point2d pos1(430,15);
                cv::Point2d pos2(430,35);
                cv::Point2d pos3(430,55);
                cv::Point2d pos4(140,20);
                cv::Point2d pos5(140,40);
                cv::Point2d pos6(140,60);

                accIn      = "Accuracy In:      " + std::to_string(int(round(accuracyIn*100))) + " %";
                accOut     = "Accuracy Out:     " + std::to_string(int(round(accuracyOut*100))) + " %";
                accTotDiff = "Accuracy TotDiff: " + std::to_string(int(round(accuracyTot*100))) + " %";
                GTIn       = "(" + std::to_string(sumEntryGT[i]) + ")";
                GTOut      = "(" + std::to_string(sumExitGT[i]) + ")";
                GTTotal    = "(" + std::to_string(sumEntryGT[i] - sumExitGT[i]) + ")";

                putText(debugIm, accIn,      pos1, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, accOut,     pos2, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, accTotDiff, pos3, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, GTIn,       pos4, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, GTOut,      pos5, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, GTTotal,    pos6, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
            }
        }

        if(save == 10) {
        saveAccuracyToFile(accuracyIn, "/Users/erikfall/Desktop/accuracyIn.csv");
        saveAccuracyToFile(accuracyOut, "/Users/erikfall/Desktop/accuracyOut.csv");
        saveAccuracyToFile(accuracyTot, "/Users/erikfall/Desktop/accuracyTot.csv");
        }
        if(save == 10) {
            save = 0;
        }
        ++ save;

    }
}
Esempio n. 9
0
// An Update() helper that draws the image.
void GameWindow::Draw()
{
    //make sure the Direct3D device is valid
    if (!m_d3ddev) return;

    //create pointer to the back buffer
    m_d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_Backbuffer);
	//if in game
	if(m_bInGame){
		//load sprite textures
		m_wPlayer.m_Texture = Load_Texture(m_wPlayer.m_Image);
		for(int i = 0; i < 7; i++){
			if(m_eAllEnemies[i].m_bOnScreen){
				m_eAllEnemies[i].m_Texture = Load_Texture(m_eAllEnemies[i].m_Image);
				m_eAllEnemies[i].m_HPTexture = Load_Texture(m_eAllEnemies[i].m_HPimg);
			}
		}
		for(int i = 0; i < 7; i++){
			if(m_pProjectileList[i].m_bOnScreen){
				m_pProjectileList[i].m_Texture = Load_Texture(m_pProjectileList[i].m_Image);
			}
		}
	}
    //start rendering
    if (m_d3ddev->BeginScene())
    {
		
        //draw m_Surface to the m_Backbuffer
		m_d3ddev->StretchRect(m_Surface, NULL, m_Backbuffer, NULL, D3DTEXF_NONE);
		//begin drawing sprites
		m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);
		//if in game
		if(m_bInGame){
			
			//Turn x and y into a vector. Eventually I will set all coordinates to be vectors
			D3DXVECTOR3 pos1(m_wPlayer.m_X, m_wPlayer.m_Y, 0);
			
			//draw player
			m_Sprite->Draw(m_wPlayer.m_Texture, NULL, NULL, &pos1, D3DCOLOR_XRGB(255,255,255));
			
			//draw player's spell icon
			m_wPlayer.m_Texture = Load_Texture(m_wPlayer.m_SpellImage);
			D3DXVECTOR3 spellpos(m_wPlayer.m_X+0.25f*m_wPlayer.m_Width, m_wPlayer.m_Y-48, 0);
			m_Sprite->Draw(m_wPlayer.m_Texture, NULL, NULL, &spellpos, D3DCOLOR_XRGB(255,255,255));
			
			//draw all enemies
			for(int i = 0; i < 7; i++){
				if(m_eAllEnemies[i].m_bOnScreen){
					D3DXVECTOR3 pos2(m_eAllEnemies[i].m_X, m_eAllEnemies[i].m_Y, 0);
					m_Sprite->Draw(m_eAllEnemies[i].m_Texture, NULL, NULL, &pos2, D3DCOLOR_XRGB(255,255,255));
					//draw hp icons
					D3DXVECTOR3 pos4(m_eAllEnemies[i].m_X, m_eAllEnemies[i].m_Y- 32, 0);
					m_Sprite->Draw(m_eAllEnemies[i].m_HPTexture, NULL, NULL, &pos4, D3DCOLOR_XRGB(255,255,255));
				}
			}
			
			//draw projectile spells 
			for(int i = 0; i < 10; i++){
				if(m_pProjectileList[i].m_bOnScreen){
					D3DXVECTOR3 pos3(m_pProjectileList[i].m_X, m_pProjectileList[i].m_Y, 0);
					m_Sprite->Draw(m_pProjectileList[i].m_Texture, NULL, NULL, &pos3, D3DCOLOR_XRGB(255,255,255));
				}
			}

			//draw powerups
			D3DXVECTOR3 pos5(m_pPowerup.m_X, m_pPowerup.m_Y, 0);
			m_Sprite->Draw(m_pPowerup.m_Texture, NULL, NULL, &pos5, D3DCOLOR_XRGB(255, 255, 255));
			//draw hp ui
			D3DXVECTOR3 HpPos(16, 684, 0);
			m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			if(m_wPlayer.m_Health > 1){
				D3DXVECTOR3 HpPos(48, 684, 0);
				m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			}
			if(m_wPlayer.m_Health > 2){
				D3DXVECTOR3 HpPos(80, 684, 0);
				m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			}
		}
		else{
			//write title
			m_Font->DrawTextA(NULL, "Snape Simulator 2012", -1, &m_rTitle, DT_RIGHT, D3DCOLOR_XRGB(0, 0, 70));
			//draw "press space to start" in center of screen
			D3DXVECTOR3 StartPos(356, 256, 0);
			m_Sprite->Draw(m_StartGameTexture, NULL, NULL, &StartPos, D3DCOLOR_XRGB(255, 255, 255));
		}
		//UI- draw scores
		std::stringstream ss;//create a stringstream
		ss << m_Score;//add number to the stream
		std::string j = ss.str();
		m_Font->DrawTextA(NULL, j.c_str(), -1, &m_rCurrScore, DT_RIGHT, D3DCOLOR_ARGB(255, 255, 255, 255));

		std::stringstream ss2;
		ss2 << m_Highscore;
		j = ss2.str();
		m_Font->DrawTextA(NULL, j.c_str(), -1, &m_rBest, DT_RIGHT, D3DCOLOR_ARGB(255, 255, 255, 255));

        //stop rendering
        m_Sprite->End();
		m_d3ddev->EndScene();
        m_d3ddev->Present(NULL, NULL, NULL, NULL);

	}
}
Esempio n. 10
0
void RenderQuad()
{
	if (quadVAO == 0)
	{
		// positions
		glm::vec3 pos1(-1.0, 1.0, 0.0);
		glm::vec3 pos2(-1.0, -1.0, 0.0);
		glm::vec3 pos3(1.0, -1.0, 0.0);
		glm::vec3 pos4(1.0, 1.0, 0.0);
		// texture coordinates
		glm::vec2 uv1(0.0, 1.0);
		glm::vec2 uv2(0.0, 0.0);
		glm::vec2 uv3(1.0, 0.0);
		glm::vec2 uv4(1.0, 1.0);
		// normal vector
		glm::vec3 nm(0.0, 0.0, 1.0);

		// calculate tangent/bitangent vectors of both triangles
		glm::vec3 tangent1, bitangent1;
		glm::vec3 tangent2, bitangent2;
		// - triangle 1
		glm::vec3 edge1 = pos2 - pos1;
		glm::vec3 edge2 = pos3 - pos1;
		glm::vec2 deltaUV1 = uv2 - uv1;
		glm::vec2 deltaUV2 = uv3 - uv1;

		GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);

		tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
		tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
		tangent1.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);
		tangent1 = glm::normalize(tangent1);

		bitangent1.x = f * (-deltaUV2.x * edge1.x + deltaUV1.x * edge2.x);
		bitangent1.y = f * (-deltaUV2.x * edge1.y + deltaUV1.x * edge2.y);
		bitangent1.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);
		bitangent1 = glm::normalize(bitangent1);

		// - triangle 2
		edge1 = pos3 - pos1;
		edge2 = pos4 - pos1;
		deltaUV1 = uv3 - uv1;
		deltaUV2 = uv4 - uv1;

		f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);

		tangent2.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
		tangent2.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
		tangent2.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);
		tangent2 = glm::normalize(tangent2);


		bitangent2.x = f * (-deltaUV2.x * edge1.x + deltaUV1.x * edge2.x);
		bitangent2.y = f * (-deltaUV2.x * edge1.y + deltaUV1.x * edge2.y);
		bitangent2.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);
		bitangent2 = glm::normalize(bitangent2);


		GLfloat quadVertices[] = {
			// Positions            // normal         // TexCoords  // Tangent                          // Bitangent
			pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x, uv1.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
			pos2.x, pos2.y, pos2.z, nm.x, nm.y, nm.z, uv2.x, uv2.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
			pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x, uv3.y, tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,

			pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x, uv1.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
			pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x, uv3.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
			pos4.x, pos4.y, pos4.z, nm.x, nm.y, nm.z, uv4.x, uv4.y, tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z
		};
		// Setup plane VAO
		glGenVertexArrays(1, &quadVAO);
		glGenBuffers(1, &quadVBO);
		glBindVertexArray(quadVAO);
		glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
		glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(GLfloat), (GLvoid*)0);
		glEnableVertexAttribArray(1);
		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
		glEnableVertexAttribArray(2);
		glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 14 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
		glEnableVertexAttribArray(3);
		glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(GLfloat), (GLvoid*)(8 * sizeof(GLfloat)));
		glEnableVertexAttribArray(4);
		glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 14 * sizeof(GLfloat), (GLvoid*)(11 * sizeof(GLfloat)));
	}
	glBindVertexArray(quadVAO);
	glDrawArrays(GL_TRIANGLES, 0, 6);
	glBindVertexArray(0);
}
void App::DisplayFrame(void) {
  glClearColor(0, 0, 0, 1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

  bullet.getWorld()->stepSimulation(1);
  glm::mat4 P =
      glm::perspective(50.0f, width / static_cast<float>(height), 1.0f, 500.0f);
  glm::mat4 M;
  glm::mat4 V = glm::lookAt(cameraposition, cameraposition + cameratarget,
                            glm::vec3(0.0f, 1.0f, 0.0f));

  glMatrixMode(GL_PROJECTION);
  glLoadMatrixf(glm::value_ptr(P));
  glMatrixMode(GL_MODELVIEW);

  M = glm::mat4(1.0f);
  glLoadMatrixf(glm::value_ptr(V));
  GLfloat ambient[] = { 0.1f, 0.1f, 0.1f, 1.0f };
  GLfloat diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
  glLightfv(GL_LIGHT0, GL_POSITION, lightpos.data());

  GLfloat ambient2[] = { 0.0f, 0.0f, 0.1f, 1.0f };
  GLfloat diffuse2[] = { 0.0f, 0.0f, 1.0f, 1.0f };
  GLfloat specular2[] = { 0.0f, 0.0f, 1.0f, 1.0f };
  glLightfv(GL_LIGHT1, GL_AMBIENT, ambient2);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2);
  glLightfv(GL_LIGHT1, GL_SPECULAR, specular2);
  glLightfv(GL_LIGHT1, GL_POSITION, lightpos2.data());
  glLoadMatrixf(glm::value_ptr(V * M));
  bullet.getWorld()->debugDrawWorld();
  int texturenr = 0;
  for (auto it = bullet.getGameObject().begin();
       it != bullet.getGameObject().end(); ++it) {

    texturenr = texturenr == 1 ? 0 : 1;
    glBindTexture(GL_TEXTURE_2D, texture[texturenr]);
    btTransform trans;
    (*it)->GetTransform(trans);
    M = glm::mat4(1.0f);
    glm::vec3 translate =
        glm::vec3(trans.getOrigin().getX(), trans.getOrigin().getY(),
                  trans.getOrigin().getZ());
    glm::mat4 T = glm::translate(M, translate);
    btMatrix3x3 rotMatrix = trans.getBasis();
    float z, y, x;
    rotMatrix.getEulerZYX(z, y, x);
    M = glm::rotate(T, x, glm::vec3(1.0f, 0.0f, 0.0f));
    M = glm::rotate(M, y, glm::vec3(0.0f, 1.0f, 0.0f));
    M = glm::rotate(M, z, glm::vec3(0.0f, 0.0f, 1.0f));

    glLoadMatrixf(glm::value_ptr(V * M));
    (*it)->DrawShape();
    if (shadowmode == false)
      continue;
    for(lightindex=0;lightindex<2;++lightindex){
    if (it == bullet.getGameObject().begin())
      continue;

    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(glm::value_ptr(V));
    std::vector<bool> visibleface;
    glm::vec3 light;
    if(lightindex==0)light = glm::vec3 (lightpos[0],lightpos[1],lightpos[2] );
    else light =glm::vec3 (lightpos2[0],lightpos2[1],lightpos2[2] );
    for (auto it = bullet.getSolidSphere().getVertices().begin();
         it != bullet.getSolidSphere().getVertices().end(); it += 3) {

      glm::vec4 pos4(*(it), *(it + 1), *(it + 2), 1);
      pos4 = T * pos4;
      glm::vec3 pos3(pos4.x, pos4.y, pos4.z);
      glm::vec3 lightvec = light - pos3;
      if (glm::dot(lightvec, (pos3 - translate) /
                                 bullet.getSolidSphere().getRadius()) > 0) {
        visibleface.push_back(true);
      } else {
        visibleface.push_back(false);
      }
    }

    {
      auto it = bullet.getSolidSphere().getVertices().begin();
      CircularAccess ca(visibleface);
      for (int i = 0; it != bullet.getSolidSphere().getVertices().end();
           ++i, it += 3) {
        if (ca[i - 1] != ca[i] /*|ca[i+1]!=ca[i]*/
            ||
            ca[i - bullet.getSolidSphere().getSectors()] != ca[i]
                /*||ca[i+bullet.getSolidSphere().getSectors()]!=ca[i]*/) {
          // if(ca[i]==true){
          glm::vec4 pos4(*(it), *(it + 1), *(it + 2), 1);
          pos4 = T * pos4;
          shadow.push_back(pos4.x);
          shadow.push_back(pos4.y);
          shadow.push_back(pos4.z);
        }
      }
      shadow.push_back(shadow[0]);
      shadow.push_back(shadow[1]);
      shadow.push_back(shadow[2]);
      visibleface.clear();
    }
    if (shadow.empty() != true) {
      DrawShadow();
    }
  }
  }
  glutSwapBuffers();

}
Esempio n. 12
0
void Result::showResultLose(int score){
	int left = -320;
	int right = 320;
	int top = 240;
	int bot = -240;
	char strbuffer[64];
	// L
	Point pol1(left+60,top-80);
	Point pol2(left+60,bot+220);
	Point pol3(left+180,bot+220);
	Point pol4(left+180,bot+270);
	Point pol5(left+110,bot+270);
	Point pol6(left+110,top-80);
	Point polc((pol1.x+pol3.x)/2,(pol1.y+pol3.y)/2);
	vector<Point> pol;
	pol.push_back(pol1);
	pol.push_back(pol2);
	pol.push_back(pol3);
	pol.push_back(pol4);
	pol.push_back(pol5);
	pol.push_back(pol6);
	if (firsttime){
		pol_l.setCorner(pol);
		pol_l.setCenter(polc);
		Transform scale = createScale(0.1, 0.1);
		pol_l.applyTransform(scale);
	}

	// O
	Point poo1(left+190,top-80);
	Point poo2(left+190,bot+220);
	Point poo3(left+310,bot+220);
	Point poo4(left+310,top-80);
	Point poo5(left+230,top-120);
	Point poo6(left+230,bot+260);
	Point poo7(left+270,bot+260);
	Point poo8(left+270,top-120);
	Point pooc((poo1.x+poo3.x)/2,(poo1.y+poo3.y)/2);
	vector<Point> poo, poov;
	poo.push_back(poo1);
	poo.push_back(poo2);
	poo.push_back(poo3);
	poo.push_back(poo4);
	poov.push_back(poo5);
	poov.push_back(poo6);
	poov.push_back(poo7);
	poov.push_back(poo8);
	if (firsttime){
		pol_o.setCorner(poo);
		pol_o.setCenter(pooc);
		pol_o1.setCorner(poov);
		pol_o1.setCenter(pooc);
		Transform scale = createScale(0.1, 0.1);
		pol_o.applyTransform(scale);
		pol_o1.applyTransform(scale);
	}
	// S
	Point pos1(left+320,top-80);
	Point pos2(left+320,top-190);
	Point pos3(left+410,top-190);
	Point pos4(left+410,top-220);
	Point pos5(left+320,top-220);
	Point pos6(left+320,top-260);
	Point pos7(left+450,top-260);
	Point pos8(left+450,top-150);
	Point pos9(left+360,top-150);
	Point pos10(left+360,top-120);
	Point pos11(left+450,top-120);
	Point pos12(left+450,top-80);
	Point posc((pos1.x+pos7.x)/2,(pos1.y+pos7.y)/2);
	vector<Point> pos;
	pos.push_back(pos1);
	pos.push_back(pos2);
	pos.push_back(pos3);
	pos.push_back(pos4);
	pos.push_back(pos5);
	pos.push_back(pos6);
	pos.push_back(pos7);
	pos.push_back(pos8);
	pos.push_back(pos9);
	pos.push_back(pos10);
	pos.push_back(pos11);
	pos.push_back(pos12);
	if (firsttime){
		pol_s.setCorner(pos);
		pol_s.setCenter(posc);
		Transform scale = createScale(0.1, 0.1);
		pol_s.applyTransform(scale);
	}
	

	// E
	Point poe1(left+460,top-80);
	Point poe2(left+460,bot+220);
	Point poe3(left+580,bot+220);
	Point poe4(left+580,bot+260);
	Point poe5(left+510,bot+260);
	Point poe6(left+510,bot+290);

	Point poe7(left+580,bot+220+70);
	Point poe8(left+580,bot+260+70);
	Point poe9(left+510,bot+260+70);
	Point poe10(left+510,bot+290+70);

	Point poe11(left+580,bot+220+140);
	Point poe12(left+580,bot+260+140);
	Point poec((poe1.x+poe3.x)/2,(poe1.y+poe3.y)/2);
	vector<Point> poe;
	poe.push_back(poe1);
	poe.push_back(poe2);
	poe.push_back(poe3);
	poe.push_back(poe4);
	poe.push_back(poe5);
	poe.push_back(poe6);
	poe.push_back(poe7);
	poe.push_back(poe8);
	poe.push_back(poe9);
	poe.push_back(poe10);
	poe.push_back(poe11);
	poe.push_back(poe12);
	if (firsttime){
		pol_e.setCorner(poe);
		pol_e.setCenter(poec);
		Transform scale = createScale(0.1, 0.1);
		pol_e.applyTransform(scale);
	}

	

	// Other
	Point pot1(left+60, top-40);
	Point pot2(right-60, top-40);
	Point pot3(right-60, top-60);
	Point pot4(left+60, top-60);
	Point potc((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2);
	vector<Point> pot;
	pot.push_back(pot1);
	pot.push_back(pot2);
	pot.push_back(pot3);
	pot.push_back(pot4);
	if (firsttime){
		pol_pot1.setCorner(pot);
		pol_pot1.setCenter(potc);
		Transform scale = createScale(0.1, 0.1);
		pol_pot1.applyTransform(scale);
	}
	

	pot1.set(left+60, bot+180);
	pot2.set(right-60, bot+180);
	pot3.set(right-60, bot+200);
	pot4.set(left+60, bot+200);
	potc.set((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2);
	pot.clear();
	pot.push_back(pot1);
	pot.push_back(pot2);
	pot.push_back(pot3);
	pot.push_back(pot4);
	if (firsttime){
		pol_pot2.setCorner(pot);
		pol_pot2.setCenter(potc);
		Transform scale = createScale(0.1, 0.1);
		pol_pot2.applyTransform(scale);
	}
	

	resultframe++;
	if (resultframe >= 25)
		resultframe = 25;
	else {
		Transform scale = createScale(1.1, 1.1);
		pol_pot1.applyTransform(scale);
		pol_pot2.applyTransform(scale);
		pol_l.applyTransform(scale);
		pol_o.applyTransform(scale);
		pol_o1.applyTransform(scale);
		pol_s.applyTransform(scale);
		pol_e.applyTransform(scale);
	}
	pol_l.draw(WHITE);
	fill_polygon(pol_l[0].x, pol_l[2].y, pol_l[2].x, pol_l[0].y,WHITE,WHITE);
	pol_o.draw(WHITE);
	fill_polygon(pol_o[0].x, pol_o[2].y, pol_o[2].x, pol_o[0].y,WHITE,WHITE);
	pol_o1.draw(BLACK);
	fill_polygon(pol_o1[0].x, pol_o1[2].y, pol_o1[2].x, pol_o1[0].y,BLACK,BLACK);	
	pol_s.draw(WHITE);
	fill_polygon(pol_s[0].x, pol_s[6].y, pol_s[6].x, pol_s[0].y,WHITE,WHITE);
	pol_e.draw(WHITE);
	fill_polygon(pol_e[0].x, pol_e[2].y, pol_e[2].x, pol_e[0].y,WHITE,WHITE);
	pol_pot1.draw(WHITE);
	pol_pot2.draw(WHITE);

	settextstyle(7,0,40);
	setcolor(WHITE);
	sprintf(strbuffer,"%d",score);
	outtextxy(getmaxx()/2-50, getmaxy()/2+100, strbuffer);
	firsttime = false;
}
Esempio n. 13
0
/**
 * This test checks various generic API methods in DecimalFormat to achieve 100%
 * API coverage.
 */
void IntlTestDecimalFormatAPI::testAPI(/*char *par*/)
{
    UErrorCode status = U_ZERO_ERROR;

// ======= Test constructors

    logln((UnicodeString)"Testing DecimalFormat constructors");

    DecimalFormat def(status);
    if(U_FAILURE(status)) {
        errcheckln(status, "ERROR: Could not create DecimalFormat (default) - %s", u_errorName(status));
        return;
    }

    // bug 10864
    status = U_ZERO_ERROR;
    DecimalFormat noGrouping("###0.##", status);
    if (noGrouping.getGroupingSize() != 0) {
      errln("Grouping size should be 0 for no grouping.");
    }
    // end bug 10864

    status = U_ZERO_ERROR;
    const UnicodeString pattern("#,##0.# FF");
    DecimalFormat pat(pattern, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern)");
        return;
    }

    status = U_ZERO_ERROR;
    DecimalFormatSymbols *symbols = new DecimalFormatSymbols(Locale::getFrench(), status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: Could not create DecimalFormatSymbols (French)");
        return;
    }

    status = U_ZERO_ERROR;
    DecimalFormat cust1(pattern, symbols, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols*)");
    }

    status = U_ZERO_ERROR;
    DecimalFormat cust2(pattern, *symbols, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: Could not create DecimalFormat (pattern, symbols)");
    }

    DecimalFormat copy(pat);

// ======= Test clone(), assignment, and equality

    logln((UnicodeString)"Testing clone(), assignment and equality operators");

    if( ! (copy == pat) || copy != pat) {
        errln((UnicodeString)"ERROR: Copy constructor or == failed");
    }

    copy = cust1;
    if(copy != cust1) {
        errln((UnicodeString)"ERROR: Assignment (or !=) failed");
    }

    Format *clone = def.clone();
    if( ! (*clone == def) ) {
        errln((UnicodeString)"ERROR: Clone() failed");
    }
    delete clone;

// ======= Test various format() methods

    logln((UnicodeString)"Testing various format() methods");

    double d = -10456.0037;
    int32_t l = 100000000;
    Formattable fD(d);
    Formattable fL(l);

    UnicodeString res1, res2, res3, res4;
    FieldPosition pos1(0), pos2(0), pos3(0), pos4(0);

    res1 = def.format(d, res1, pos1);
    logln( (UnicodeString) "" + (int32_t) d + " formatted to " + res1);

    res2 = pat.format(l, res2, pos2);
    logln((UnicodeString) "" + (int32_t) l + " formatted to " + res2);

    status = U_ZERO_ERROR;
    res3 = cust1.format(fD, res3, pos3, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: format(Formattable [double]) failed");
    }
    logln((UnicodeString) "" + (int32_t) fD.getDouble() + " formatted to " + res3);

    status = U_ZERO_ERROR;
    res4 = cust2.format(fL, res4, pos4, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: format(Formattable [long]) failed");
    }
    logln((UnicodeString) "" + fL.getLong() + " formatted to " + res4);

// ======= Test parse()

    logln((UnicodeString)"Testing parse()");

    UnicodeString text("-10,456.0037");
    Formattable result1, result2;
    ParsePosition pos(0);
    UnicodeString patt("#,##0.#");
    status = U_ZERO_ERROR;
    pat.applyPattern(patt, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: applyPattern() failed");
    }
    pat.parse(text, result1, pos);
    if(result1.getType() != Formattable::kDouble && result1.getDouble() != d) {
        errln((UnicodeString)"ERROR: Roundtrip failed (via parse()) for " + text);
    }
    logln(text + " parsed into " + (int32_t) result1.getDouble());

    status = U_ZERO_ERROR;
    pat.parse(text, result2, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: parse() failed");
    }
    if(result2.getType() != Formattable::kDouble && result2.getDouble() != d) {
        errln((UnicodeString)"ERROR: Roundtrip failed (via parse()) for " + text);
    }
    logln(text + " parsed into " + (int32_t) result2.getDouble());

// ======= Test getters and setters

    logln((UnicodeString)"Testing getters and setters");

    const DecimalFormatSymbols *syms = pat.getDecimalFormatSymbols();
    DecimalFormatSymbols *newSyms = new DecimalFormatSymbols(*syms);
    def.setDecimalFormatSymbols(*newSyms);
    def.adoptDecimalFormatSymbols(newSyms); // don't use newSyms after this
    if( *(pat.getDecimalFormatSymbols()) != *(def.getDecimalFormatSymbols())) {
        errln((UnicodeString)"ERROR: adopt or set DecimalFormatSymbols() failed");
    }

    UnicodeString posPrefix;
    pat.setPositivePrefix("+");
    posPrefix = pat.getPositivePrefix(posPrefix);
    logln((UnicodeString)"Positive prefix (should be +): " + posPrefix);
    if(posPrefix != "+") {
        errln((UnicodeString)"ERROR: setPositivePrefix() failed");
    }

    UnicodeString negPrefix;
    pat.setNegativePrefix("-");
    negPrefix = pat.getNegativePrefix(negPrefix);
    logln((UnicodeString)"Negative prefix (should be -): " + negPrefix);
    if(negPrefix != "-") {
        errln((UnicodeString)"ERROR: setNegativePrefix() failed");
    }

    UnicodeString posSuffix;
    pat.setPositiveSuffix("_");
    posSuffix = pat.getPositiveSuffix(posSuffix);
    logln((UnicodeString)"Positive suffix (should be _): " + posSuffix);
    if(posSuffix != "_") {
        errln((UnicodeString)"ERROR: setPositiveSuffix() failed");
    }

    UnicodeString negSuffix;
    pat.setNegativeSuffix("~");
    negSuffix = pat.getNegativeSuffix(negSuffix);
    logln((UnicodeString)"Negative suffix (should be ~): " + negSuffix);
    if(negSuffix != "~") {
        errln((UnicodeString)"ERROR: setNegativeSuffix() failed");
    }

    int32_t multiplier = 0;
    pat.setMultiplier(8);
    multiplier = pat.getMultiplier();
    logln((UnicodeString)"Multiplier (should be 8): " + multiplier);
    if(multiplier != 8) {
        errln((UnicodeString)"ERROR: setMultiplier() failed");
    }

    int32_t groupingSize = 0;
    pat.setGroupingSize(2);
    groupingSize = pat.getGroupingSize();
    logln((UnicodeString)"Grouping size (should be 2): " + (int32_t) groupingSize);
    if(groupingSize != 2) {
        errln((UnicodeString)"ERROR: setGroupingSize() failed");
    }

    pat.setDecimalSeparatorAlwaysShown(TRUE);
    UBool tf = pat.isDecimalSeparatorAlwaysShown();
    logln((UnicodeString)"DecimalSeparatorIsAlwaysShown (should be TRUE) is " + (UnicodeString) (tf ? "TRUE" : "FALSE"));
    if(tf != TRUE) {
        errln((UnicodeString)"ERROR: setDecimalSeparatorAlwaysShown() failed");
    }
    // Added by Ken Liu testing set/isExponentSignAlwaysShown
    pat.setExponentSignAlwaysShown(TRUE);
    UBool esas = pat.isExponentSignAlwaysShown();
    logln((UnicodeString)"ExponentSignAlwaysShown (should be TRUE) is " + (UnicodeString) (esas ? "TRUE" : "FALSE"));
    if(esas != TRUE) {
        errln((UnicodeString)"ERROR: ExponentSignAlwaysShown() failed");
    }

    // Added by Ken Liu testing set/isScientificNotation
    pat.setScientificNotation(TRUE);
    UBool sn = pat.isScientificNotation();
    logln((UnicodeString)"isScientificNotation (should be TRUE) is " + (UnicodeString) (sn ? "TRUE" : "FALSE"));
    if(sn != TRUE) {
        errln((UnicodeString)"ERROR: setScientificNotation() failed");
    }

    // Added by Ken Liu testing set/getMinimumExponentDigits
    int8_t MinimumExponentDigits = 0;
    pat.setMinimumExponentDigits(2);
    MinimumExponentDigits = pat.getMinimumExponentDigits();
    logln((UnicodeString)"MinimumExponentDigits (should be 2) is " + (int8_t) MinimumExponentDigits);
    if(MinimumExponentDigits != 2) {
        errln((UnicodeString)"ERROR: setMinimumExponentDigits() failed");
    }

    // Added by Ken Liu testing set/getRoundingIncrement
    double RoundingIncrement = 0.0;
    pat.setRoundingIncrement(2.0);
    RoundingIncrement = pat.getRoundingIncrement();
    logln((UnicodeString)"RoundingIncrement (should be 2.0) is " + (double) RoundingIncrement);
    if(RoundingIncrement != 2.0) {
        errln((UnicodeString)"ERROR: setRoundingIncrement() failed");
    }
    //end of Ken's Adding

    UnicodeString funkyPat;
    funkyPat = pat.toPattern(funkyPat);
    logln((UnicodeString)"Pattern is " + funkyPat);

    UnicodeString locPat;
    locPat = pat.toLocalizedPattern(locPat);
    logln((UnicodeString)"Localized pattern is " + locPat);

// ======= Test applyPattern()

    logln((UnicodeString)"Testing applyPattern()");

    UnicodeString p1("#,##0.0#;(#,##0.0#)");
    logln((UnicodeString)"Applying pattern " + p1);
    status = U_ZERO_ERROR;
    pat.applyPattern(p1, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: applyPattern() failed with " + (int32_t) status);
    }
    UnicodeString s2;
    s2 = pat.toPattern(s2);
    logln((UnicodeString)"Extracted pattern is " + s2);
    if(s2 != p1) {
        errln((UnicodeString)"ERROR: toPattern() result did not match pattern applied");
    }

    if(pat.getSecondaryGroupingSize() != 0) {
        errln("FAIL: Secondary Grouping Size should be 0, not %d\n", pat.getSecondaryGroupingSize());
    }

    if(pat.getGroupingSize() != 3) {
        errln("FAIL: Primary Grouping Size should be 3, not %d\n", pat.getGroupingSize());
    }

    UnicodeString p2("#,##,##0.0# FF;(#,##,##0.0# FF)");
    logln((UnicodeString)"Applying pattern " + p2);
    status = U_ZERO_ERROR;
    pat.applyLocalizedPattern(p2, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: applyPattern() failed with " + (int32_t) status);
    }
    UnicodeString s3;
    s3 = pat.toLocalizedPattern(s3);
    logln((UnicodeString)"Extracted pattern is " + s3);
    if(s3 != p2) {
        errln((UnicodeString)"ERROR: toLocalizedPattern() result did not match pattern applied");
    }

    status = U_ZERO_ERROR;
    UParseError pe;
    pat.applyLocalizedPattern(p2, pe, status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: applyPattern((with ParseError)) failed with " + (int32_t) status);
    }
    UnicodeString s4;
    s4 = pat.toLocalizedPattern(s3);
    logln((UnicodeString)"Extracted pattern is " + s4);
    if(s4 != p2) {
        errln((UnicodeString)"ERROR: toLocalizedPattern(with ParseErr) result did not match pattern applied");
    }

    if(pat.getSecondaryGroupingSize() != 2) {
        errln("FAIL: Secondary Grouping Size should be 2, not %d\n", pat.getSecondaryGroupingSize());
    }

    if(pat.getGroupingSize() != 3) {
        errln("FAIL: Primary Grouping Size should be 3, not %d\n", pat.getGroupingSize());
    }

// ======= Test getStaticClassID()

    logln((UnicodeString)"Testing getStaticClassID()");

    status = U_ZERO_ERROR;
    NumberFormat *test = new DecimalFormat(status);
    if(U_FAILURE(status)) {
        errln((UnicodeString)"ERROR: Couldn't create a DecimalFormat");
    }

    if(test->getDynamicClassID() != DecimalFormat::getStaticClassID()) {
        errln((UnicodeString)"ERROR: getDynamicClassID() didn't return the expected value");
    }

    delete test;
}
Esempio n. 14
0
// 建立矩形的VAO数据
void setupQuadVAO()
{
	// 顶点位置
	glm::vec3 pos1(-1.0, 1.0, 0.0);
	glm::vec3 pos2(-1.0, -1.0, 0.0);
	glm::vec3 pos3(1.0, -1.0, 0.0);
	glm::vec3 pos4(1.0, 1.0, 0.0);
	// 纹理坐标
	glm::vec2 uv1(0.0, 1.0);
	glm::vec2 uv2(0.0, 0.0);
	glm::vec2 uv3(1.0, 0.0);
	glm::vec2 uv4(1.0, 1.0);
	// 法向量
	glm::vec3 nm(0.0, 0.0, 1.0);

	// 计算两个三角形的TB向量
	glm::vec3 tangent1, bitangent1;
	glm::vec3 tangent2, bitangent2;
	// 三角形1
	glm::vec3 edge1 = pos2 - pos1;
	glm::vec3 edge2 = pos3 - pos1;
	glm::vec2 deltaUV1 = uv2 - uv1;
	glm::vec2 deltaUV2 = uv3 - uv1;

	GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);

	tangent1.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
	tangent1.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
	tangent1.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);
	tangent1 = glm::normalize(tangent1);

	bitangent1.x = f * (-deltaUV2.x * edge1.x + deltaUV1.x * edge2.x);
	bitangent1.y = f * (-deltaUV2.x * edge1.y + deltaUV1.x * edge2.y);
	bitangent1.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);
	bitangent1 = glm::normalize(bitangent1);

	// 三角形2
	edge1 = pos3 - pos1;
	edge2 = pos4 - pos1;
	deltaUV1 = uv3 - uv1;
	deltaUV2 = uv4 - uv1;

	f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);

	tangent2.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
	tangent2.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
	tangent2.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);
	tangent2 = glm::normalize(tangent2);


	bitangent2.x = f * (-deltaUV2.x * edge1.x + deltaUV1.x * edge2.x);
	bitangent2.y = f * (-deltaUV2.x * edge1.y + deltaUV1.x * edge2.y);
	bitangent2.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);
	bitangent2 = glm::normalize(bitangent2);

	// 每个三角形的TB向量提前计算出来 也可以由Geometry shader计算
	GLfloat quadVertices[] = {
		// 位置         // 法向量      // 纹理  // Tangent 向量  // Bitangent 向量
		pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x, uv1.y, 
		tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
		pos2.x, pos2.y, pos2.z, nm.x, nm.y, nm.z, uv2.x, uv2.y, 
		tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,
		pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x, uv3.y, 
		tangent1.x, tangent1.y, tangent1.z, bitangent1.x, bitangent1.y, bitangent1.z,

		pos1.x, pos1.y, pos1.z, nm.x, nm.y, nm.z, uv1.x, uv1.y, 
		tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
		pos3.x, pos3.y, pos3.z, nm.x, nm.y, nm.z, uv3.x, uv3.y, 
		tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z,
		pos4.x, pos4.y, pos4.z, nm.x, nm.y, nm.z, uv4.x, uv4.y, 
		tangent2.x, tangent2.y, tangent2.z, bitangent2.x, bitangent2.y, bitangent2.z
	};
	glGenVertexArrays(1, &quadVAOId);
	glGenBuffers(1, &quadVBOId);
	glBindVertexArray(quadVAOId);
	glBindBuffer(GL_ARRAY_BUFFER, quadVBOId);
	glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 
		14 * sizeof(GLfloat), (GLvoid*)0);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 
		14 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
	glEnableVertexAttribArray(2);
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 
		14 * sizeof(GLfloat), (GLvoid*)(6 * sizeof(GLfloat)));
	glEnableVertexAttribArray(3);
	glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 
		14 * sizeof(GLfloat), (GLvoid*)(8 * sizeof(GLfloat)));
	glEnableVertexAttribArray(4);
	glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE,
		14 * sizeof(GLfloat), (GLvoid*)(11 * sizeof(GLfloat)));
	glBindVertexArray(0);
}