[problem] Unable to use the pan velocity values in constraint.
[cause] They are not properties.
[solution] Add properties which use this.
Change-Id: I066a528ab0f56c1208e891d2f0d7a698ce09feac
Signed-off-by: Adeel Kazmi <adeel.kazmi@samsung.com>
Vector2 screenPosition;
Vector2 screenDisplacement;
+ Vector2 screenVelocity;
Vector2 localPosition;
Vector2 localDisplacement;
+ Vector2 localVelocity;
bool called;
void Reset()
{
- screenPosition = screenDisplacement = localPosition = localDisplacement = Vector2::ZERO;
+ screenPosition = screenDisplacement = screenVelocity = localPosition = localDisplacement = localVelocity = Vector2::ZERO;
called = false;
}
};
Vector3 operator()(const Vector3& current,
const PropertyInput& screenPositionProperty,
const PropertyInput& screenDisplacementProperty,
+ const PropertyInput& screenVelocityProperty,
const PropertyInput& localPositionProperty,
- const PropertyInput& localDisplacementProperty)
+ const PropertyInput& localDisplacementProperty,
+ const PropertyInput& localVelocityProperty)
{
constraintData.screenPosition = screenPositionProperty.GetVector2();
constraintData.screenDisplacement = screenDisplacementProperty.GetVector2();
+ constraintData.screenVelocity = screenVelocityProperty.GetVector2();
constraintData.localPosition = localPositionProperty.GetVector2();
constraintData.localDisplacement = localDisplacementProperty.GetVector2();
+ constraintData.localVelocity = localVelocityProperty.GetVector2();
constraintData.called = true;
return Vector3::ZERO;
}
Vector2 localPosition,
Vector2 screenDisplacement = Vector2::ONE,
Vector2 localDisplacement = Vector2::ONE,
- Vector2 velocity = Vector2::ONE,
+ Vector2 screenVelocity = Vector2::ONE,
+ Vector2 localVelocity = Vector2::ONE,
unsigned int numberOfTouches = 1 )
{
PanGesture pan( state );
pan.screenDisplacement = screenDisplacement;
pan.displacement = localDisplacement;
- pan.screenVelocity = pan.velocity = velocity;
+ pan.screenVelocity = screenVelocity;
+ pan.velocity = localVelocity;
+
pan.numberOfTouches = numberOfTouches;
return pan;
ConstraintData constraintData;
actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
+ Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
Source( detector, PanGestureDetector::LOCAL_POSITION ),
Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
+ Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
PanConstraint( constraintData ) ) );
// Render and notify
Vector2 screenPosition( 20.0f, 20.0f );
Vector2 screenDisplacement( 1.0f, 1.0f );
+ Vector2 screenVelocity( 1.3f, 4.0f );
Vector2 localPosition( 21.0f, 21.0f );
Vector2 localDisplacement( 0.5f, 0.5f );
+ Vector2 localVelocity( 1.5f, 2.5f );
- PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement ) );
+ PanGestureDetector::SetPanGestureProperties( GeneratePan( 1u, Gesture::Started, screenPosition, localPosition, screenDisplacement, localDisplacement, screenVelocity, localVelocity ) );
DALI_TEST_EQUALS( renderController.WasCalled( TestRenderController::RequestUpdateFunc ), true, TEST_LOCATION );
// Render and notify
DALI_TEST_EQUALS( constraintData.localPosition, localPosition, TEST_LOCATION );
DALI_TEST_EQUALS( constraintData.screenDisplacement, screenDisplacement, TEST_LOCATION );
DALI_TEST_EQUALS( constraintData.localDisplacement, localDisplacement, TEST_LOCATION );
+ DALI_TEST_EQUALS( constraintData.screenVelocity, screenVelocity, TEST_LOCATION );
+ DALI_TEST_EQUALS( constraintData.localVelocity, localVelocity, TEST_LOCATION );
constraintData.Reset();
END_TEST;
}
ConstraintData constraintData;
actor.ApplyConstraint( Constraint::New<Vector3>( property, Source( detector, PanGestureDetector::SCREEN_POSITION ),
Source( detector, PanGestureDetector::SCREEN_DISPLACEMENT ),
+ Source( detector, PanGestureDetector::SCREEN_VELOCITY ),
Source( detector, PanGestureDetector::LOCAL_POSITION ),
Source( detector, PanGestureDetector::LOCAL_DISPLACEMENT ),
+ Source( detector, PanGestureDetector::LOCAL_VELOCITY ),
PanConstraint( constraintData ) ) );
// Render and notify
*/
class PanGestureDetector : public GestureDetector
{
-public: // Typedefs
+public:
- // Signals
+ // Typedefs
typedef SignalV2< void (Actor, PanGesture) > DetectedSignalV2; ///< Pan gesture detected signal type
- // Signal Names
- static const char* const SIGNAL_PAN_DETECTED; ///< name "pan-detected"
-
// Directional Pan
typedef std::pair< Radian, Radian > AngleThresholdPair; ///< Range of angles for a direction
typedef std::vector< AngleThresholdPair > AngleContainer; ///< Group of angular thresholds for all directions
static const Radian DEFAULT_THRESHOLD; ///< The default threshold is PI * 0.25 radians (or 45 degrees).
- // Default Properties
+ /// @name Properties
+ /** @{ */
static const Property::Index SCREEN_POSITION; ///< name "screen-position", type VECTOR2
static const Property::Index SCREEN_DISPLACEMENT; ///< name "screen-displacement", type VECTOR2
+ static const Property::Index SCREEN_VELOCITY; ///< name "screen-velocity", type VECTOR2
static const Property::Index LOCAL_POSITION; ///< name "local-position", type VECTOR2
static const Property::Index LOCAL_DISPLACEMENT; ///< name "local-displacement", type VECTOR2
+ static const Property::Index LOCAL_VELOCITY; ///< name "local-velocity", type VECTOR2
static const Property::Index PANNING; ///< name "panning", type BOOLEAN
+ /** @} */
+
+ /// @name Signals
+ /** @{ */
+ static const char* const SIGNAL_PAN_DETECTED; ///< name "pan-detected", @see DetectedSignal()
+ /** @} */
public: // Creation & Destruction
#include <dali/public-api/math/radian.h>
#include <dali/public-api/math/degree.h>
#include <dali/integration-api/debug.h>
+#include <dali/internal/event/actors/actor-impl.h>
#include <dali/internal/event/common/property-index-ranges.h>
#include <dali/internal/event/common/thread-local-storage.h>
#include <dali/internal/event/events/gesture-event-processor.h>
const Property::Index PanGestureDetector::SCREEN_POSITION = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
const Property::Index PanGestureDetector::SCREEN_DISPLACEMENT = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 1;
-const Property::Index PanGestureDetector::LOCAL_POSITION = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 2;
-const Property::Index PanGestureDetector::LOCAL_DISPLACEMENT = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 3;
-const Property::Index PanGestureDetector::PANNING = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 4;
+const Property::Index PanGestureDetector::SCREEN_VELOCITY = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 2;
+const Property::Index PanGestureDetector::LOCAL_POSITION = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 3;
+const Property::Index PanGestureDetector::LOCAL_DISPLACEMENT = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 4;
+const Property::Index PanGestureDetector::LOCAL_VELOCITY = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 5;
+const Property::Index PanGestureDetector::PANNING = Internal::DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT + 6;
namespace Internal
{
// Properties
-const std::string DEFAULT_PROPERTY_NAMES[] =
+PropertyDetails DEFAULT_PROPERTIES[] =
{
- "screen-position",
- "screen-displacement",
- "local-position",
- "local-displacement",
- "panning",
-};
-const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTY_NAMES ) / sizeof( std::string );
-
-const Property::Type DEFAULT_PROPERTY_TYPES[DEFAULT_PROPERTY_COUNT] =
-{
- Property::VECTOR2, // SCREEN_POSITION
- Property::VECTOR2, // SCREEN_DISPLACEMENT
- Property::VECTOR2, // LOCAL_POSITION
- Property::VECTOR2, // LOCAL_DISPLACEMENT
- Property::BOOLEAN, // PANNING
+ { "screen-position", Property::VECTOR2, false, false, true },
+ { "screen-displacement", Property::VECTOR2, false, false, true },
+ { "screen-velocity", Property::VECTOR2, false, false, true },
+ { "local-position", Property::VECTOR2, false, false, true },
+ { "local-displacement", Property::VECTOR2, false, false, true },
+ { "local-velocity", Property::VECTOR2, false, false, true },
+ { "panning", Property::BOOLEAN, false, false, true },
};
+const int DEFAULT_PROPERTY_COUNT = sizeof( DEFAULT_PROPERTIES ) / sizeof( DEFAULT_PROPERTIES[0] );
BaseHandle Create()
{
const int start = DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
for ( int i = 0; i < DEFAULT_PROPERTY_COUNT; ++i )
{
- ( *mDefaultPropertyLookup )[ DEFAULT_PROPERTY_NAMES[i] ] = i + start;
+ ( *mDefaultPropertyLookup )[ DEFAULT_PROPERTIES[i].name ] = i + start;
}
}
}
index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
{
- return DEFAULT_PROPERTY_NAMES[ index ];
+ return DEFAULT_PROPERTIES[ index ].name;
}
else
{
index -= DEFAULT_GESTURE_DETECTOR_PROPERTY_MAX_COUNT;
if ( ( index >= 0 ) && ( index < DEFAULT_PROPERTY_COUNT ) )
{
- return DEFAULT_PROPERTY_TYPES[ index ];
+ return DEFAULT_PROPERTIES[ index ].type;
}
else
{
break;
}
+ case Dali::PanGestureDetector::SCREEN_VELOCITY:
+ {
+ if(mSceneObject)
+ {
+ value = mSceneObject->GetScreenVelocityProperty().Get();
+ }
+ else
+ {
+ value = Vector2();
+ }
+ break;
+ }
+
case Dali::PanGestureDetector::LOCAL_POSITION:
{
if(mSceneObject)
break;
}
+ case Dali::PanGestureDetector::LOCAL_VELOCITY:
+ {
+ if(mSceneObject)
+ {
+ value = mSceneObject->GetLocalVelocityProperty().Get();
+ }
+ else
+ {
+ value = Vector2();
+ }
+ break;
+ }
+
case Dali::PanGestureDetector::PANNING:
{
if(mSceneObject)
break;
}
+ case Dali::PanGestureDetector::SCREEN_VELOCITY:
+ {
+ property = &mSceneObject->GetScreenVelocityProperty();
+ break;
+ }
+
case Dali::PanGestureDetector::LOCAL_POSITION:
{
property = &mSceneObject->GetLocalPositionProperty();
break;
}
+ case Dali::PanGestureDetector::LOCAL_VELOCITY:
+ {
+ property = &mSceneObject->GetLocalVelocityProperty();
+ break;
+ }
+
case Dali::PanGestureDetector::PANNING:
{
property = &mSceneObject->GetPanningProperty();
}
}
-void PanGesture::SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut)
+void PanGesture::SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut, unsigned int lastVSyncTime)
{
if( mInGesture )
{
// make current displacement relative to previous update-frame now.
gestureOut.screen.displacement = gestureOut.screen.position - mLastEventGesture.screen.position;
gestureOut.local.displacement = gestureOut.local.position - mLastEventGesture.local.position;
+ // calculate velocity relative to previous update-frame
+ unsigned int timeDiff( lastVSyncTime - mLastEventGesture.time );
+ gestureOut.screen.velocity = gestureOut.screen.displacement / timeDiff;
+ gestureOut.local.velocity = gestureOut.local.displacement / timeDiff;
}
+
+ gestureOut.time = lastVSyncTime;
}
}
bool PanGesture::UpdateProperties( unsigned int lastVSyncTime, unsigned int nextVSyncTime )
{
- bool propertiesUpdated( false );
-
if( !mInGesture )
{
// clear current pan history
}
case AVERAGE:
{
- SimpleAverageAlgorithm(justStarted, nextGesture);
+ SimpleAverageAlgorithm(justStarted, nextGesture, lastVSyncTime);
// make latest gesture equal to current gesture after averaging
updateProperties = true;
break;
mPanning.Set( mInGesture & !justFinished );
mScreenPosition.Set( nextGesture.screen.position );
mScreenDisplacement.Set( nextGesture.screen.displacement );
+ mScreenVelocity.Set( nextGesture.screen.velocity );
mLocalPosition.Set( nextGesture.local.position );
mLocalDisplacement.Set( nextGesture.local.displacement );
-
- propertiesUpdated = true;
+ mLocalVelocity.Set( nextGesture.local.velocity );
}
if( mProfiling )
mProfiling->ClearData();
}
- return propertiesUpdated;
+ return updateProperties;
}
const GesturePropertyBool& PanGesture::GetPanningProperty() const
return mScreenPosition;
}
+const GesturePropertyVector2& PanGesture::GetScreenVelocityProperty() const
+{
+ return mScreenVelocity;
+}
+
const GesturePropertyVector2& PanGesture::GetScreenDisplacementProperty() const
{
return mScreenDisplacement;
return mLocalDisplacement;
}
+const GesturePropertyVector2& PanGesture::GetLocalVelocityProperty() const
+{
+ return mLocalVelocity;
+}
+
void PanGesture::SetPredictionMode(PredictionMode mode)
{
mPredictionMode = mode;
/**
* USes last two gestures
*
+ * @param[in] justStarted Whether the pan has just started.
* @param[out] gestureOut Output gesture using average values from last two gestures
+ * @param[in] lastVSyncTime The time to set on gestureOut.
*/
- void SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut);
+ void SimpleAverageAlgorithm(bool justStarted, PanInfo& gestureOut, unsigned int lastVSyncTime);
/**
* Uses elapsed time and time stamps
const GesturePropertyVector2& GetScreenPositionProperty() const;
/**
+ * Retrieves a reference to the screen velocity property.
+ * @return The screen velocity property.
+ */
+ const GesturePropertyVector2& GetScreenVelocityProperty() const;
+
+ /**
* Retrieves a reference to the screen displacement property.
* @return The screen displacement property.
*/
const GesturePropertyVector2& GetLocalDisplacementProperty() const;
/**
+ * Retrieves a reference to the local velocity property.
+ * @return The local velocity property.
+ */
+ const GesturePropertyVector2& GetLocalVelocityProperty() const;
+
+ /**
* @brief Sets the prediction mode of the pan gesture
*
* @param[in] mode The prediction mode
GesturePropertyBool mPanning; ///< panning flag
GesturePropertyVector2 mScreenPosition; ///< screen-position
GesturePropertyVector2 mScreenDisplacement; ///< screen-displacement
+ GesturePropertyVector2 mScreenVelocity; ///< screen-velocity
GesturePropertyVector2 mLocalPosition; ///< local-position
GesturePropertyVector2 mLocalDisplacement; ///< local-displacement
+ GesturePropertyVector2 mLocalVelocity; ///< local-velocity
PanInfo mGestures[PAN_GESTURE_HISTORY]; ///< Circular buffer storing the 4 most recent gestures.
PanInfoHistory mPanHistory;