Ejemplo n.º 1
0
bool ParticleHitEmitter::initWithTotalParticles(unsigned int numberOfPartiles)
{
	if (CCParticleSystemQuad::initWithTotalParticles(numberOfPartiles))
	{
		// duration
		m_fDuration = 0.1f;

		setEmitterMode(kCCParticleModeGravity);

		// Gravity Mode: gravity
		setGravity(ccp(0, 0));

		// Gravity Mode: speed of particles
		setSpeed(0);
		setSpeedVar(0);

		// Gravity Mode: radial
		setRadialAccel(0);
		setRadialAccelVar(0);

		// Gravity Mode: tangential
		setTangentialAccel(0);
		setTangentialAccelVar(0);

		// angle
		m_fAngle = 90;
		m_fAngleVar = 360;

		// emitter position
		CCSize winSize = CCDirector::sharedDirector()->getWinSize();
		this->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		setPosVar(CCPointZero);

		// life of particles
		m_fLife = 0.1f;
		m_fLifeVar = 0;

		// size, in pixels
		m_fStartSize = 100;
		m_fStartSizeVar = 0.0f;
		m_fEndSize = 300;

		// emits per second
		m_fEmissionRate = m_uTotalParticles / m_fDuration;
		//m_uTotalParticles = 50;
		// color of particles
		m_tStartColor.r = 1.0f;
		m_tStartColor.g = 1.0f;
		m_tStartColor.b = 1.0f;
		m_tStartColor.a = 1.0f;
		m_tStartColorVar.r = 0.0f;
		m_tStartColorVar.g = 0.0f;
		m_tStartColorVar.b = 0.0f;
		m_tStartColorVar.a = 0.0f;
		m_tEndColor.r = 1.0f;
		m_tEndColor.g = 1.0f;
		m_tEndColor.b = 1.0f;
		m_tEndColor.a = 0.0f;
		m_tEndColorVar.r = 0.0f;
		m_tEndColorVar.g = 0.0f;
		m_tEndColorVar.b = 0.0f;
		m_tEndColorVar.a = 0.0f;

		setTexture(CCTextureCache::sharedTextureCache()->addImage("./Data/fire.png"));//.pvr");

		// additive
		this->setBlendAdditive(true);
		mLayer->addChild(this);
		return true;
	}
	return false;
}
Ejemplo n.º 2
0
Sprite::Sprite(const Texture& texture) :
m_texture    (NULL),
m_textureRect()
{
    setTexture(texture);
}
Ejemplo n.º 3
0
void HelpState::addPlankton(PlanktonController::Type type)
{
    auto entity = std::make_unique<Entity>(m_messageBus);
    entity->setWorldPosition({ static_cast<float>(Util::Random::value(0, 1920)), static_cast<float>(Util::Random::value(0, 1080)) });

    auto physComponent = m_physWorld.addBody(planktonSize);
    physComponent->setPosition(entity->getWorldPosition());
    physComponent->setTriggerOnly(true);
    physComponent->setName("control");
    entity->addComponent<PhysicsComponent>(physComponent);

    auto& appInstance = getContext().appInstance;
    bool colourblind = appInstance.getGameSettings().colourblindMode;
    AnimatedDrawable::Ptr ad;
    auto ident = ParticleSystem::create(Particle::Type::Ident, m_messageBus);
    ident->setTexture(appInstance.getTexture("assets/images/particles/ident.png"));
    auto text = std::make_unique<TextDrawable>(m_messageBus);
    text->setFont(appInstance.getFont("assets/fonts/Ardeco.ttf"));
    switch (type)
    {
    case PlanktonController::Type::Good:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food01.png"));
        ad->loadAnimationData("assets/images/player/food01.cra");
        (colourblind) ? ident->setColour({ 14u, 160u, 225u }) : ident->setColour({ 84u, 150u, 75u });
        text->setString("+50 HP");
        break;
    case PlanktonController::Type::Bad:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food02.png"));
        ad->loadAnimationData("assets/images/player/food02.cra");
        (colourblind) ? ident->setColour({ 214u, 190u, 25u }) : ident->setColour({ 184u, 67u, 51u });
        text->setString("-35 HP");
        break;
    case PlanktonController::Type::Bonus:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/food03.png"));
        ad->loadAnimationData("assets/images/player/food03.cra");
        ident->setColour({ 158u, 148u, 224u });
        text->setString("+100 HP");
        break;
    case PlanktonController::Type::UberLife:
        ad = std::make_unique<AnimatedDrawable>(m_messageBus, appInstance.getTexture("assets/images/player/bonus.png"));
        ad->loadAnimationData("assets/images/player/bonus.cra");
        ident->setColour({ 158u, 148u, 224u });
        text->setString("FULL HEALTH");
        break;
    default:
        break;
    }
    ident->setName("ident");
    entity->addComponent<ParticleSystem>(ident);

    text->setCharacterSize(40u);
    Util::Position::centreOrigin(*text);
    text->setPosition(0.f, 40.f);
    text->setName("text");
    entity->addComponent<TextDrawable>(text);

    ad->setBlendMode(sf::BlendAdd);
    ad->setOrigin(sf::Vector2f(ad->getFrameSize()) / 2.f);
    if (!ad->getAnimations().empty()) ad->play(ad->getAnimations()[0]);
    ad->setName("drawable");
    entity->addComponent<AnimatedDrawable>(ad);

    auto trail = ParticleSystem::create(Particle::Type::Trail, m_messageBus);
    trail->setTexture(appInstance.getTexture("assets/images/particles/circle.png"));
    float particleSize = planktonSize / 12.f;
    trail->setParticleSize({ particleSize, particleSize });
    trail->setName("trail");
    trail->setEmitRate(10.f);
    entity->addComponent<ParticleSystem>(trail);

    if (type == PlanktonController::Type::UberLife)
    {
        auto tails = std::make_unique<TailDrawable>(m_messageBus);
        tails->addTail(sf::Vector2f(-18.f, -15.f));
        tails->addTail(sf::Vector2f(-8.f, -5.f));
        tails->addTail(sf::Vector2f(-8.f, 5.f));
        tails->addTail(sf::Vector2f(-18.f, 15.f));
        tails->setName("tail");
        entity->addComponent<TailDrawable>(tails);
    }

    auto controller = std::make_unique<PlanktonController>(m_messageBus);
    controller->setType(type);
    controller->setDecayRate(0.f);
    controller->setColourblind(colourblind);
    entity->addComponent<PlanktonController>(controller);

    m_rootNode.addChild(entity);
}
Ejemplo n.º 4
0
Animation::Animation(std::string frmName, unsigned int direction) : ActiveUI()
{
    auto frm = ResourceManager::frmFileType(frmName);
    setTexture(ResourceManager::texture(frmName));


    int xOffset = frm->shiftX(direction);
    int yOffset = frm->shiftY(direction);


    // Смещение кадра в текстуре анимации
    unsigned int x = 0;
    unsigned int y = 0;

    for (unsigned int d = 0; d != direction; ++d)
    {
        y += frm->height(d); //? может i - 1
    }


    for (auto f = 0; f != frm->framesPerDirection(); ++f)
    {
        xOffset += frm->offsetX(direction, f);
        yOffset += frm->offsetY(direction, f);

        auto frame = new AnimationFrame();
        frame->setWidth(frm->width(direction, f));
        frame->setHeight(frm->height(direction, f));
        frame->setXOffset(xOffset);
        frame->setYOffset(yOffset);
        frame->setY(y);
        frame->setX(x);

        auto fps = frm->framesPerSecond();
        if (fps == 0)
        {
            frame->setDuration(1000);
        }
        else
        {
            frame->setDuration(std::round(1000.0/static_cast<double>(frm->framesPerSecond())));
        }

        x += frm->width(direction);
        frames()->push_back(frame);
    }

    if (frm->animatedPalette())
    {
        AnimatedPalette*  palette=Game::getInstance()->animatedPalette();
        auto masks = frm->animatedMasks();

        if ((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color((*masks)[libfalltergeist::FrmFileType::MASK_MONITOR][j],i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _monitorTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SLIME] != NULL)
        {
            for (auto i=0; i<4; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();	

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SLIME][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _slimeTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_SHORE] != NULL)
        {
            for (auto i=0; i<6; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_SHORE][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _shoreTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();

                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_SLOW][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireSlowTextures.push_back(texture);
            }
        }


        if ((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST] != NULL)
        {
            for (auto i=0; i<5; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_FIRE_FAST][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _fireFastTextures.push_back(texture);
            }
        }

        if ((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT] != NULL)
        {
            for (auto i=0; i<16; i++)
            {
                unsigned int* mask = new unsigned int[frm->width() * frm->height()]();
                //modify
                for (unsigned int j = 0; j< frm->width() * frm->height(); j++)
                {
                    mask[j] = palette->color(((*masks)[libfalltergeist::FrmFileType::MASK_REDDOT][j]),i);
                }
                //set
                auto texture = new Texture(frm->width(), frm->height());
                texture->loadFromRGBA(mask);
                _reddotTextures.push_back(texture);
            }
        }
    }
}
void LayerTile::updateContents(BlackBerry::Platform::Graphics::Buffer* contents, double scale)
{
    m_scale = scale;
    setTexture(textureCacheCompositingThread()->updateContents(m_texture, contents));
}
Ejemplo n.º 6
0
 Selection::Selection(engine::graphics::Texture* texture, int size) :
     TexturedShowable(texture->getDimensions() * size, engine::Vector2d(texture->getDimensions().getX() * size / 2, texture->getDimensions().getY() / 2))
 {
     setTexture(texture);
 }
Ejemplo n.º 7
0
    std::shared_ptr<TextureAtlas> GdxTextureAtlasLoader::load(std::istream& in) const
    {
        assert(_textureManager);

        auto atlas = std::make_shared<TextureAtlas>();
        std::string line;

        // texture name
        while(line.empty())
        {
            std::getline(in, line);
            StringUtils::trim(line);
        }
        if(_textureManager)
        {
            atlas->setTexture(_textureManager->load(line));
        }

        bool inRegion = false;
        TextureRegion region;

        while(in)
        {
            std::getline(in, line);
            std::size_t sep = line.find(':');
            std::string n = line.substr(0, sep);
            std::string v = line.substr(sep+1);

            if(!inRegion)
            {
                if(sep == std::string::npos)
                {
                    inRegion = true;
                    region = TextureRegion();
                    region.name = line;
                }
                else
                {
                    // header value
                }
            }
            else
            {
                if(line.substr(0, 1) == " ")
                {
                    StringUtils::trim(n);
                    StringUtils::trim(v);
                    if(n == "rotate")
                    {
                        region.rotate = v == "true";
                    }
                    else if(n == "xy")
                    {
                        sep = v.find(',');                       
                        region.x = std::stoi(v.substr(0, sep));
                        region.y = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "size")
                    {
                        sep = v.find(',');
                        region.width = std::stoi(v.substr(0, sep));
                        region.height = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "orig")
                    {
                        sep = v.find(',');
                        region.originalWidth = std::stoi(v.substr(0, sep));
                        region.originalHeight = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "offset")
                    {
                        sep = v.find(',');
                        region.offsetX = std::stoi(v.substr(0, sep));
                        region.offsetY = std::stoi(v.substr(sep+1));
                    }
                    else if(n == "index")
                    {
                        region.index = std::stoi(v);
                    }
                }
                else
                {
                    region.origin = TextureRegion::Origin::TopLeft;
                    atlas->addRegion(region);
                    region = TextureRegion();
                    region.name = line;
                }             
            }
        }

        return std::move(atlas);
    }
Ejemplo n.º 8
0
void display(void)
{
 	//時間計測
  curTime = timeGetTime();
  float dt = (float)(curTime - lastTime) * 0.001;//secに変換
  elapseTime1 += dt;
  elapseTime2 += dt;
  fps ++;
		printf("elapseTime2 = %f \n", elapseTime2);
  if(elapseTime1 >= 1.0)
  {
		printf("frame per sec = %d \n", fps);
		elapseTime1 = 0.0;
		fps = 0;
  }
  lastTime = curTime;

	//波データを作成し、投影マップを設定
	if(kindWave == 0) makeWaveCircle(amp, elapseTime2);
	else if(kindWave == 1) makeWavePlane(amp, elapseTime2);
	else makeWaveMix(amp, elapseTime2);
	makeTexImage();
	setTexture();

  if(flagWireframe)//'w'でwireframeとsolid model切り替え
  {
	  glPolygonMode(GL_FRONT,GL_LINE);
	  glPolygonMode(GL_BACK,GL_POINT);
  }
  else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

	resize(width, height);
	//カラーバッファのクリア
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  if(cos(M_PI * view.theta /180.0) > 0.0)//カメラ仰角90度でビューアップベクトル切替
	  gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, 1.0, 0.0);
  else
	  gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, -1.0, 0.0);

  //光源設定//'l'を押した後光源位置可変
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

  //fragment shaderのユニフォーム変数インデックスを取得
  GLint texLoc = glGetUniformLocation(shaderProg, "smplCaustics");
  glUniform1i(texLoc, 0);//GL_TEXTURE0を適用
  // シェーダプログラムの適用 
  glUseProgram(shaderProg);

  //描画
	fish1.motion1(elapseTime2);
	fish2.motion1(elapseTime2);
	drawFloor0(10.0, 10.0, 10, 10);

  // シェーダプログラムの適用を解除	
  glUseProgram(0);

	//テクスチャ、半透明物体があるとき
	glDepthMask(GL_FALSE); //デプスバッファを書き込み禁止
	glEnable(GL_BLEND);//アルファブレンディングを有効にする
	glBlendFunc(GL_DST_ALPHA,GL_ONE_MINUS_SRC_ALPHA);//色混合係数を決める

	//半透明描画
	drawWave();
	//テクスチャ、半透明物体があるとき
	glDepthMask(GL_TRUE); //デプスバッファの書き込みを許可
	glDisable(GL_BLEND);
	
  //影
  drawShadow();

	drawLight();

  if(flagHelp)
  {
		printf("矢印キーによる光源/投影中心移動 \n");
		printf(" →,←:x軸 \n");
		printf(" ↑,↓:y軸 \n");
		printf(" [Shift]+↑,↓:z軸 \n");
		printf(" 'l'を押した後、光源位置の移動可 \n");
		printf("'w'でワイヤーフレームとソリッドモデル切り替え \n");
		printf("マウス操作で視点変更可 \n");
		printf("  dolly:中央付近を左ボタンクリックで近づき,右ボタンクリックで遠ざかる \n");
		printf("  pan:左横および右横を右ボタンクリックで注視点が左右に変化する \n");
		printf("  tilt:真上および真下を右ボタンクリックで注視点が上下に変化する \n");
		printf("  tumble:左右にドラッグすると視点が左右に変化する \n");
		printf("  crane:上下にドラッグすると視点が上下に変化する \n");
		printf("  zoom:左下を右ボタンクリックでズームイン \n");
		printf("        右下を右ボタンクリックでズームアウト \n");
		printf("[Shift]+'r'でリセット \n");
		printf("[F1]キー:投影マッピングの視野角fovの増減 \n");
		printf("[F2]キー:波の振幅amp \n");
		printf("[F3]キー:波の種類(円形波と平面波)の切り替え \n");
		printf("[F4]キー:円形波の個数切り替え \n");
		flagHelp = false;
  }
  //終了
  glutSwapBuffers();
}
Ejemplo n.º 9
0
// For each Direct3D sampler of either the pixel or vertex stage,
// looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive).
// Sampler mapping needs to be up-to-date on the program object before this is called.
gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shaderType,
                                     const FramebufferTextureArray &framebufferTextures, size_t framebufferTextureCount)
{
    ProgramD3D *programD3D = GetImplAs<ProgramD3D>(data.state->getProgram());

    ASSERT(!programD3D->isSamplerMappingDirty());

    unsigned int samplerRange = programD3D->getUsedSamplerRange(shaderType);
    for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
    {
        GLenum textureType = programD3D->getSamplerTextureType(shaderType, samplerIndex);
        GLint textureUnit = programD3D->getSamplerMapping(shaderType, samplerIndex, *data.caps);
        if (textureUnit != -1)
        {
            gl::Texture *texture = data.state->getSamplerTexture(textureUnit, textureType);
            ASSERT(texture);

            gl::Sampler *samplerObject = data.state->getSampler(textureUnit);

            const gl::SamplerState &samplerState =
                samplerObject ? samplerObject->getSamplerState() : texture->getSamplerState();

            // TODO: std::binary_search may become unavailable using older versions of GCC
            if (texture->isSamplerComplete(samplerState, data) &&
                !std::binary_search(framebufferTextures.begin(),
                                    framebufferTextures.begin() + framebufferTextureCount, texture))
            {
                gl::Error error = setSamplerState(shaderType, samplerIndex, texture, samplerState);
                if (error.isError())
                {
                    return error;
                }

                error = setTexture(shaderType, samplerIndex, texture);
                if (error.isError())
                {
                    return error;
                }
            }
            else
            {
                // Texture is not sampler complete or it is in use by the framebuffer.  Bind the incomplete texture.
                gl::Texture *incompleteTexture = getIncompleteTexture(textureType);

                gl::Error error = setSamplerState(shaderType, samplerIndex, incompleteTexture,
                                                  incompleteTexture->getSamplerState());
                if (error.isError())
                {
                    return error;
                }

                error = setTexture(shaderType, samplerIndex, incompleteTexture);
                if (error.isError())
                {
                    return error;
                }
            }
        }
        else
        {
            // No texture bound to this slot even though it is used by the shader, bind a NULL texture
            gl::Error error = setTexture(shaderType, samplerIndex, NULL);
            if (error.isError())
            {
                return error;
            }
        }
    }

    // Set all the remaining textures to NULL
    size_t samplerCount = (shaderType == gl::SAMPLER_PIXEL) ? data.caps->maxTextureImageUnits
                                                            : data.caps->maxVertexTextureImageUnits;
    clearTextures(shaderType, samplerRange, samplerCount);

    return gl::Error(GL_NO_ERROR);
}
Ejemplo n.º 10
0
void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& matrialdatas, bool singleSprite)
{
    Node* node=nullptr;
    for(const auto& it : nodedata->modelNodeDatas)
    {
        if(it)
        {
            if(it->bones.size() > 0 || singleSprite)
            {
                auto mesh = Mesh::create(nodedata->id, getMeshIndexData(it->subMeshId));
                if(mesh)
                {
                    _meshes.pushBack(mesh);
                    if (_skeleton && it->bones.size())
                    {
                        auto skin = MeshSkin::create(_skeleton, it->bones, it->invBindPose);
                        mesh->setSkin(skin);
                    }
                    mesh->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this);

                    if (it->matrialId == "" && matrialdatas.materials.size())
                    {
                        const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
                        mesh->setTexture(textureData->filename);
                    }
                    else
                    {
                        const NMaterialData*  materialData=matrialdatas.getMaterialData(it->matrialId);
                        if(materialData)
                        {
                            const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
                            if(textureData)
                            {
                                auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
                                if(tex)
                                {
                                    Texture2D::TexParams    texParams;
                                    texParams.minFilter = GL_LINEAR;
                                    texParams.magFilter = GL_LINEAR;
                                    texParams.wrapS = textureData->wrapS;
                                    texParams.wrapT = textureData->wrapT;
                                    tex->setTexParameters(texParams);
                                    mesh->setTexture(tex);
                                    mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
                                }

                            }
                        }
                    }
                }
            }
            else
            {
                auto sprite = createSprite3DNode(nodedata,it,matrialdatas);
                if (sprite)
                {
                    if(root)
                    {
                        root->addChild(sprite);
                    } 
                }
                node=sprite;
            } 
        }
    }
    if(nodedata->modelNodeDatas.size() ==0 )
    {
        node= Node::create();
        if(node)
        {
            node->setName(nodedata->id);
            node->setAdditionalTransform(&nodedata->transform);
            if(root)
            {
                root->addChild(node);
            } 
        }
    }
    for(const auto& it : nodedata->children)
    {
        createNode(it,node, matrialdatas, singleSprite);
    }
}
Ejemplo n.º 11
0
void Sprite3D::setTexture(const std::string& texFile)
{
    auto tex = Director::getInstance()->getTextureCache()->addImage(texFile);
    setTexture(tex);
}
Ejemplo n.º 12
0
void MenuButton::popUp()
{
	setTexture(upTexture);

}
Ejemplo n.º 13
0
void GraphicsDeviceGL_1_3::setShaderResource(TextureHandle handle, u32 nameHash, u32 slot)
{
	setTexture(handle);
}
Ejemplo n.º 14
0
bool ParticleTraceEmitter::initWithTotalParticles(unsigned int numberOfPartiles)
{
	if (CCParticleSystemQuad::initWithTotalParticles(numberOfPartiles))
	{
		// duration
		m_fDuration = kCCParticleDurationInfinity;

		// Gravity Mode
		this->m_nEmitterMode = kCCParticleModeGravity;

		this->m_ePositionType = kCCPositionTypeFree;

		// Gravity Mode: gravity
		this->modeA.gravity = ccp(0, 0);

		// Gravity Mode: radial acceleration
		this->modeA.radialAccel = 0;
		this->modeA.radialAccelVar = 0;

		// Gravity Mode: speed of particles
		this->modeA.speed = 0;
		this->modeA.speedVar = 0;

		// starting angle
		m_fAngle = 90;
		m_fAngleVar = 0;

		// emitter position
		CCSize winSize = CCDirector::sharedDirector()->getWinSize();
		//this->setPosition(ccp(winSize.width / 2, 60));
		//this->m_tPosVar = ccp(40, 20);

		// life of particles
		m_fLife = 1;
		m_fLifeVar = 0.0f;


		// size, in pixels
		m_fStartSize = 30.0f;
		//m_fStartSizeVar = 54.0f;
		m_fEndSize = kCCParticleStartSizeEqualToEndSize;

		// emits per frame
		m_fEmissionRate = 40.0f;
		//m_uTotalParticles = 50;
		// color of particles
		m_tStartColor.r = 1.0f;
		m_tStartColor.g = 1.0f;
		m_tStartColor.b = 1.0f;
		m_tStartColor.a = 1.0f;
		m_tStartColorVar.r = 0.0f;
		m_tStartColorVar.g = 0.0f;
		m_tStartColorVar.b = 0.0f;
		m_tStartColorVar.a = 0.0f;
		m_tEndColor.r = 1.0f;
		m_tEndColor.g = 1.0f;
		m_tEndColor.b = 1.0f;
		m_tEndColor.a = 0.0f;
		m_tEndColorVar.r = 0.0f;
		m_tEndColorVar.g = 0.0f;
		m_tEndColorVar.b = 0.0f;
		m_tEndColorVar.a = 0.0f;

		setTexture(CCTextureCache::sharedTextureCache()->addImage("./Data/fire.png"));//.pvr");

		// additive
		this->setBlendAdditive(true);
		mLayer->addChild(this);
		return true;
	}
	return false;
}
Ejemplo n.º 15
0
bool CCParticleFire::initWithTotalParticles(unsigned int numberOfParticles)
{
    if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
    {
        // duration
        m_fDuration = kCCParticleDurationInfinity;

        // Gravity Mode
        this->m_nEmitterMode = kCCParticleModeGravity;

        // Gravity Mode: gravity
        this->modeA.gravity = ccp(0,0);

        // Gravity Mode: radial acceleration
        this->modeA.radialAccel = 0;
        this->modeA.radialAccelVar = 0;

        // Gravity Mode: speed of particles
        this->modeA.speed = 60;
        this->modeA.speedVar = 20;        

        // starting angle
        m_fAngle = 90;
        m_fAngleVar = 10;

        // emitter position
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        this->setPosition(ccp(winSize.width/2, 60));
        this->m_tPosVar = ccp(40, 20);

        // life of particles
        m_fLife = 3;
        m_fLifeVar = 0.25f;


        // size, in pixels
        m_fStartSize = 54.0f;
        m_fStartSizeVar = 10.0f;
        m_fEndSize = kCCParticleStartSizeEqualToEndSize;

        // emits per frame
        m_fEmissionRate = m_uTotalParticles/m_fLife;

        // color of particles
        m_tStartColor.r = 0.76f;
        m_tStartColor.g = 0.25f;
        m_tStartColor.b = 0.12f;
        m_tStartColor.a = 1.0f;
        m_tStartColorVar.r = 0.0f;
        m_tStartColorVar.g = 0.0f;
        m_tStartColorVar.b = 0.0f;
        m_tStartColorVar.a = 0.0f;
        m_tEndColor.r = 0.0f;
        m_tEndColor.g = 0.0f;
        m_tEndColor.b = 0.0f;
        m_tEndColor.a = 1.0f;
        m_tEndColorVar.r = 0.0f;
        m_tEndColorVar.g = 0.0f;
        m_tEndColorVar.b = 0.0f;
        m_tEndColorVar.a = 0.0f;

        CCTexture2D* pTexture = getDefaultTexture();
        if (pTexture != NULL)
        {
            setTexture(pTexture);
        }
        
        // additive
        this->setBlendAdditive(true);
        return true;
    }
    return false;
}
Ejemplo n.º 16
0
void TerrainEffect::setHeightmap(const Texture& heightmap)
{
	setTexture(this->heightmap, heightmap);
}
Ejemplo n.º 17
0
bool CCParticleSmoke::initWithTotalParticles(unsigned int numberOfParticles)
{
    if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
    {
        // duration
        m_fDuration = kCCParticleDurationInfinity;

        // Emitter mode: Gravity Mode
        setEmitterMode(kCCParticleModeGravity);

        // Gravity Mode: gravity
        setGravity(ccp(0,0));

        // Gravity Mode: radial acceleration
        setRadialAccel(0);
        setRadialAccelVar(0);

        // Gravity Mode: speed of particles
        setSpeed(25);
        setSpeedVar(10);

        // angle
        m_fAngle = 90;
        m_fAngleVar = 5;

        // emitter position
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        this->setPosition(ccp(winSize.width/2, 0));
        setPosVar(ccp(20, 0));

        // life of particles
        m_fLife = 4;
        m_fLifeVar = 1;

        // size, in pixels
        m_fStartSize = 60.0f;
        m_fStartSizeVar = 10.0f;
        m_fEndSize = kCCParticleStartSizeEqualToEndSize;

        // emits per frame
        m_fEmissionRate = m_uTotalParticles/m_fLife;

        // color of particles
        m_tStartColor.r = 0.8f;
        m_tStartColor.g = 0.8f;
        m_tStartColor.b = 0.8f;
        m_tStartColor.a = 1.0f;
        m_tStartColorVar.r = 0.02f;
        m_tStartColorVar.g = 0.02f;
        m_tStartColorVar.b = 0.02f;
        m_tStartColorVar.a = 0.0f;
        m_tEndColor.r = 0.0f;
        m_tEndColor.g = 0.0f;
        m_tEndColor.b = 0.0f;
        m_tEndColor.a = 1.0f;
        m_tEndColorVar.r = 0.0f;
        m_tEndColorVar.g = 0.0f;
        m_tEndColorVar.b = 0.0f;
        m_tEndColorVar.a = 0.0f;

        CCTexture2D* pTexture = getDefaultTexture();
        if (pTexture != NULL)
        {
            setTexture(pTexture);
        }

        // additive
        this->setBlendAdditive(false);
        return true;
    }
    return false;
}
Ejemplo n.º 18
0
void TerrainEffect::setNormalmap(const Texture& normalmap)
{
	setTexture(this->normalmap, normalmap);
}
Ejemplo n.º 19
0
 Selection::Selection(engine::graphics::Texture* texture, float radius) :
     TexturedShowable(texture->getDimensions() * radius, texture->getDimensions() * radius / 2)
 {
     setTexture(texture);
 }
Ejemplo n.º 20
0
Sprite::Sprite()
{
	const float vertexPositions[] =
	{
		0.75f, 0.75f, 0.0f, 1.0f,
		0.75f, -0.75f, 0.0f, 1.0f,
		-0.75f, -0.75f, 0.0f, 1.0f,
		-0.75f, 0.75f, 0.0f, 1.0f
	};

	const GLubyte indexPositions[] =
	{
		0, 1, 2,
		3, 2, 0
	};

	const float textureCoords[] =
	{
		-5.0, -5.0,
		5.0, -5.0,
		5.0, 5.0,
		-5.0, 5.0,
	};

	//Clear gl errors TODO:Need to look where the initial error is coming from.
	glGetError();
	GL_CHECK( glGenVertexArrays(1, &vao) );
	GL_CHECK( glBindVertexArray(vao) );

	shaders.push_back(CreateShader(GL_VERTEX_SHADER, strVertexShader));
	shaders.push_back(CreateShader(GL_FRAGMENT_SHADER, strFragmentShader));
	shaderProgram = CreateProgram(shaders);

	//Create buffer object to store vertex information
	GL_CHECK( glGenBuffers(1, &positionBufferObject) );
	GL_CHECK( glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject) );
	GL_CHECK( glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW));

	GLint posAttrib = glGetAttribLocation(shaderProgram, "position" );
	GL_CHECK( glEnableVertexAttribArray(posAttrib));
	GL_CHECK( glVertexAttribPointer(posAttrib, 4, GL_FLOAT, GL_FALSE, 0, NULL) );

	//Create buffer object to store texture mappings
	GLuint textMapObject;
	GL_CHECK( glGenBuffers(1, &textMapObject));
	GL_CHECK( glBindBuffer(GL_ARRAY_BUFFER, textMapObject));
	GL_CHECK( glBufferData(GL_ARRAY_BUFFER, sizeof(textureCoords), textureCoords, GL_STATIC_DRAW));

	GLint texAttrib = glGetAttribLocation(shaderProgram, "texcoord");
	GL_CHECK( glEnableVertexAttribArray(texAttrib));
	GL_CHECK( glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 0, NULL));

	//Create buffer object to store triangle indexes
	GL_CHECK( glGenBuffers(1, &IndexBufferId) );
	GL_CHECK( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBufferId) );
	GL_CHECK( glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexPositions), indexPositions, GL_STATIC_DRAW) );

	setTexture();
	setSize(0.25f, 0.25f);
	glBindVertexArray(0);

}
Ejemplo n.º 21
0
void PlatformDemoState::buildTerrain()
{
    m_shaderResource.preload(PlatformShaderId::SpecularSmooth2D, xy::Shader::NormalMapped::vertex, NORMAL_FRAGMENT_TEXTURED);
    m_textureResource.setFallbackColour({ 127, 127, 255 });
    const auto& normalTexture = m_textureResource.get("normalFallback");

    auto background = xy::Component::create<Plat::Background>(m_messageBus, m_textureResource);
    background->setAmbientColour(m_scene.getAmbientColour());
    auto entity = xy::Entity::create(m_messageBus);
    entity->addComponent(background);
    m_scene.addEntity(entity, xy::Scene::Layer::BackRear);

    auto drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/left_edge.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(256.f, 1080.f - 128.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1024.f, 1080.f - 128.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/ground_section.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1792.f, 1080.f - 128.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/right_edge.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(2560.f, 0.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    auto model = m_meshRenderer.createModel(MeshID::Platform, m_messageBus);
    model->rotate(xy::Model::Axis::X, 90.f);
    model->rotate(xy::Model::Axis::Z, 180.f);
    model->setPosition({ 384.f, 158.f, 0.f });
    model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Platform01));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(400.f, 700.f);
    entity->addComponent(model);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/plat_03.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(2000.f, 550.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------
    drawable = xy::Component::create<xy::AnimatedDrawable>(m_messageBus);
    drawable->setTexture(m_textureResource.get("assets/images/platform/plat_02.png"));
    drawable->setNormalMap(normalTexture);
    drawable->setShader(m_shaderResource.get(PlatformShaderId::SpecularSmooth2D));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1670.f, 450.f);
    entity->addComponent(drawable);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
    //-------------------------

    model = m_meshRenderer.createModel(MeshID::Platform, m_messageBus);
    model->rotate(xy::Model::Axis::X, 90.f);
    model->rotate(xy::Model::Axis::Z, 180.f);
    model->setPosition({ 384.f, 158.f, 0.f });
    model->setBaseMaterial(m_meshRenderer.getMaterial(MatId::Platform04));

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1210.f, 600.f);
    entity->addComponent(model);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);

    //------some shadow receivers-------//
    model = m_meshRenderer.createModel(MeshID::Quad, m_messageBus);
    model->setPosition({ 0.f, 0.f, -250.f });

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1000.f, 702.f);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);

    model = m_meshRenderer.createModel(MeshID::Quad, m_messageBus);
    model->rotate(xy::Model::Axis::X, 90.f);

    entity = xy::Entity::create(m_messageBus);
    entity->setPosition(1000.f, 952.f);
    entity->addComponent(model);
    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
}
Ejemplo n.º 22
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }  
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));  
	closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));
    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Point::ZERO);
    this->addChild(menu, 5,40);
    /////////////////////////////
    // 3. add your codes below...
    //添加定时器
	schedule(schedule_selector(HelloWorld::update));
    //!添加背景图片1
    auto sprite = Sprite::create("images/background2.png");
	sprite->setScaleX(2.5);
	sprite->setScaleY(2.5);

    // position the sprite on the center of the screen
    sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(sprite, 0);
    
	//!添加背景图片2
	auto   sprite1=Sprite::create("images/backgroundBottom.png");
	sprite1->setAnchorPoint(Point(0,0));
	sprite1->setPosition(0,0);
	this->addChild(sprite1,2);

	//!添加游戏准备图片
	auto   sprite2 =Sprite::create("images/getready.png");
	sprite2->setPosition(180,500);
	sprite2->setVisible(false);
	sprite2->setScaleX(2);
	sprite2->setScaleY(2);
	this->addChild(sprite2,2,2);

	//!添加游戏结束图片
	auto   sprite3=Sprite::create("images/gameover.png");
	sprite3->setScaleX(2);
	sprite3->setScaleY(2);
	sprite3->setPosition(180,500);
	sprite3->setVisible(false);
	this->addChild(sprite3,2,3);
	this->setOpacity(0.0f);

	//!添加分数面板图片
	auto   sprite4=Sprite::create("images/scoreboard.png");
	sprite4->setScaleX(2.5);
	sprite4->setScaleY(2.5);
	sprite4->setPosition(180,350);
	sprite4->setVisible(false);
	this->addChild(sprite4,2,4);
	sprite4->setOpacity(0.0f);

	//!添加分数面板分数字体
	score=0;
	sprintf(b,"%d",score);
	auto   fscores=LabelTTF::create(b,"Arial",25);
	this->addChild(fscores,5,100);
	fscores->setPosition(260,370);
	fscores->setVisible(false);
	//!添加一个新分数标志
	auto   newsprite=Sprite::create("images/newhighscore.png");
	newsprite->setScale(2);
	newsprite->setAnchorPoint(Point(1.5,-1.0));
	fscores->addChild(newsprite,1,1);
	newsprite->setVisible(false);

	//!添加分数面板最高分字体
	this->getUserScore();
	sprintf(c,"%d",userScore);
	auto   fuscores=LabelTTF::create(c,"Arial",25);
	fuscores->setPosition(260,320);
	fuscores->setVisible(false);
	this->addChild(fuscores,5,101);

	//!添加重新开始按钮
	auto   restartItem = MenuItemImage::create("images/pauseRestart.png","images/pauseRestart1.png",CC_CALLBACK_1(HelloWorld::restartCallBack,this));
	restartItem->setPosition(100,240);
	restartItem->setVisible(false);
	restartItem->setScale(0.7);
	menu->addChild(restartItem,0,1992);

	//!添加分数
	sprintf(a,"scores:%d",score);
	auto   scores=LabelTTF::create(a,"Arial",25);
	scores->setPosition(180,620);
	this->addChild(scores,4,10);

	//!添加事件
	auto   listener =EventListenerTouchOneByOne::create();
	listener->setSwallowTouches(true);
	listener->onTouchBegan=CC_CALLBACK_2(HelloWorld::touchEvent,this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);

	//!添加雪花效果
	auto   snow=ParticleSnow::create();
	auto   texture=Director::getInstance()->getTextureCache();
	snow->setTexture(texture->addImage("stars.png"));
	snow->setPosition(180,640);

	this->addChild(snow,2);

	//!添加滚动图片1
	auto   sbd1=Sprite::create("images/ground.png");
	sbd1->setAnchorPoint(Point(0,0));
	sbd1->setPosition(0,120);
	sbd1->setScale(2.2);
	this->addChild(sbd1,2,20);

	//!添加滚动图片2
	auto   sbd2=Sprite::create("images/ground.png");
	sbd2->setAnchorPoint(Point(0,0));
	sbd2->setPosition(360,120);
	sbd2->setScale(2.2);
	this->addChild(sbd2,2,21);

	//!添加游戏金币,该金币为玩家没玩一次游戏所得分数
	auto   goldsprite=Sprite::create("images/flappycoin.png");
	goldsprite->setScale(1.5);
	goldsprite->setAnchorPoint(Point(1.2,0));
	auto   file=UserDefault::getInstance();
	gameGold=file->getIntegerForKey("gameGold");
	sprintf(d,"%d",gameGold);
	auto   gold=LabelTTF::create(d,"Arial",20);
	gold->setPosition(45,580);
	gold->setAnchorPoint(Point(0,0));
	gold->addChild(goldsprite);
	this->addChild(gold,3,25);

	srand(time(0));
	_time=0.0f;
	//!设置当前状态
	currState =gameReady::getInstance();
	currState->enter(this);
    return true;
}
void LayerTile::setContents(BlackBerry::Platform::Graphics::Buffer* contents)
{
    m_scale = 0; // Resolution independent
    setTexture(textureCacheCompositingThread()->textureForContents(contents));
}
Ejemplo n.º 24
0
void special(int key, int x, int y)
{
  if(sKey == TRANSLATE)
  {
	  switch( key )
	  {
	  case GLUT_KEY_RIGHT://x方向
		  pos[objNo][0] += 0.1;
		  break;
	  case GLUT_KEY_LEFT://-x方向
		  pos[objNo][0] -= 0.1;
		  break;
	  case GLUT_KEY_UP:
		  if(glutGetModifiers() == 0) pos[objNo][1] += 0.1;//y方向
		  else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) pos[objNo][2] -= 0.1; //z方向
		  break;
	  case GLUT_KEY_DOWN:
		  if(glutGetModifiers() == 0) pos[objNo][1] -= 0.1;//-y方向
		  else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) pos[objNo][2] += 0.1; //-z方向
		  break;
	  default:
		  break;
	  }
  }
  else if(sKey == ROTATE)
  {
	  switch( key )
	  {
	  case GLUT_KEY_RIGHT://x軸回転
		  angle[objNo][0] += 10.0;
		  break;
	  case GLUT_KEY_LEFT://-x軸回転
		  angle[objNo][0] -= 10.0;
		  break;
	  case GLUT_KEY_UP:
		  if(glutGetModifiers() == 0) angle[objNo][1] += 10;//y方向
		  else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) angle[objNo][2] += 10; //z方向
		  break;
	  case GLUT_KEY_DOWN:
		  if(glutGetModifiers() == 0) angle[objNo][1] -= 10;//-y方向
		  else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) angle[objNo][2] -= 10; //-z方向
		  break;
	  default:
		  break;
	  }
  }
  else if(sKey == SCALE)
  {
	  switch( key )
	  {
	  case GLUT_KEY_RIGHT://x方向拡大
		  scale[objNo][0] += 0.1;
		  break;
	  case GLUT_KEY_LEFT://x方向縮小
		  scale[objNo][0] -= 0.1;
		  break;
	  case GLUT_KEY_UP:
		  if(glutGetModifiers() == 0) scale[objNo][1] += 0.1;//y方向拡大
		  else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scale[objNo][2] += 0.1; //z方向
		  break;
	  case GLUT_KEY_DOWN:
		  if(glutGetModifiers() == 0) scale[objNo][1] -= 0.1;//y方向縮小
		  else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scale[objNo][2] -= 0.1; //z方向
		  break;
	  default:
		  break;
	  }
  }
  else if(sKey == LIGHT)
  {
		float d = 1.0;
	  switch( key )
	  {
	  case GLUT_KEY_RIGHT://x方向
		  lightPos[0] += d;
		  break;
	  case GLUT_KEY_LEFT:
		  lightPos[0] -= d;//-x方向
		  break;
	  case GLUT_KEY_UP:
		  if(glutGetModifiers() == 0) lightPos[1] += d;//y方向
		  if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) lightPos[2] -= d;//z方向
		  break;
	  case GLUT_KEY_DOWN:
		  if(glutGetModifiers() == 0) lightPos[1] -= d;//-y方向
		  if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) lightPos[2] += d;//-z方向
		  break;
	  default:
		  break;
	  }
  }
	if(key == GLUT_KEY_F1) 
	{
	  if(wrapMode == GL_CLAMP) 
		{
			wrapMode = GL_REPEAT; 
			printf("wrapMode = GL_REPAT \n"); 
		}
	  else 
		{
			wrapMode = GL_CLAMP;
			printf("wrapMode = GL_CLAMP \n");
		}
		setTexture();//init();
	}	
	if(key == GLUT_KEY_F2)
	{
		if(glutGetModifiers() == 0) fov += 1.0;
		if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) fov -= 1.0;
		if(fov < 5.0) fov = 5.0;
		if(fov > 90.0) fov = 90.0;
		printf("fov = %f \n", fov);
	}
	if(key == GLUT_KEY_F3)
	{
		projCenter += 1;
		if(projCenter >= 4) projCenter = 0;
		if(projCenter == 0) printf("投影中心は真上 \n");
		else if(projCenter == 1) printf("投影中心は+z軸上 \n");
		else if(projCenter == 2) printf("投影中心は光源 \n");
		else printf("投影中心は視点 \n");
	}
	if(key == GLUT_KEY_F4)
	{
		if(flagTexRotation) flagTexRotation = false;
		else flagTexRotation = true;
	}
	if(key == GLUT_KEY_PAGE_UP) 
	{
		dang += 0.1;
  }	
	if(key == GLUT_KEY_PAGE_DOWN) 
	{
		dang -= 0.1;
  }	
}
void LayerTile::discardContents()
{
    m_scale = 0; // Unknown scale
    setTexture(0);
}
Ejemplo n.º 26
0
void CD3D9Shader::setTexture(const std::string& strTexture, unsigned long uTexID)
{
	CTexture* pTexture = GetD3D9RenderSystem().GetTextureMgr().getLoadedTexture(uTexID);
	setTexture(strTexture, pTexture);
}
Ejemplo n.º 27
0
bool LayerUserInfo::init()
{
    if(!BaseLayer::init())
    {
        return false;
    }
    
    auto root = CSLoader::createNode("LayerFriendDetails.csb");
    addChild(root);
    auto btnBack = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_back"));
    auto tmpImgIcon = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root, "image_user_avatar"));
    auto imgHead = ShaderSprite::createAndDownload("Default/image_defualt_user_icon_large.png", "Default/image_defualt_user_icon_large.png", "Default/image_mask_circle.png");
    imgHead->setPosition(tmpImgIcon->getPosition());
    root->addChild(imgHead, tmpImgIcon->getLocalZOrder());
    tmpImgIcon->removeFromParent();
    
    auto text_title= dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_title"));
    auto nickName = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_nick_name"));
    auto account = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_account"));
    auto spriteSex = dynamic_cast<Sprite*>(CSLoader::seekNodeByName(root, "sprite_sex"));
    auto textNickname = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_nike_name"));
    auto textAccount = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "text_account"));
    auto textSex = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_friend_session"));
    auto titleDiamond = dynamic_cast<Text*>(CSLoader::seekNodeByName(root, "title_diamond"));
    auto imgTextfieldBg = dynamic_cast<ImageView*>(CSLoader::seekNodeByName(root, "img_diamond_bg"));
    auto textfieldDiamond = dynamic_cast<TextField*>(CSLoader::seekNodeByName(root, "textfield_diamond"));
    mBtnConfirm = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_diamond"));
    
    text_title->setString(tools::local_string("personal_info","个人资料"));
    nickName->setString(tools::local_string("nickname","昵称"));
    account->setString(tools::local_string("account","账号"));
    mBtnConfirm->setTitleText(tools::local_string("confirm_change_password","确定"));
    titleDiamond->setString(tools::local_string("give_diamond","赠送钻石"));
    mCheckboxHiteMoments = dynamic_cast<CheckBox*>(CSLoader::seekNodeByName(root, "checkbox_friend_session"));
    mBtnSendMsg = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_send_message"));
    mBtnDeleteFriend = dynamic_cast<Button*>(CSLoader::seekNodeByName(root, "btn_delete_friend"));
    
    btnBack->addClickEventListener([&](Ref *ref)
    {
        if(IsInvitation)
        {
            auto layer = dynamic_cast<LayerInvitationList*>(this->getParent());
            if(layer)
            {
                layer->refresh_deal_data();
            }
        }
        this->removeFromParent();
    });
    imgHead->setSpriteTexture(mInfo.picname());
    spriteSex->setTexture(mInfo.sex() == msg::Sex::MALE ? gMaleIcon : gFemaleIcon);
    textSex->setString(mInfo.sex() == msg::Sex::MALE ? tools::local_string("block_his_moment", "屏蔽他的朋友圈") : tools::local_string("block_her_moment", "屏蔽她的朋友圈"));
    textNickname->setString(mInfo.nickname());
    spriteSex->setPositionX(textNickname->getPositionX() - textNickname->getContentSize().width - 30);
    textAccount->setString(tools::to_string(mInfo.userid()));
    mCheckboxHiteMoments->setSelected(false);
    setCheckBoxTextures(mCheckboxHiteMoments);
    mCheckboxHiteMoments->addClickEventListener([&](Ref *ref)
    {
        auto checkbox = dynamic_cast<CheckBox*>(ref);
        bool isSelect = checkbox->isSelected();
        
        
        
        int userId = mInfo.userid();
        log("屏蔽userId = %d", userId);
        auto processor = PM->BlockUser_up(userId, isSelect);
        send_data(processor, REQ_SHIELD_FRIEND);
    });
    mEditboxtDiamond = GameTools::createEditBoxFromTextField(imgTextfieldBg, textfieldDiamond);
    mEditboxtDiamond->setInputMode(EditBox::InputMode::NUMERIC);
    mEditboxtDiamond->setReturnType(EditBox::KeyboardReturnType::DONE);
    mEditboxtDiamond->setMaxLength(10);
    mEditboxtDiamond->setFontColor(Color3B::WHITE);
    mEditboxtDiamond->setPlaceHolder("0");
    mEditboxtDiamond->setDelegate(this);
    
    mBtnConfirm->addClickEventListener([&](Ref *ref){
        
        log("send Diamond: %s, len = %d", mEditboxtDiamond->getText(), strlen(mEditboxtDiamond->getText()));
        if(strlen(mEditboxtDiamond->getText()) <= 0 || !GameTools::isRegexMath(mEditboxtDiamond->getText(), GameTools::INPUT_TYPE::NUMBER))
        {
            Toast::ToastShow(tools::local_string("input_whole","只支持数字"));
            return;
        }
        GameTools::editBoxLoseInputFocus();
        requestDiamond();
        
    });
    //处理搜索消息
    if(!IsInvitation)
        InitNormal();
    else
    {
        
        //处理请求消息
        mBtnSendMsg->setTitleText(tools::local_string("operate", "同意"));
        mBtnSendMsg->addClickEventListener([&](Ref *ref)
                                          {
                                              sendInvitationFriend(true);
                                          });
        mBtnDeleteFriend->setTitleText(tools::local_string("disagree_friend_request", "拒绝"));
        mBtnDeleteFriend->addClickEventListener([&](Ref *ref)
                                          {
                                              sendInvitationFriend(false);
                                          });
        
    }
    send_data(PM->null_up(), REQ_MOMENT_BLOCK_LIST);//每次都请求已屏蔽的朋友圈列表
    return true;
}
Ejemplo n.º 28
0
bool CCParticleExplosion::initWithTotalParticles(unsigned int numberOfParticles)
{
    if( CCParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) 
    {
        // duration
        m_fDuration = 0.1f;

        setEmitterMode(kCCParticleModeGravity);

        // Gravity Mode: gravity
        setGravity(ccp(0,0));

        // Gravity Mode: speed of particles
        setSpeed(70);
        setSpeedVar(40);

        // Gravity Mode: radial
        setRadialAccel(0);
        setRadialAccelVar(0);

        // Gravity Mode: tangential
        setTangentialAccel(0);
        setTangentialAccelVar(0);

        // angle
        m_fAngle = 90;
        m_fAngleVar = 360;

        // emitter position
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        this->setPosition(ccp(winSize.width/2, winSize.height/2));
        setPosVar(CCPointZero);

        // life of particles
        m_fLife = 5.0f;
        m_fLifeVar = 2;

        // size, in pixels
        m_fStartSize = 15.0f;
        m_fStartSizeVar = 10.0f;
        m_fEndSize = kCCParticleStartSizeEqualToEndSize;

        // emits per second
        m_fEmissionRate = m_uTotalParticles/m_fDuration;

        // color of particles
        m_tStartColor.r = 0.7f;
        m_tStartColor.g = 0.1f;
        m_tStartColor.b = 0.2f;
        m_tStartColor.a = 1.0f;
        m_tStartColorVar.r = 0.5f;
        m_tStartColorVar.g = 0.5f;
        m_tStartColorVar.b = 0.5f;
        m_tStartColorVar.a = 0.0f;
        m_tEndColor.r = 0.5f;
        m_tEndColor.g = 0.5f;
        m_tEndColor.b = 0.5f;
        m_tEndColor.a = 0.0f;
        m_tEndColorVar.r = 0.5f;
        m_tEndColorVar.g = 0.5f;
        m_tEndColorVar.b = 0.5f;
        m_tEndColorVar.a = 0.0f;

        CCTexture2D* pTexture = getDefaultTexture();
        if (pTexture != NULL)
        {
            setTexture(pTexture);
        }

        // additive
        this->setBlendAdditive(false);
        return true;
    }
    return false;
}
Ejemplo n.º 29
0
void CCSlot::_updateFrame()
{
    const auto frameDisplay = (DBCCSprite*)(this->_rawDisplay);

    if (this->_display && this->_displayIndex >= 0)
    {
        const unsigned displayIndex = this->_displayIndex;
        const auto rawDisplayData = displayIndex < this->_displayDataSet->displays.size() ? this->_displayDataSet->displays[displayIndex] : nullptr;
        const auto replacedDisplayData = displayIndex < this->_replacedDisplayDataSet.size() ? this->_replacedDisplayDataSet[displayIndex] : nullptr;
        const auto currentDisplayData = replacedDisplayData ? replacedDisplayData : rawDisplayData;
        const auto currentTextureData = static_cast<CCTextureData*>(currentDisplayData->textureData);

        if (currentTextureData)
        {
            if (!currentTextureData->texture)
            {
                const auto textureAtlasTexture = static_cast<CCTextureAtlasData*>(currentTextureData->parent)->texture;
                if (textureAtlasTexture)
                {
                    cocos2d::Rect rect(currentTextureData->region.x, currentTextureData->region.y, currentTextureData->region.width, currentTextureData->region.height);
                    cocos2d::Vec2 offset(0.f, 0.f);
                    cocos2d::Size originSize(currentTextureData->region.width, currentTextureData->region.height);

                    /*if (currentTextureData->frame) 
                    {
                        offset.setPoint(-currentTextureData->frame->x, -currentTextureData->frame->y);
                        originSize.setSize(currentTextureData->frame->width, currentTextureData->frame->height);
                    }*/

                    currentTextureData->texture = cocos2d::SpriteFrame::createWithTexture(textureAtlasTexture, rect, currentTextureData->rotated, offset, originSize); // TODO multiply textureAtlas
                    currentTextureData->texture->retain();
                }
            }

            const auto currentTexture = this->_armature->_replacedTexture ? static_cast<cocos2d::Texture2D*>(this->_armature->_replacedTexture) : (currentTextureData->texture ? currentTextureData->texture->getTexture() : nullptr);

            if (currentTexture)
            {
                if (this->_meshData && this->_display == this->_meshDisplay)
                {
                    const auto& region = currentTextureData->region;
                    const auto& textureAtlasSize = currentTextureData->texture->getTexture()->getContentSizeInPixels();
                    auto displayVertices = new cocos2d::V3F_C4B_T2F[(unsigned)(this->_meshData->uvs.size() / 2)]; // does cocos2dx release it?
                    auto vertexIndices = new unsigned short[this->_meshData->vertexIndices.size()]; // does cocos2dx release it?
                    cocos2d::Rect boundsRect(999999.f, 999999.f, -999999.f, -999999.f);

                    for (std::size_t i = 0, l = this->_meshData->uvs.size(); i < l; i += 2)
                    {
                        const auto iH = (unsigned)(i / 2);
                        const auto x = this->_meshData->vertices[i];
                        const auto y = this->_meshData->vertices[i + 1];
                        cocos2d::V3F_C4B_T2F vertexData;
                        vertexData.vertices.set(x, -y, 0.f);
                        vertexData.texCoords.u = (region.x + this->_meshData->uvs[i] * region.width) / textureAtlasSize.width;
                        vertexData.texCoords.v = (region.y + this->_meshData->uvs[i + 1] * region.height) / textureAtlasSize.height;
                        vertexData.colors = cocos2d::Color4B::WHITE;
                        displayVertices[iH] = vertexData;

                        if (boundsRect.origin.x > x)
                        {
                            boundsRect.origin.x = x;
                        }

                        if (boundsRect.size.width < x) 
                        {
                            boundsRect.size.width = x;
                        }

                        if (boundsRect.origin.y > -y)
                        {
                            boundsRect.origin.y = -y;
                        }

                        if (boundsRect.size.height < -y)
                        {
                            boundsRect.size.height = -y;
                        }
                    }

                    boundsRect.size.width -= boundsRect.origin.x;
                    boundsRect.size.height -= boundsRect.origin.y;

                    for (std::size_t i = 0, l = this->_meshData->vertexIndices.size(); i < l; ++i)
                    {
                        vertexIndices[i] = this->_meshData->vertexIndices[i];
                    }

                    // In cocos2dx render meshDisplay and frameDisplay are the same display
                    frameDisplay->setSpriteFrame(currentTextureData->texture); // polygonInfo will be override
                    if (currentTexture != currentTextureData->texture->getTexture())
                    {
                        frameDisplay->setTexture(currentTexture); // Relpace texture // polygonInfo will be override
                    }

                    //
                    cocos2d::PolygonInfo polygonInfo;
                    auto& triangles = polygonInfo.triangles;
                    triangles.verts = displayVertices;
                    triangles.indices = vertexIndices;
                    triangles.vertCount = (unsigned)(this->_meshData->uvs.size() / 2);
                    triangles.indexCount = (unsigned)(this->_meshData->vertexIndices.size());
                    polygonInfo.rect = boundsRect; // Copy
                    frameDisplay->setPolygonInfo(polygonInfo);
                    frameDisplay->setContentSize(boundsRect.size);

                    if (this->_meshData->skinned)
                    {
                        frameDisplay->setScale(1.f, 1.f);
                        frameDisplay->setRotationSkewX(0.f);
                        frameDisplay->setRotationSkewY(0.f);
                        frameDisplay->setPosition(0.f, 0.f);
                    }

                    frameDisplay->setAnchorPoint(cocos2d::Vec2::ZERO);
                }
                else
                {
                    cocos2d::Vec2 pivot(currentDisplayData->pivot.x, currentDisplayData->pivot.y);

                    const auto& rectData = currentTextureData->frame ? *currentTextureData->frame : currentTextureData->region;
                    auto width = rectData.width;
                    auto height = rectData.height;
                    if (!currentTextureData->frame && currentTextureData->rotated)
                    {
                        width = rectData.height;
                        height = rectData.width;
                    }

                    if (currentDisplayData->isRelativePivot)
                    {
                        pivot.x *= width;
                        pivot.y *= height;
                    }

                    if (currentTextureData->frame)
                    {
                        pivot.x += currentTextureData->frame->x;
                        pivot.y += currentTextureData->frame->y;
                    }

                    if (rawDisplayData && rawDisplayData != currentDisplayData)
                    {
                        pivot.x += rawDisplayData->transform.x - currentDisplayData->transform.x;
                        pivot.y += rawDisplayData->transform.y - currentDisplayData->transform.y;
                    }

                    pivot.x = pivot.x / currentTextureData->region.width;
                    pivot.y = 1.f - pivot.y / currentTextureData->region.height;

                    frameDisplay->setSpriteFrame(currentTextureData->texture); // polygonInfo will be override

                    if (currentTexture != currentTextureData->texture->getTexture())
                    {
                        frameDisplay->setTexture(currentTexture); // Relpace texture // polygonInfo will be override
                    }

                    frameDisplay->setAnchorPoint(pivot);
                }

                this->_updateVisible();

                return;
            }
        }
    }

    frameDisplay->setTexture(nullptr);
    frameDisplay->setTextureRect(cocos2d::Rect::ZERO);
    frameDisplay->setAnchorPoint(cocos2d::Vec2::ZERO);
    frameDisplay->setVisible(false);
}
Ejemplo n.º 30
0
bool xD3D9GpuProgParamTable::setTexture(const wchar_t* name    , IBaseTexture* pTexture , eShaderType _shader)
{
	int iTexName = xStringHash(name);
	return setTexture(iTexName , pTexture , _shader);
}