* Method to project a point on a circle of radius halfSide at given
* angle onto a square of side 2 * halfSide
*/
-void CircleSquareProjection( Vector3& position, Degree angle, float halfSide )
+void CircleSquareProjection( Vector3& position, Radian angle, float halfSide )
{
- Radian angleInRadians(angle);
-
// 135 90 45
// +--+--+
// | \|/ |
// | /|\ |
// +--+--+
// 225 270 315
- if( angle >= 45.0f && angle < 135.0f )
+ if( angle >= Dali::ANGLE_45 && angle < Dali::ANGLE_135 )
{
- position.x = halfSide * cosf(angleInRadians) / sinf(angleInRadians);
+ position.x = halfSide * cosf(angle) / sinf(angle);
position.y = -halfSide;
}
- else if( angle >= 135.0f && angle < 225.0f )
+ else if( angle >= Dali::ANGLE_135 && angle < Dali::ANGLE_225 )
{
position.x = -halfSide;
- position.y = halfSide * sinf(angleInRadians) / cosf(angleInRadians);
+ position.y = halfSide * sinf(angle) / cosf(angle);
}
- else if( angle >= 225.0f && angle < 315.0f )
+ else if( angle >= Dali::ANGLE_225 && angle < Dali::ANGLE_315 )
{
- position.x = -halfSide * cosf(angleInRadians) / sinf(angleInRadians);
+ position.x = -halfSide * cosf(angle) / sinf(angle);
position.y = halfSide;
}
else
{
position.x = halfSide;
- position.y = -halfSide * sinf(angleInRadians) / cosf(angleInRadians);
+ position.y = -halfSide * sinf(angle) / cosf(angle);
}
position.z = 0.0f;
}
mStencilActor.SetOrientation( Degree(mInitialAngle), Vector3::ZAXIS );
- mStencilActor.SetProperty( mRotationAngleIndex, static_cast<float>(mInitialSector) );
+ mStencilActor.SetProperty( mRotationAngleIndex, mInitialSector.degree );
if( mRotateActors )
{
Actor actor = mLayer.GetChildAt(i);
if( actor != mStencilActor )
{
- anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mInitialActorAngle ) ), Vector3::ZAXIS ) );
+ anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( mInitialActorAngle ), Vector3::ZAXIS ) );
}
}
}
- anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), static_cast<float>(mFinalSector), mEasingFunction, TimePeriod( offsetTime, duration ) );
- anim.AnimateTo( Property( mStencilActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mFinalAngle ) ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) );
+ anim.AnimateTo( Property( mStencilActor, mRotationAngleIndex ), mFinalSector.degree, mEasingFunction, TimePeriod( offsetTime, duration ) );
+ anim.AnimateTo( Property( mStencilActor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalAngle ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) );
if( mRotateActorsWithStencil )
{
Actor actor = mLayer.GetChildAt(i);
if( actor != mStencilActor )
{
- anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mFinalAngle - mInitialAngle ) ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) );
+ anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mFinalAngle.degree - mInitialAngle.degree ) ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) );
}
}
}
Actor actor = mLayer.GetChildAt(i);
if( actor != mStencilActor )
{
- anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( mFinalActorAngle ) ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) );
+ anim.AnimateTo( Property( actor, Actor::Property::ORIENTATION ), Quaternion( Radian( mFinalActorAngle ), Vector3::ZAXIS ), mEasingFunction, TimePeriod( offsetTime, duration ) );
}
}
}
mStencilActor.SetCullFace(CullNone); // Allow clockwise & anticlockwise faces
mStartAngleIndex = mStencilActor.RegisterProperty("start-angle", Property::Value(0.0f));
- mRotationAngleIndex = mStencilActor.RegisterProperty("rotation-angle", Property::Value(initialSector));
+ mRotationAngleIndex = mStencilActor.RegisterProperty("rotation-angle", Property::Value(initialSector.degree));
Source srcStart( mStencilActor, mStartAngleIndex );
- Source srcRot( mStencilActor, mRotationAngleIndex );
+ Source srcRotation( mStencilActor, mRotationAngleIndex );
// Constrain the vertices of the square mesh to sweep out a sector as the
// rotation angle is animated.
constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(2, AnimatableVertex::Property::POSITION), SquareFanConstraint(0) );
constraint.AddSource( srcStart );
- constraint.AddSource( srcRot );
+ constraint.AddSource( srcRotation );
constraint.Apply();
constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(3, AnimatableVertex::Property::POSITION), SquareFanConstraint(1) );
constraint.AddSource( srcStart );
- constraint.AddSource( srcRot );
+ constraint.AddSource( srcRotation );
constraint.Apply();
constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(4, AnimatableVertex::Property::POSITION), SquareFanConstraint(2) );
constraint.AddSource( srcStart );
- constraint.AddSource( srcRot );
+ constraint.AddSource( srcRotation );
constraint.Apply();
constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(5, AnimatableVertex::Property::POSITION), SquareFanConstraint(3) );
constraint.AddSource( srcStart );
- constraint.AddSource( srcRot );
+ constraint.AddSource( srcRotation );
constraint.Apply();
constraint = Constraint::New<Vector3>( mMesh, mMesh.GetPropertyIndex(6, AnimatableVertex::Property::POSITION), SquareFanConstraint(4) );
constraint.AddSource( srcStart );
- constraint.AddSource( srcRot );
+ constraint.AddSource( srcRotation );
constraint.Apply();
mStencilActor.SetDrawMode( DrawMode::STENCIL );
const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
const char* APPLICATION_TITLE_PAN_LIGHT( "Lighting: Pan Light" );
-const char* APPLICATION_TITLE_PAN_OBJECT( "Lighting: Pan Object" );
+const char* APPLICATION_TITLE_PAN_OBJECT( "Lighting: Rotate Object" );
const char* APPLICATION_TITLE_PAN_SCENE( "Lighting: Pan Scene" );
const char* APPLICATION_TITLE_ROTATE_SCENE( "Lighting: Rotate Scene" );
const char* CHANGE_EFFECT_IMAGE( DALI_IMAGE_DIR "icon-change.png" );
const char* SCENE_IMAGE_2( DALI_IMAGE_DIR "gallery-small-42.jpg");
const char* SCENE_IMAGE_3( DALI_IMAGE_DIR "gallery-small-48.jpg");
-const Quaternion JAUNTY_ROTATION(Math::PI/5.0f, Math::PI/5.0f, 0.0f); // Euler angles
const float MIN_PINCH_SCALE( 0.3f );
const float MAX_PINCH_SCALE( 2.05f );
const Vector2 DEFAULT_STAGE_SIZE( 480.0f, 800.0f );
+const float X_ROTATION_DISPLACEMENT_FACTOR = 60.f;
+const float Y_ROTATION_DISPLACEMENT_FACTOR = 60.f;
+const float LIGHT_PAN_X_DISPLACEMENT_FACTOR = 180.f;
+const float LIGHT_PAN_Y_DISPLACEMENT_FACTOR = 180.f;
+
}
/**
: mApp(app),
mPaused(false),
mTranslation(Vector3::ZERO),
- mLongitudinal(15.0f),
- mAxisTilt(30.0f),
- mLightLongitudinal(0.0f),
- mLightAxisTilt(0.0f),
- mObjectLongitudinal(0.0f),
- mObjectAxisTilt(0.0f),
+ mSceneYRotation( Dali::ANGLE_30 * 0.5f ),
+ mSceneXRotation( Dali::ANGLE_30 ),
+ mLightYRotation(0.0f),
+ mLightXRotation(0.0f),
+ mObjectYRotation(0.0f),
+ mObjectXRotation(0.0f),
mPinchScale(0.5f),
mScaleAtPinchStart(0.5f),
mPanState(PAN_SCENE)
}
public:
- struct PositionInFrontOf
- {
- PositionInFrontOf()
- {
- }
-
- void operator()( Vector3& current, const PropertyInputContainer& inputs )
- {
- current = inputs[0]->GetVector3();
- current.z += 1.0f;
- }
- };
struct RotationConstraint
{
void operator()( Quaternion& current, const PropertyInputContainer& inputs )
{
- Degree angle( inputs[0]->GetFloat() );
- current = Quaternion( Radian(angle) * mSign, Vector3::YAXIS );
+ Radian angle( inputs[0]->GetFloat() );
+ current = Quaternion( angle * mSign, Vector3::YAXIS );
}
float mSign;
mView.SetPosition(Vector3(0.0f, 0.0f, -50));
mContents.SetPosition(mTranslation);
- mContents.SetOrientation(CalculateWorldRotation(Radian(mLongitudinal), Radian(mAxisTilt)));
+ mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) );
mContents.SetScale(mPinchScale, mPinchScale, mPinchScale);
mPanGestureDetector = PanGestureDetector::New();
mLightAnchor = Actor::New();
mLightAnchor.SetParentOrigin(ParentOrigin::CENTER);
mLightAnchor.SetAnchorPoint(AnchorPoint::CENTER);
- mLightAnchor.SetOrientation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt)));
+ mLightAnchor.SetOrientation( CalculateWorldRotation( mLightXRotation, mLightYRotation ) );
// Work out a scaling factor as the initial light position was calculated for desktop
// Need to scale light position as scene actor size is based on stage size (i.e. much bigger on device)
mImageActor2.Add(mImageActor1);
mImageActor2.Add(mImageActor3);
- Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value(30.0f));
+ Property::Index angleIndex = mImageActor2.RegisterProperty("angle", Property::Value( Dali::ANGLE_30 ) );
Source angleSrc( mImageActor2, angleIndex );
Constraint constraint = Constraint::New<Quaternion>( mImageActor1, Actor::Property::ORIENTATION, RotationConstraint(-1.0f) );
// Want to animate angle from 30 => -30 and back again smoothly.
- mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-30.0f), AlphaFunctions::Sin );
+ mSceneAnimation.AnimateTo( Property( mImageActor2, angleIndex ), Property::Value(-Dali::ANGLE_30), AlphaFunctions::Sin );
mSceneAnimation.SetLooping(true);
mSceneAnimation.Play();
}
- Quaternion CalculateWorldRotation(Radian longitude, Radian axisTilt )
+ Quaternion CalculateWorldRotation( Radian XRotation, Radian YRotation )
{
- Quaternion q(longitude, Vector3::YAXIS);
- Quaternion p(axisTilt, Vector3::XAXIS);
+ Quaternion p( XRotation, Vector3::XAXIS );
+ Quaternion q( YRotation, Vector3::YAXIS );
return p*q;
}
{
case PAN_LIGHT:
{
- mLightLongitudinal += gesture.displacement.x/4.0f;
- mLightAxisTilt -= gesture.displacement.y/6.0f;
- mLightAxisTilt = Clamp<float>(mLightAxisTilt, -90.0f, 90.0f);
- mLightAnchor.SetOrientation(CalculateWorldRotation(Radian(mLightLongitudinal), Radian(mLightAxisTilt)));
+ mLightXRotation = mLightXRotation - gesture.displacement.y / LIGHT_PAN_X_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis
+ mLightXRotation = Clamp(mLightXRotation, -Dali::ANGLE_45, Dali::ANGLE_45 );
+ mLightYRotation = mLightYRotation + gesture.displacement.x / LIGHT_PAN_Y_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis
+ mLightYRotation = Clamp(mLightYRotation, -Dali::ANGLE_45, Dali::ANGLE_45 );
+ mLightAnchor.SetOrientation( CalculateWorldRotation( mLightXRotation, mLightYRotation ) );
break;
}
case ROTATE_SCENE:
{
- mLongitudinal += gesture.displacement.x/4.0f;
- mAxisTilt -= gesture.displacement.y/6.0f;
- mAxisTilt = Clamp<float>(mAxisTilt, -90.0f, 90.0f);
- mContents.SetOrientation(CalculateWorldRotation(Radian(mLongitudinal), Radian(mAxisTilt)));
+ mSceneXRotation = mSceneXRotation - gesture.displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis
+ mSceneXRotation = Clamp( mSceneXRotation, -Dali::ANGLE_90, Dali::ANGLE_90 );
+ mSceneYRotation = mSceneYRotation + gesture.displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis
+ mSceneYRotation = Clamp( mSceneYRotation, -Dali::ANGLE_90, Dali::ANGLE_90 );
+ mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) );
break;
}
- case PAN_OBJECT:
+ case ROTATE_OBJECT:
{
- mObjectLongitudinal += gesture.displacement.x/4.0f;
- mObjectAxisTilt -= gesture.displacement.y/6.0f;
- mObjectAxisTilt = Clamp<float>(mObjectAxisTilt, -90.0f, 90.0f);
- mSceneActor.SetOrientation(CalculateWorldRotation(Radian(mObjectLongitudinal), Radian(mObjectAxisTilt)));
+ mObjectXRotation = mObjectXRotation - gesture.displacement.y / X_ROTATION_DISPLACEMENT_FACTOR; // X displacement rotates around Y axis
+ mObjectYRotation = mObjectYRotation + gesture.displacement.x / Y_ROTATION_DISPLACEMENT_FACTOR; // Y displacement rotates around X axis
+ mSceneActor.SetOrientation( CalculateWorldRotation( mObjectXRotation, mObjectYRotation ) );
break;
}
}
mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_LIGHT) );
break;
case PAN_LIGHT:
- mPanState = PAN_OBJECT;
+ mPanState = ROTATE_OBJECT;
mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_OBJECT) );
break;
- case PAN_OBJECT:
+ case ROTATE_OBJECT:
mPanState = PAN_SCENE;
mTitleActor.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_PAN_SCENE) );
break;
mContents.SetPosition(mTranslation);
// Align scene so that light anchor orientation is Z Axis
- mAxisTilt = -mLightAxisTilt;
- mLongitudinal = -mLightLongitudinal;
- mContents.SetOrientation(CalculateWorldRotation(Radian(mLongitudinal), Radian(mAxisTilt)));
+ mSceneXRotation = -mLightXRotation;
+ mSceneYRotation = -mLightYRotation;
+ mContents.SetOrientation( CalculateWorldRotation( mSceneXRotation, mSceneYRotation ) );
return true;
}
PinchGestureDetector mPinchGestureDetector;
TapGestureDetector mTapGestureDetector;
Vector3 mTranslation;
- Degree mLongitudinal;
- Degree mAxisTilt;
- Degree mLightLongitudinal;
- Degree mLightAxisTilt;
- Degree mObjectLongitudinal;
- Degree mObjectAxisTilt;
+ Radian mSceneYRotation;
+ Radian mSceneXRotation;
+ Radian mLightYRotation;
+ Radian mLightXRotation;
+ Radian mObjectYRotation;
+ Radian mObjectXRotation;
float mPinchScale;
float mScaleAtPinchStart;
PAN_SCENE,
ROTATE_SCENE,
PAN_LIGHT,
- PAN_OBJECT
+ ROTATE_OBJECT
};
PanState mPanState;