playMaker

Author Topic: quaternion Lerp  (Read 5422 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
quaternion Lerp
« on: February 17, 2012, 05:55:32 AM »
Hi,

 Here is a quaternion lerp. Network being now accessible, these kind of function becomes necessary when synching players movement.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Interpolates between from and to by t and normalizes the result afterwards.")]
public class QuaternionLerp : FsmStateAction
{
[RequiredField]
[Tooltip("From Quaternion.")]
public FsmQuaternion fromQuaternion;

[RequiredField]
[Tooltip("To Quaternion.")]
public FsmQuaternion toQuaternion;

[RequiredField]
[Tooltip("Interpolate between fromQuaternion and toQuaternion by this amount. Value is clamped to 0-1 range. 0 = fromQuaternion; 1 = toQuaternion; 0.5 = half way between.")]
public FsmFloat amount;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("Store the result in this quaternion variable.")]
public FsmQuaternion storeResult;

[Tooltip("Repeat every frame. Useful if any of the values are changing.")]
public bool everyFrame;

public override void Reset()
{
fromQuaternion = new FsmQuaternion { UseVariable = true };
toQuaternion = new FsmQuaternion { UseVariable = true };
storeResult = null;
everyFrame = true;
}

public override void OnEnter()
{
DoQuatLerp();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
DoQuatLerp();
}

void DoQuatLerp()
{
storeResult.Value = Quaternion.Lerp(fromQuaternion.Value, toQuaternion.Value, amount.Value);
}
}
}



Bye,

 jean

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: quaternion Lerp
« Reply #1 on: February 19, 2013, 05:20:27 PM »
Hi, could I also get slerp, euler and angleaxis?

These seem to be what I need to solve a problem I have.

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: quaternion Lerp
« Reply #2 on: March 18, 2013, 01:58:08 AM »
Hi,

 ok, done, please get all the actions in that following package:

https://hutonggames.fogbugz.com/default.asp?W967

bye,

 Jean

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: quaternion Lerp
« Reply #3 on: March 27, 2013, 11:09:22 AM »
Thanks :)