diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index b4f37cb..54490fb 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -130,20 +130,19 @@ public: { } - Vector3 operator()( const Vector3& current, const PropertyInput& scrollProperty, const PropertyInput& parentSize ) + void operator()( Vector3& position, const PropertyInputContainer& inputs ) { - Vector3 pos( current ); - const float parentHeight = parentSize.GetVector3().height; + const Vector3& parentSize = inputs[1]->GetVector3(); - // Wrap bubbles vertically - if( pos.y + mShapeSize * 0.5f < -parentHeight * 0.5f ) + // Wrap bubbles verically. + if( position.y + mShapeSize * 0.5f < -parentSize.y * 0.5f ) { - pos.y = parentHeight * 0.5f + mShapeSize * 0.5f; + position.y = parentSize.y * 0.5f + mShapeSize * 0.5f; } - // Bubbles X position moves parallax to horizontal panning by a scale factor unique to each bubble - pos.x = mInitialX + ( scrollProperty.GetVector3().x * mScale ); - return pos; + // Bubbles X position moves parallax to horizontal + // panning by a scale factor unique to each bubble. + position.x = mInitialX + ( inputs[0]->GetVector3().x * mScale ); } private: @@ -756,11 +755,10 @@ void DaliTableView::InitialiseBackgroundActors( Actor actor ) child.SetPosition( childPos ); // Define bubble horizontal parallax and vertical wrapping - Constraint animConstraint = Constraint::New < Vector3 > ( Actor::Property::POSITION, - Source( mScrollView, ScrollView::Property::SCROLL_POSITION ), - Dali::ParentSource( Dali::Actor::Property::SIZE ), - AnimateBubbleConstraint( childPos, Random::Range( -0.85f, 0.25f ), childSize.height ) ); - child.ApplyConstraint( animConstraint ); + Constraint animConstraint = Constraint::New < Vector3 > ( child, Actor::Property::POSITION, AnimateBubbleConstraint( childPos, Random::Range( -0.85f, 0.25f ), childSize.height ) ); + animConstraint.AddSource( Source( mScrollView, ScrollView::Property::SCROLL_POSITION ) ); + animConstraint.AddSource( Dali::ParentSource( Dali::Actor::Property::SIZE ) ); + animConstraint.Apply(); // Kickoff animation Animation animation = Animation::New( Random::Range( 40.0f, 80.0f ) ); diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index f8cce6f..9aa0894 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -73,65 +73,6 @@ const int TOTAL_LEVELS(3); ///< // constraints //////////////////////////////////////////////////////////////// /** - * CollisionConstraint generates a collision vector - * between two actors a and b, assuming they're rectangular - * based on their size. - */ -struct CollisionConstraint -{ - /** - * Collision Constraint constructor - * The adjust (optional) parameter can be used to add a margin - * to the actors. A +ve size will result in larger collisions, - * while a -ve size will result in tighter collisions. - * - * @param[in] adjust (optional) Adjusts the rectangular size detection - */ - CollisionConstraint(Vector3 adjust = Vector3::ZERO) - : mAdjust(adjust) - { - } - - /** - * Generates collision vector indicating whether Actor's A and B - * have overlapped eachother, and the relative position of Actor B to A. - * - * @param[in] current The current collision-property (ignored) - * @param[in] propertyA Actor A's Position property. - * @param[in] propertyB Actor B's Position property. - * @param[in] propertySizeA Actor A's Size property. - * @param[in] propertySizeB Actor B's Size property. - * @return The collision vector is returned. - */ - Vector3 operator()(const Vector3& current, - const PropertyInput& propertyA, - const PropertyInput& propertyB, - const PropertyInput& propertySizeA, - const PropertyInput& propertySizeB) - { - const Vector3& a = propertyA.GetVector3(); - const Vector3& b = propertyB.GetVector3(); - const Vector3& sizeA = propertySizeA.GetVector3(); - const Vector3& sizeB = propertySizeB.GetVector3(); - const Vector3 sizeComb = (sizeA + sizeB + mAdjust) * 0.5f; - - // get collision relative to a. - Vector3 delta = b - a; - - // Check if not overlapping Actors. - if( (fabsf(delta.x) > sizeComb.width) || - (fabsf(delta.y) > sizeComb.height) ) - { - delta = Vector3::ZERO; // not overlapping - } - - return delta; // overlapping, return overlap vector relative to actor a. - } - - const Vector3 mAdjust; ///< Size Adjustment value -}; - -/** * CollisionCircleRectangleConstraint generates a collision vector * between two actors a (circle) and b (rectangle) */ @@ -157,23 +98,20 @@ struct CollisionCircleRectangleConstraint * Generates collision vector indicating whether Actor's A and B * have overlapped eachother, and the relative position of Actor B to A. * - * @param[in] current The current collision-property (ignored) - * @param[in] propertyA Actor A's Position property. - * @param[in] propertyB Actor B's Position property. - * @param[in] propertySizeA Actor A's Size property. - * @param[in] propertySizeB Actor B's Size property. + * @param[in,out] current The current collision-property + * @param[in] inputs Contains: + * Actor A's Position property. + * Actor B's Position property. + * Actor A's Size property. + * Actor B's Size property. * @return The collision vector is returned. */ - Vector3 operator()(const Vector3& current, - const PropertyInput& propertyA, - const PropertyInput& propertyB, - const PropertyInput& propertySizeA, - const PropertyInput& propertySizeB) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - const Vector3& a = propertyA.GetVector3(); - const Vector3 b = propertyB.GetVector3() + mAdjustPosition; - const Vector3& sizeA = propertySizeA.GetVector3(); - const Vector3& sizeB = propertySizeB.GetVector3(); + const Vector3& a = inputs[0]->GetVector3(); + const Vector3 b = inputs[1]->GetVector3() + mAdjustPosition; + const Vector3& sizeA = inputs[2]->GetVector3(); + const Vector3& sizeB = inputs[3]->GetVector3(); const Vector3 sizeA2 = sizeA * 0.5f; // circle radius const Vector3 sizeB2 = (sizeB + mAdjustSize) * 0.5f; // rectangle half rectangle. @@ -211,10 +149,12 @@ struct CollisionCircleRectangleConstraint if(delta.Length() < sizeA2.x) { delta.Normalize(); - return delta; + current = delta; + } + else + { + current = Vector3::ZERO; } - - return Vector3::ZERO; } const Vector3 mAdjustPosition; ///< Position Adjustment value @@ -243,20 +183,17 @@ struct WobbleConstraint } /** - * @param[in] current The current rotation property (ignored) - * @param[in] propertyWobble The wobble property (value from 0.0f to 1.0f) + * @param[in,out] current The current rotation property + * @param[in] inputs Contains the wobble property (value from 0.0f to 1.0f) * @return The rotation (quaternion) is generated. */ - Quaternion operator()(const Quaternion& current, - const PropertyInput& propertyWobble) + void operator()( Quaternion& current, const PropertyInputContainer& inputs ) { - const float& wobble = propertyWobble.GetFloat(); + const float& wobble = inputs[0]->GetFloat(); float f = sinf(wobble * 10.0f) * (1.0f-wobble); - Quaternion q(mDeviation * f, Vector3::ZAXIS); - - return q; + current = Quaternion(mDeviation * f, Vector3::ZAXIS); } const float mDeviation; ///< Deviation factor in radians. @@ -348,10 +285,9 @@ private: mPaddleImage.SetSize( mPaddleFullSize ); mWobbleProperty = mPaddle.RegisterProperty(WOBBLE_PROPERTY_NAME, 0.0f); - Constraint wobbleConstraint = Constraint::New( Actor::Property::ORIENTATION, - LocalSource(mWobbleProperty), - WobbleConstraint(10.0f)); - mPaddle.ApplyConstraint(wobbleConstraint); + Constraint wobbleConstraint = Constraint::New( mPaddle, Actor::Property::ORIENTATION, WobbleConstraint(10.0f)); + wobbleConstraint.AddSource( LocalSource(mWobbleProperty) ); + wobbleConstraint.Apply(); mPaddle.SetPosition( stageSize * Vector3( PADDLE_START_POSITION ) ); mContentLayer.Add(mPaddle); @@ -377,13 +313,12 @@ private: Actor delegate = Actor::New(); stage.Add(delegate); Property::Index property = delegate.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO); - Constraint constraint = Constraint::New( property, - Source(mBall, Actor::Property::POSITION), - Source(mPaddle, Actor::Property::POSITION), - Source(mBall, Actor::Property::SIZE), - Source(mPaddle, Actor::Property::SIZE), - CollisionCircleRectangleConstraint( -Vector3(0.0f, mPaddleHitMargin.height * 0.575f, 0.0f),-Vector3(mPaddleHitMargin) )); - delegate.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( delegate, property, CollisionCircleRectangleConstraint( -Vector3(0.0f, mPaddleHitMargin.height * 0.575f, 0.0f),-Vector3(mPaddleHitMargin) ) ); + constraint.AddSource( Source(mBall, Actor::Property::POSITION) ); + constraint.AddSource( Source(mPaddle, Actor::Property::POSITION) ); + constraint.AddSource( Source(mBall, Actor::Property::SIZE) ); + constraint.AddSource( Source(mPaddle, Actor::Property::SIZE) ); + constraint.Apply(); PropertyNotification paddleNotification = delegate.AddPropertyNotification( property, GreaterThanCondition(0.0f) ); paddleNotification.NotifySignal().Connect( this, &ExampleController::OnHitPaddle ); @@ -602,13 +537,12 @@ private: // Add a constraint on the brick between it and the ball generating a collision-property Property::Index property = brick.RegisterProperty(COLLISION_PROPERTY_NAME, Vector3::ZERO); - Constraint constraint = Constraint::New( property, - Source(mBall, Actor::Property::POSITION), - Source(brick, Actor::Property::POSITION), - Source(mBall, Actor::Property::SIZE), - Source(brick, Actor::Property::SIZE), - CollisionCircleRectangleConstraint(BRICK_COLLISION_MARGIN)); - brick.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( brick, property, CollisionCircleRectangleConstraint(BRICK_COLLISION_MARGIN) ); + constraint.AddSource( Source(mBall, Actor::Property::POSITION) ); + constraint.AddSource( Source(brick, Actor::Property::POSITION) ); + constraint.AddSource( Source(mBall, Actor::Property::SIZE) ); + constraint.AddSource( Source(brick, Actor::Property::SIZE) ); + constraint.Apply(); // Now add a notification on this collision-property diff --git a/examples/cluster/cluster-example.cpp b/examples/cluster/cluster-example.cpp index 2996281..5558b79 100644 --- a/examples/cluster/cluster-example.cpp +++ b/examples/cluster/cluster-example.cpp @@ -183,15 +183,16 @@ struct CarouselEffectOrientationConstraint * @param[in] current The object's current property value * @return The object's new property value */ - Vector2 operator()(const Vector2& current, - const PropertyInput& propertyOrientation) + void operator()( Vector2& current, const PropertyInputContainer& inputs ) { Vector3 axis; float angle; - propertyOrientation.GetQuaternion().ToAxisAngle( axis, angle ); - Vector2 direction( cosf(angle), sinf(angle) ); + inputs[0]->GetQuaternion().ToAxisAngle( axis, angle ); + + current.x = cosf(angle); + current.y = sinf(angle); - return mAngleSweep * direction; + current *= mAngleSweep; } Vector2 mAngleSweep; @@ -220,16 +221,13 @@ struct ShearEffectConstraint } /** - * @param[in] current The current shear effect Angle. - * @param[in] scrollOvershootProperty The overshoot property from ScrollView - * @param[in] propertyViewOrientation The orientation of the view e.g. Portrait, Landscape. + * @param[in,out] current The current shear effect Angle. + * @param[in] inputs Contains the overshoot property from ScrollView and the orientation of the view e.g. Portrait, Landscape. * @return angle to provide ShearShaderEffect */ - float operator()(const float& current, - const PropertyInput& scrollOvershootProperty, - const PropertyInput& propertyViewOrientation) + void operator()( float& current, const PropertyInputContainer& inputs ) { - float f = scrollOvershootProperty.GetVector3().x; + float f = inputs[0]->GetVector3().x; float mag = fabsf(f); float halfWidth = mStageSize.x * 0.5f; @@ -245,11 +243,11 @@ struct ShearEffectConstraint // the component mask passed in. Vector3 axis; float angle; - propertyViewOrientation.GetQuaternion().ToAxisAngle( axis, angle ); + inputs[1]->GetQuaternion().ToAxisAngle( axis, angle ); Vector2 direction( cosf(angle), sinf(angle) ); float yield = direction.x * mComponentMask.x + direction.y * mComponentMask.y; - return overshoot * mMaxOvershoot * yield; + current = overshoot * mMaxOvershoot * yield; } Vector2 mStageSize; @@ -276,15 +274,15 @@ struct ShearEffectCenterConstraint } /** - * @param[in] current The current center - * @param[in] propertyViewSize The current view size + * @param[in,out] current The current center + * @param[in] inputs Contains the current view size * @return vector to provide ShearShaderEffect */ - Vector2 operator()(const Vector2& current, - const PropertyInput& propertyViewSize) + void operator()( Vector2& current, const PropertyInputContainer& inputs ) { - float f = propertyViewSize.GetVector3().width / mStageSize.width; - return Vector2( f * mCenter.x, mCenter.y ); + float f = inputs[0]->GetVector3().width / mStageSize.width; + current.x = f * mCenter.x; + current.y = mCenter.y; } Vector2 mStageSize; @@ -313,9 +311,9 @@ struct SphereEffectOffsetConstraint * @param[in] propertyViewSize The current view size * @return vector to provide SphereShaderEffect */ - float operator()(const float& current) + void operator()( float& current, const PropertyInputContainer& /* inputs */ ) { - return current + mOffset; + current += mOffset; } float mOffset; @@ -375,11 +373,11 @@ struct ClusterInfo } - Cluster mCluster; ///< Cluster instance - int mIndex; ///< Cluster index - Vector3 mPosition; ///< Cluster original position - Vector3 mSize; ///< Cluster original size - ActiveConstraint mEffectConstraint; ///< Cluster constraint + Cluster mCluster; ///< Cluster instance + int mIndex; ///< Cluster index + Vector3 mPosition; ///< Cluster original position + Vector3 mSize; ///< Cluster original size + Constraint mEffectConstraint; ///< Cluster constraint }; /** @@ -691,7 +689,7 @@ public: RemoveShaderEffectRecursively( cluster ); if( i->mEffectConstraint ) { - cluster.RemoveConstraint(i->mEffectConstraint); + i->mEffectConstraint.Remove(); i->mEffectConstraint.Reset(); } } @@ -721,10 +719,10 @@ public: Vector2 shearCenter( Vector2(position.x + size.width * shearAnchor.x, position.y + size.height * shearAnchor.y) ); Property::Index centerProperty = shaderEffect.GetPropertyIndex(shaderEffect.GetCenterPropertyName()); - Constraint constraint = Constraint::New( centerProperty, - Source(mView, Actor::Property::SIZE), - ShearEffectCenterConstraint(stageSize, shearCenter) ); - shaderEffect.ApplyConstraint(constraint); + Constraint constraint = Constraint::New( shaderEffect, centerProperty, ShearEffectCenterConstraint(stageSize, shearCenter) ); + constraint.AddSource( Source(mView, Actor::Property::SIZE) ); + + constraint.Apply(); SetShaderEffectRecursively( cluster,shaderEffect ); @@ -733,16 +731,15 @@ public: Property::Index angleXAxisProperty = shaderEffect.GetPropertyIndex(shaderEffect.GetAngleXAxisPropertyName()); Property::Index angleYAxisProperty = shaderEffect.GetPropertyIndex(shaderEffect.GetAngleYAxisPropertyName()); - constraint = Constraint::New( angleXAxisProperty, - Source(mScrollView, scrollOvershootProperty), - Source(mView, Actor::Property::ORIENTATION), - ShearEffectConstraint(stageSize, SHEAR_EFFECT_MAX_OVERSHOOT, Vector2::XAXIS) ); - shaderEffect.ApplyConstraint(constraint); - constraint = Constraint::New( angleYAxisProperty, - Source(mScrollView, scrollOvershootProperty), - Source(mView, Actor::Property::ORIENTATION), - ShearEffectConstraint(stageSize, SHEAR_EFFECT_MAX_OVERSHOOT, Vector2::YAXIS) ); - shaderEffect.ApplyConstraint(constraint); + constraint = Constraint::New( shaderEffect, angleXAxisProperty, ShearEffectConstraint(stageSize, SHEAR_EFFECT_MAX_OVERSHOOT, Vector2::XAXIS) ); + constraint.AddSource( Source(mScrollView, scrollOvershootProperty) ); + constraint.AddSource( Source(mView, Actor::Property::ORIENTATION) ); + constraint.Apply(); + + constraint = Constraint::New( shaderEffect, angleYAxisProperty, ShearEffectConstraint(stageSize, SHEAR_EFFECT_MAX_OVERSHOOT, Vector2::YAXIS ) ); + constraint.AddSource( Source(mScrollView, scrollOvershootProperty) ); + constraint.AddSource( Source(mView, Actor::Property::ORIENTATION) ); + constraint.Apply(); } @@ -766,9 +763,9 @@ public: CAROUSEL_EFFECT_ANGLE_SWEEP / stageSize.width ); Property::Index anglePerUnit = shaderEffect.GetPropertyIndex( shaderEffect.GetAnglePerUnitPropertyName() ); - shaderEffect.ApplyConstraint( Constraint::New( anglePerUnit, - Source(mView, Actor::Property::ORIENTATION), - CarouselEffectOrientationConstraint( angleSweep ) ) ); + Constraint constraint = Constraint::New( shaderEffect, anglePerUnit, CarouselEffectOrientationConstraint( angleSweep ) ); + constraint.AddSource( Source(mView, Actor::Property::ORIENTATION) ); + constraint.Apply(); break; } @@ -794,11 +791,11 @@ public: // dont apply shader effect to scrollview as it might override internal shaders for bounce effect etc for( std::vector::iterator i = mClusterInfo.begin(); i != mClusterInfo.end(); ++i ) { - Constraint constraint = Constraint::New(Actor::Property::POSITION_Z, SphereEffectOffsetConstraint(SPHERE_EFFECT_POSITION_Z)); - constraint.SetRemoveAction(Constraint::Discard); Cluster cluster = i->mCluster; + i->mEffectConstraint = Constraint::New( cluster, Actor::Property::POSITION_Z, SphereEffectOffsetConstraint( SPHERE_EFFECT_POSITION_Z ) ); + i->mEffectConstraint.SetRemoveAction(Constraint::Discard); SetShaderEffectRecursively( cluster, shaderEffect ); - i->mEffectConstraint = cluster.ApplyConstraint(constraint); + i->mEffectConstraint.Apply(); } break; } diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index 632445f..4c8ea21 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -57,20 +57,16 @@ struct MagnifierPathConstraint { } - Vector3 operator()(const Vector3& current, - const PropertyInput& sizeProperty, - const PropertyInput& animationTimeProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - float time = animationTimeProperty.GetFloat(); - const Vector3& size = sizeProperty.GetVector3(); + float time = inputs[1]->GetFloat(); + const Vector3& size = inputs[0]->GetVector3(); - Vector3 range(mStageSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f); - Vector3 position(mOffset); + current = mOffset; - position.x += 0.5f * sinf(time * 0.471f) * range.width; - position.y += 0.5f * sinf(time * 0.8739f) * range.height; - - return position; + Vector3 range( mStageSize - size - Vector3::ONE * MAGNIFIER_INDENT * 2.0f ); + current.x += 0.5f * sinf(time * 0.471f) * range.width; + current.y += 0.5f * sinf(time * 0.8739f) * range.height; } Vector3 mStageSize; ///< Keep track of the stage size for determining path within stage bounds @@ -103,23 +99,19 @@ struct ConfinementConstraint { } - Vector3 operator()(const Vector3& constPosition, - const PropertyInput& sizeProperty, - const PropertyInput& parentOriginProperty, - const PropertyInput& anchorPointProperty, - const PropertyInput& referenceSizeProperty) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - const Vector3& size = sizeProperty.GetVector3(); - const Vector3 origin = parentOriginProperty.GetVector3(); - const Vector3& anchor = anchorPointProperty.GetVector3(); - const Vector3& referenceSize = referenceSizeProperty.GetVector3(); + const Vector3& size = inputs[0]->GetVector3(); + const Vector3 origin = inputs[1]->GetVector3(); + const Vector3& anchor = inputs[2]->GetVector3(); + const Vector3& referenceSize = inputs[3]->GetVector3(); Vector3 offset(mOffsetOrigin * referenceSize); - Vector3 newPosition( constPosition + offset ); - // Get actual position of Actor relative to parent's Top-Left. - Vector3 position(constPosition + offset + origin * referenceSize); + Vector3 position(current + offset + origin * referenceSize); + + current += offset; // if top-left corner is outside of Top-Left bounds, then push back in screen. Vector3 corner(position - size * anchor - mMinIndent); @@ -127,17 +119,17 @@ struct ConfinementConstraint if(mFlipHorizontal && corner.x < 0.0f) { corner.x = 0.0f; - newPosition.x += size.width; + current.x += size.width; } if(mFlipVertical && corner.y < 0.0f) { corner.y = 0.0f; - newPosition.y += size.height; + current.y += size.height; } - newPosition.x -= std::min(corner.x, 0.0f); - newPosition.y -= std::min(corner.y, 0.0f); + current.x -= std::min(corner.x, 0.0f); + current.y -= std::min(corner.y, 0.0f); // if bottom-right corner is outside of Bottom-Right bounds, then push back in screen. corner += size - referenceSize + mMinIndent + mMaxIndent; @@ -145,19 +137,17 @@ struct ConfinementConstraint if(mFlipHorizontal && corner.x > 0.0f) { corner.x = 0.0f; - newPosition.x -= size.width; + current.x -= size.width; } if(mFlipVertical && corner.y > 0.0f) { corner.y = 0.0f; - newPosition.y -= size.height; + current.y -= size.height; } - newPosition.x -= std::max(corner.x, 0.0f); - newPosition.y -= std::max(corner.y, 0.0f); - - return newPosition; + current.x -= std::max(corner.x, 0.0f); + current.y -= std::max(corner.y, 0.0f); } Vector3 mOffsetOrigin; ///< Manual Parent Offset Origin. @@ -244,14 +234,13 @@ public: overlay.Add( mMagnifier ); // Apply constraint to animate the position of the magnifier. - Constraint constraint = Constraint::New(Actor::Property::POSITION, - LocalSource(Actor::Property::SIZE), - LocalSource(Actor::Property::PARENT_ORIGIN), - LocalSource(Actor::Property::ANCHOR_POINT), - ParentSource(Actor::Property::SIZE), - ConfinementConstraint(ParentOrigin::CENTER, Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT)); + Constraint constraint = Constraint::New( mMagnifier, Actor::Property::POSITION, ConfinementConstraint(ParentOrigin::CENTER, Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT) ); + constraint.AddSource( LocalSource(Actor::Property::SIZE) ); + constraint.AddSource( LocalSource(Actor::Property::PARENT_ORIGIN) ); + constraint.AddSource( LocalSource(Actor::Property::ANCHOR_POINT) ); + constraint.AddSource( ParentSource(Actor::Property::SIZE) ); constraint.SetRemoveAction(Constraint::Discard); - mMagnifier.ApplyConstraint( constraint ); + constraint.Apply(); // Create bouncing magnifier automatically bounces around screen. mBouncingMagnifier = Toolkit::Magnifier::New(); @@ -265,18 +254,16 @@ public: ContinueAnimation(); // Apply constraint to animate the position of the magnifier. - constraint = Constraint::New(Actor::Property::POSITION, - LocalSource(Actor::Property::SIZE), - LocalSource(mAnimationTimeProperty), - MagnifierPathConstraint(mStageSize, mStageSize * 0.5f)); - mBouncingMagnifier.ApplyConstraint( constraint ); + constraint = Constraint::New( mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mStageSize, mStageSize * 0.5f) ); + constraint.AddSource( LocalSource(Actor::Property::SIZE) ); + constraint.AddSource( LocalSource(mAnimationTimeProperty) ); + constraint.Apply(); // Apply constraint to animate the source of the magnifier. - constraint = Constraint::New(mBouncingMagnifier.GetPropertyIndex( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME ), - LocalSource(Actor::Property::SIZE), - LocalSource(mAnimationTimeProperty), - MagnifierPathConstraint(mStageSize)); - mBouncingMagnifier.ApplyConstraint( constraint ); + constraint = Constraint::New( mBouncingMagnifier, mBouncingMagnifier.GetPropertyIndex( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME ), MagnifierPathConstraint(mStageSize) ); + constraint.AddSource( LocalSource(Actor::Property::SIZE) ); + constraint.AddSource( LocalSource(mAnimationTimeProperty) ); + constraint.Apply(); } /** diff --git a/examples/radial-menu/radial-sweep-view-impl.cpp b/examples/radial-menu/radial-sweep-view-impl.cpp index 6289962..bc9925c 100644 --- a/examples/radial-menu/radial-sweep-view-impl.cpp +++ b/examples/radial-menu/radial-sweep-view-impl.cpp @@ -26,9 +26,8 @@ namespace * Method to project a point on a circle of radius halfSide at given * angle onto a square of side 2 * halfSide */ -Vector3 CircleSquareProjection( Degree angle, float halfSide ) +void CircleSquareProjection( Vector3& position, Degree angle, float halfSide ) { - Vector3 position(0.0f, 0.0f, 0.0f); Radian angleInRadians(angle); // 135 90 45 @@ -58,7 +57,8 @@ Vector3 CircleSquareProjection( Degree angle, float halfSide ) position.x = halfSide; position.y = -halfSide * sinf(angleInRadians) / cosf(angleInRadians); } - return position; + + position.z = 0.0f; } float HoldZeroFastEaseInOutHoldOne(float progress) @@ -88,9 +88,9 @@ struct SquareFanConstraint { } - Vector3 operator()( const Vector3& current, const PropertyInput& start, const PropertyInput& rotation ) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - float degree = fmodf((start.GetFloat() + rotation.GetFloat()), 360.0f); + float degree = fmodf((inputs[0]->GetFloat() + inputs[1]->GetFloat()), 360.0f); if(degree < 0.0f) { degree += 360.0f; @@ -100,15 +100,17 @@ struct SquareFanConstraint float endAngle = (90.0f*mSideIndex)+45.0f; if(degree < startAngle) { - return Vector3::ZERO; + current = Vector3::ZERO; } - else if( degree >= endAngle ) + else { - degree = endAngle; + if( degree >= endAngle ) + { + degree = endAngle; + } + CircleSquareProjection( current, Degree(degree), 0.5f ); + current.x = -current.x; // Inverting X makes the animation go anti clockwise from left center } - Vector3 pos = CircleSquareProjection(Degree(degree), 0.5f); - pos.x = -pos.x; // Inverting X makes the animation go anti clockwise from left center - return pos; } int mSideIndex; @@ -362,18 +364,35 @@ void RadialSweepViewImpl::CreateStencil( Degree initialSector ) // Constrain the vertices of the square mesh to sweep out a sector as the // rotation angle is animated. - mMesh.ApplyConstraint(Constraint::New( mMesh.GetPropertyIndex(1, AnimatableVertex::Property::POSITION), - srcStart, srcStart, SquareFanConstraint(0))); - mMesh.ApplyConstraint(Constraint::New( mMesh.GetPropertyIndex(2, AnimatableVertex::Property::POSITION), - srcStart, srcRot, SquareFanConstraint(0))); - mMesh.ApplyConstraint(Constraint::New( mMesh.GetPropertyIndex(3, AnimatableVertex::Property::POSITION), - srcStart, srcRot, SquareFanConstraint(1))); - mMesh.ApplyConstraint(Constraint::New( mMesh.GetPropertyIndex(4, AnimatableVertex::Property::POSITION), - srcStart, srcRot, SquareFanConstraint(2))); - mMesh.ApplyConstraint(Constraint::New( mMesh.GetPropertyIndex(5, AnimatableVertex::Property::POSITION), - srcStart, srcRot, SquareFanConstraint(3))); - mMesh.ApplyConstraint(Constraint::New( mMesh.GetPropertyIndex(6, AnimatableVertex::Property::POSITION), - srcStart, srcRot, SquareFanConstraint(4))); + Constraint constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(1, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) ); + constraint.AddSource( srcStart ); + constraint.AddSource( srcStart ); + constraint.Apply(); + + constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(2, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) ); + constraint.AddSource( srcStart ); + constraint.AddSource( srcRot ); + constraint.Apply(); + + constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(3, AnimatableVertex::Property::POSITION), SquareFanConstraint(1) ); + constraint.AddSource( srcStart ); + constraint.AddSource( srcRot ); + constraint.Apply(); + + constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(4, AnimatableVertex::Property::POSITION), SquareFanConstraint(2) ); + constraint.AddSource( srcStart ); + constraint.AddSource( srcRot ); + constraint.Apply(); + + constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(5, AnimatableVertex::Property::POSITION), SquareFanConstraint(3) ); + constraint.AddSource( srcStart ); + constraint.AddSource( srcRot ); + constraint.Apply(); + + constraint = Constraint::New( mMesh, mMesh.GetPropertyIndex(6, AnimatableVertex::Property::POSITION), SquareFanConstraint(4) ); + constraint.AddSource( srcStart ); + constraint.AddSource( srcRot ); + constraint.Apply(); mStencilActor.SetDrawMode( DrawMode::STENCIL ); mStencilActor.SetPositionInheritanceMode(USE_PARENT_POSITION); diff --git a/examples/refraction-effect/refraction-effect-example.cpp b/examples/refraction-effect/refraction-effect-example.cpp index 951bab3..cf43e1f 100644 --- a/examples/refraction-effect/refraction-effect-example.cpp +++ b/examples/refraction-effect/refraction-effect-example.cpp @@ -56,10 +56,13 @@ struct LightOffsetConstraint { } - Vector2 operator()( const Vector2& current, const PropertyInput& spinAngleProperty) + void operator()( Vector2& current, const PropertyInputContainer& inputs ) { - float spinAngle = spinAngleProperty.GetFloat(); - return Vector2( cos(spinAngle ), sin( spinAngle ) ) * mRadius; + float spinAngle = inputs[0]->GetFloat(); + current.x = cos( spinAngle ); + current.y = sin( spinAngle ); + + current *= mRadius; } float mRadius; @@ -254,10 +257,9 @@ public: handle.SetUniform( "uLightIntensity", 2.5f ); Dali::Property::Index index = handle.RegisterProperty( "uSpinAngle", 0.f ); - Constraint constraint = Constraint::New( handle.GetPropertyIndex("uLightSpinOffset"), - LocalSource(index), - LightOffsetConstraint(stageSize.x*0.1f)); - handle.ApplyConstraint( constraint ); + Constraint constraint = Constraint::New( handle, handle.GetPropertyIndex("uLightSpinOffset"), LightOffsetConstraint(stageSize.x*0.1f) ); + constraint.AddSource( LocalSource(index) ); + constraint.Apply(); return handle; } diff --git a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp index 7345320..9ddadcb 100644 --- a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp +++ b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp @@ -100,23 +100,10 @@ public: { } - Vector3 operator()( const Vector3& current, const PropertyInput& property ) + void operator()( Vector3& current, const PropertyInputContainer& inputs ) { - Vector3 position = property.GetVector3(); - position.z += 1.0f; - return position; - } - }; - - struct QuaternionEqualToConstraint - { - QuaternionEqualToConstraint() - { - } - - Quaternion operator()( const Quaternion& current, const PropertyInput& property ) - { - return property.GetQuaternion(); + current = inputs[0]->GetVector3(); + current.z += 1.0f; } }; @@ -127,10 +114,10 @@ public: { } - Quaternion operator()( const Quaternion& current, const PropertyInput& property ) + void operator()( Quaternion& current, const PropertyInputContainer& inputs ) { - Degree angle(property.GetFloat()); - return Quaternion( Radian(angle) * mSign, Vector3::YAXIS ); + Degree angle( inputs[0]->GetFloat() ); + current = Quaternion( Radian(angle) * mSign, Vector3::YAXIS ); } float mSign; @@ -284,10 +271,14 @@ public: Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(30.0f)); Source angleSrc( mImageActor2, angleIndex ); - mImageActor1.ApplyConstraint(Constraint::New( Actor::Property::ORIENTATION, angleSrc, - RotationConstraint(-1.0f))); - mImageActor3.ApplyConstraint(Constraint::New( Actor::Property::ORIENTATION, angleSrc, - RotationConstraint(+1.0f))); + + Constraint constraint = Constraint::New( mImageActor1, Actor::Property::ORIENTATION, RotationConstraint(-1.0f) ); + constraint.AddSource( angleSrc ); + constraint.Apply(); + + constraint = Constraint::New( mImageActor3, Actor::Property::ORIENTATION, RotationConstraint(+1.0f) ); + constraint.AddSource( angleSrc ); + constraint.Apply(); mSceneAnimation = Animation::New(2.5f);