X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fmetaball-explosion%2Fmetaball-explosion-example.cpp;h=fa701ccc894241bd1bf4bbe416f4a6a5c517ee8f;hb=8b9c89c6455da22660eb69436a3539b138fd0594;hp=ac46a681f63772763f0c47b0c4ac759bc4e18f4f;hpb=07ab57fde5eb011ecd843162afd4eeae3f7d844b;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/metaball-explosion/metaball-explosion-example.cpp b/examples/metaball-explosion/metaball-explosion-example.cpp index ac46a68..fa701cc 100644 --- a/examples/metaball-explosion/metaball-explosion-example.cpp +++ b/examples/metaball-explosion/metaball-explosion-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,18 @@ * */ -//External includes +// EXTERNAL INCLUDES #include #include - -//Internal includes #include -#include +#include +#include #include +#include +// INTERNAL INCLUDES #include "shared/view.h" +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -38,7 +40,7 @@ const float GRAVITY_X(0); const float GRAVITY_Y(-0.09); } -#define METABALL_NUMBER 12 +#define METABALL_NUMBER 6 const char*const METABALL_VERTEX_SHADER = DALI_COMPOSE_SHADER ( @@ -192,7 +194,7 @@ public: /** * Touch event function */ - bool OnTouch( Actor actor, const TouchEvent& touch ); + bool OnTouch( Actor actor, const TouchData& touch ); /** * Key event function @@ -304,7 +306,25 @@ private: //---------------- MetaballExplosionController::MetaballExplosionController( Application& application ) - : mApplication( application ) +: mApplication( application ), + mScreenSize(), + mContentLayer(), + mBackImage(), + mMetaballFBO(), + mMetaballRoot(), + mMetaballs(), + mPositionIndex(), + mCompositionActor(), + mCurrentTouchPosition(), + mMetaballPosVariation(), + mMetaballPosVariationFrom(), + mMetaballPosVariationTo(), + mMetaballCenter(), + mPositionVarAnimation(), + mDispersion( 0 ), + mDispersionAnimation(), + mTimerDispersion(), + mTimeMult( 1.0f ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &MetaballExplosionController::Create ); @@ -328,7 +348,7 @@ void MetaballExplosionController::Create( Application& app ) stage.SetBackgroundColor(Color::BLACK); //Set background image for the view - mBackImage = ResourceImage::New( BACKGROUND_IMAGE ); + mBackImage = DemoHelper::LoadImage( BACKGROUND_IMAGE ); srand((unsigned)time(0)); @@ -344,7 +364,7 @@ void MetaballExplosionController::Create( Application& app ) mTimerDispersion.TickSignal().Connect(this, &MetaballExplosionController::OnTimerDispersionTick); // Connect the callback to the touch signal on the mesh actor - stage.GetRootLayer().TouchedSignal().Connect( this, &MetaballExplosionController::OnTouch ); + stage.GetRootLayer().TouchSignal().Connect( this, &MetaballExplosionController::OnTouch ); } Geometry MetaballExplosionController::CreateGeometry() @@ -373,34 +393,29 @@ Geometry MetaballExplosionController::CreateGeometry() { Vector2(1.0f, 1.0f * aspect) } }; - int indices[] = { 0, 3, 1, 0, 2, 3 }; - unsigned int numberOfVertices = sizeof(vertices)/sizeof(VertexPosition); //Vertices Property::Map positionVertexFormat; positionVertexFormat["aPosition"] = Property::VECTOR2; - PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat, numberOfVertices ); - positionVertices.SetData(vertices); + PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat ); + positionVertices.SetData( vertices, numberOfVertices ); //Textures Property::Map textureVertexFormat; textureVertexFormat["aTexture"] = Property::VECTOR2; - PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat, numberOfVertices ); - textureVertices.SetData(textures); + PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat ); + textureVertices.SetData( textures, numberOfVertices ); //Indices - Property::Map indicesVertexFormat; - indicesVertexFormat["aIndices"] = Property::INTEGER; - PropertyBuffer indicesToVertices = PropertyBuffer::New( indicesVertexFormat, 6 ); - indicesToVertices.SetData(indices); + unsigned short indices[] = { 0, 3, 1, 0, 2, 3 }; // Create the geometry object Geometry texturedQuadGeometry = Geometry::New(); texturedQuadGeometry.AddVertexBuffer( positionVertices ); texturedQuadGeometry.AddVertexBuffer( textureVertices ); - texturedQuadGeometry.SetIndexBuffer ( indicesToVertices ); + texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) ); return texturedQuadGeometry; } @@ -431,34 +446,29 @@ Geometry MetaballExplosionController::CreateGeometryComposition() { Vector2(1.0f, 1.0f) } }; - int indices[] = { 0, 3, 1, 0, 2, 3 }; - unsigned int numberOfVertices = sizeof(vertices)/sizeof(VertexPosition); //Vertices Property::Map positionVertexFormat; positionVertexFormat["aPosition"] = Property::VECTOR2; - PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat, numberOfVertices ); - positionVertices.SetData(vertices); + PropertyBuffer positionVertices = PropertyBuffer::New( positionVertexFormat ); + positionVertices.SetData( vertices, numberOfVertices ); //Textures Property::Map textureVertexFormat; textureVertexFormat["aTexture"] = Property::VECTOR2; - PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat, numberOfVertices ); - textureVertices.SetData(textures); + PropertyBuffer textureVertices = PropertyBuffer::New( textureVertexFormat ); + textureVertices.SetData( textures, numberOfVertices ); //Indices - Property::Map indicesVertexFormat; - indicesVertexFormat["aIndices"] = Property::INTEGER; - PropertyBuffer indicesToVertices = PropertyBuffer::New( indicesVertexFormat, 6 ); - indicesToVertices.SetData(indices); + unsigned short indices[] = { 0, 3, 1, 0, 2, 3 }; // Create the geometry object Geometry texturedQuadGeometry = Geometry::New(); texturedQuadGeometry.AddVertexBuffer( positionVertices ); texturedQuadGeometry.AddVertexBuffer( textureVertices ); - texturedQuadGeometry.SetIndexBuffer ( indicesToVertices ); + texturedQuadGeometry.SetIndexBuffer ( &indices[0], sizeof( indices )/ sizeof( indices[0] ) ); return texturedQuadGeometry; } @@ -474,24 +484,24 @@ void MetaballExplosionController::CreateMetaballActors() //Create the shader for the metaballs Shader shader = Shader::New( METABALL_VERTEX_SHADER, METABALL_FRAG_SHADER ); - Material material = Material::New( shader ); Geometry metaballGeom = CreateGeometry(); + Renderer renderer = Renderer::New( metaballGeom, shader ); + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON ); + renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE ); + renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE ); + renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE ); + renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE ); //Initialization of each of the metaballs for( int i = 0; i < METABALL_NUMBER; i++ ) { mMetaballs[i].position = Vector2(0.0f, 0.0f); - mMetaballs[i].radius = mMetaballs[i].initRadius = randomNumber(0.025f,0.035f); + mMetaballs[i].radius = mMetaballs[i].initRadius = randomNumber(0.05f,0.07f); mMetaballs[i].actor = Actor::New( ); mMetaballs[i].actor.SetName("Metaball"); mMetaballs[i].actor.SetScale( 1.0f ); mMetaballs[i].actor.SetParentOrigin( ParentOrigin::CENTER ); - - Renderer renderer = Renderer::New( metaballGeom, material ); - renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON ); - renderer.SetBlendFunc(BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE, BlendingFactor::ONE); - mMetaballs[i].actor.AddRenderer( renderer ); mMetaballs[i].positionIndex = mMetaballs[i].actor.RegisterProperty( "uPositionMetaball", mMetaballs[i].position ); @@ -557,17 +567,17 @@ void MetaballExplosionController::AddRefractionImage() //Create new shader Shader shader = Shader::New( METABALL_VERTEX_SHADER, REFRACTION_FRAG_SHADER ); - //Create new material - Material material = Material::New( shader ); - //Add Textures - material.AddTexture(mBackImage, "sTexture"); - material.AddTexture(fbo, "sEffect"); + //Create new texture set + TextureSet textureSet = TextureSet::New(); + TextureSetImage( textureSet, 0u, mBackImage ); + TextureSetImage( textureSet, 1u, fbo ); //Create geometry Geometry metaballGeom = CreateGeometryComposition(); - Renderer mRenderer = Renderer::New( metaballGeom, material ); + Renderer mRenderer = Renderer::New( metaballGeom, shader ); + mRenderer.SetTextures( textureSet ); mCompositionActor = Actor::New( ); mCompositionActor.SetParentOrigin(ParentOrigin::CENTER); @@ -691,31 +701,32 @@ void MetaballExplosionController::SetPositionToMetaballs(Vector2 & metaballCente mCompositionActor.SetProperty( mPositionIndex, metaballCenter ); } -bool MetaballExplosionController::OnTouch( Actor actor, const TouchEvent& touch ) +bool MetaballExplosionController::OnTouch( Actor actor, const TouchData& touch ) { - const TouchPoint &point = touch.GetPoint(0); float aspectR = mScreenSize.y / mScreenSize.x; - switch( point.state ) + switch( touch.GetState( 0 ) ) { - case TouchPoint::Down: + case PointState::DOWN: { ResetMetaballs(true); - Vector2 metaballCenter = Vector2((point.screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - point.screen.y) / mScreenSize.y) - 0.5) * 2.0; + const Vector2 screen = touch.GetScreenPosition( 0 ); + Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5) * 2.0; SetPositionToMetaballs(metaballCenter); break; } - case TouchPoint::Motion: + case PointState::MOTION: { - Vector2 metaballCenter = Vector2((point.screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - point.screen.y) / mScreenSize.y) - 0.5) * 2.0; + const Vector2 screen = touch.GetScreenPosition( 0 ); + Vector2 metaballCenter = Vector2((screen.x / mScreenSize.x) - 0.5, (aspectR * (mScreenSize.y - screen.y) / mScreenSize.y) - 0.5) * 2.0; SetPositionToMetaballs(metaballCenter); break; } - case TouchPoint::Up: - case TouchPoint::Leave: - case TouchPoint::Interrupted: + case PointState::UP: + case PointState::LEAVE: + case PointState::INTERRUPTED: { mTimerDispersion.Start(); break; @@ -753,7 +764,7 @@ void RunTest( Application& application ) // Entry point for Linux & Tizen applications // -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv );