mirror of https://github.com/axmolengine/axmol.git
add UV Animation Test & it's resource
This commit is contained in:
parent
706f49cb59
commit
8101b6a94e
|
@ -52,6 +52,7 @@ static std::function<Layer*()> createFunctions[] =
|
|||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||
// 3DEffect use custom shader which is not supported on WP8/WinRT yet.
|
||||
CL(Sprite3DEffectTest),
|
||||
CL(Sprite3DUVAnimationTest),
|
||||
#endif
|
||||
CL(Sprite3DWithSkinTest),
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||
|
@ -225,6 +226,104 @@ std::string Sprite3DBasicTest::subtitle() const
|
|||
return "Tap screen to add more sprites";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite3DUVAnimationTest
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
Sprite3DUVAnimationTest::Sprite3DUVAnimationTest()
|
||||
{
|
||||
CCLOG("hehehe dadadad");
|
||||
//the offset use to translating texture
|
||||
this->cylinder_texture_offset = 0;
|
||||
this->shining_duraion = 0;
|
||||
Size visibleSize = Director::getInstance()->getVisibleSize();
|
||||
|
||||
//use custom camera
|
||||
auto camera = Camera::createPerspective(60,visibleSize.width/visibleSize.height,0.1,200);
|
||||
camera->setCameraFlag(CameraFlag::USER1);
|
||||
|
||||
//create cylinder
|
||||
auto cylinder = Sprite3D::create("Sprite3DTest/cylinder.c3b");
|
||||
|
||||
//create and set our custom shader
|
||||
auto shader =GLProgram::createWithFilenames("Sprite3DTest/cylinder.vert","Sprite3DTest/cylinder.frag");
|
||||
state = GLProgramState::create(shader);
|
||||
cylinder->setGLProgramState(state);
|
||||
|
||||
state->setUniformFloat("offset",cylinder_texture_offset);
|
||||
state->setUniformFloat("duration",shining_duraion);
|
||||
//pass mesh's attribute to shader
|
||||
long offset = 0;
|
||||
auto attributeCount = cylinder->getMesh()->getMeshVertexAttribCount();
|
||||
for (auto i = 0; i < attributeCount; i++) {
|
||||
auto meshattribute = cylinder->getMesh()->getMeshVertexAttribute(i);
|
||||
state->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
||||
meshattribute.size,
|
||||
meshattribute.type,
|
||||
GL_FALSE,
|
||||
cylinder->getMesh()->getVertexSizeInBytes(),
|
||||
(GLvoid*)offset);
|
||||
offset += meshattribute.attribSizeBytes;
|
||||
}
|
||||
|
||||
//create the second texture for cylinder
|
||||
auto shining_texture = Director::getInstance()->getTextureCache()->addImage("Sprite3DTest/caustics.png");
|
||||
Texture2D::TexParams tRepeatParams;//set texture parameters
|
||||
tRepeatParams.magFilter = GL_LINEAR_MIPMAP_LINEAR;
|
||||
tRepeatParams.minFilter = GL_LINEAR;
|
||||
tRepeatParams.wrapS = GL_REPEAT;
|
||||
tRepeatParams.wrapT = GL_REPEAT;
|
||||
shining_texture->setTexParameters(tRepeatParams);
|
||||
//pass the texture sampler to our custom shader
|
||||
state->setUniformTexture("caustics",shining_texture);
|
||||
|
||||
|
||||
this->addChild(cylinder);
|
||||
this->setCameraMask(2);
|
||||
this->addChild(camera);
|
||||
|
||||
//adjust cylinder's position & rotation
|
||||
cylinder->setPosition3D(Vec3(0,-15,-50));
|
||||
cylinder->setRotation3D(Vec3(-90,0,0));
|
||||
|
||||
//the callback function update cylinder's texcoord
|
||||
schedule(schedule_selector(Sprite3DUVAnimationTest::cylinderUpdate));
|
||||
}
|
||||
|
||||
std::string Sprite3DUVAnimationTest::title() const
|
||||
{
|
||||
return "The UV Animation of Sprite3D";
|
||||
}
|
||||
|
||||
std::string Sprite3DUVAnimationTest::subtitle() const
|
||||
{
|
||||
return " ";
|
||||
}
|
||||
|
||||
void Sprite3DUVAnimationTest::cylinderUpdate(float dt)
|
||||
{
|
||||
//callback function to update cylinder's texcoord
|
||||
static bool fade_in = true;
|
||||
cylinder_texture_offset += 0.3*dt;
|
||||
cylinder_texture_offset = (cylinder_texture_offset >1)?0:cylinder_texture_offset;
|
||||
if(fade_in)
|
||||
{
|
||||
shining_duraion += 0.5*dt;
|
||||
if(shining_duraion>1) fade_in = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
shining_duraion -= 0.5*dt;
|
||||
if(shining_duraion<0) fade_in = true;
|
||||
}
|
||||
|
||||
//pass the result to shader
|
||||
state->setUniformFloat("offset",cylinder_texture_offset);
|
||||
state->setUniformFloat("duration",shining_duraion);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
// Sprite3DHitTest
|
||||
|
@ -1445,3 +1544,5 @@ void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p)
|
|||
}
|
||||
_mirrorSprite = sprite;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,19 @@ public:
|
|||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
};
|
||||
|
||||
class Sprite3DUVAnimationTest : public Sprite3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DUVAnimationTest);
|
||||
Sprite3DUVAnimationTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
private:
|
||||
void cylinderUpdate(float dt);
|
||||
float cylinder_texture_offset;
|
||||
float shining_duraion;
|
||||
GLProgramState * state;
|
||||
};
|
||||
class EffectSprite3D;
|
||||
|
||||
class Effect3D : public Ref
|
||||
|
|
Loading…
Reference in New Issue