2021-04-19 03:49:55 +00:00
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
2018-06-19 09:06:54 +00:00
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System.Linq ;
using System.Threading.Tasks ;
2020-04-14 14:37:41 +00:00
using Stride.Core.Mathematics ;
using Stride.Engine ;
2018-06-19 09:06:54 +00:00
namespace ParticlesSample
{
/// <summary>
/// Rotate the entity when user slide its finger on the screen.
/// </summary>
public class RotateEntity : AsyncScript
{
public override async Task Execute ( )
{
var rotationSpeed = 0f ;
while ( Game . IsRunning )
{
await Script . NextFrame ( ) ;
if ( Input . PointerEvents . Any ( ) )
rotationSpeed = 200f * Input . PointerEvents . Sum ( x = > x . DeltaPosition . X ) ;
rotationSpeed * = 0.93f ;
var elapsedTime = ( float ) Game . UpdateTime . Elapsed . TotalSeconds ;
Entity . Transform . Rotation * = Quaternion . RotationY ( rotationSpeed * elapsedTime ) ;
}
}
}
}