Cleaned up the LookAt code in SOP and SOG. Added support for incrementally

rotating physical objects. This does not use physics. Currently the rate
of change is determined as 1 / (PI * Strength).
This commit is contained in:
Mic Bowman
2012-01-13 14:48:56 -08:00
parent adea92f8b7
commit e1a2c44ebe
3 changed files with 34 additions and 49 deletions

View File

@@ -217,11 +217,10 @@ namespace OpenSim.Region.Framework.Scenes
public Quaternion SpinOldOrientation = Quaternion.Identity;
public Quaternion m_APIDTarget = Quaternion.Identity;
public float m_APIDDamp = 0;
public float m_APIDStrength = 0;
protected int m_APIDIterations = 0;
protected Quaternion m_APIDTarget = Quaternion.Identity;
protected float m_APIDDamp = 0;
protected float m_APIDStrength = 0;
/// <summary>
/// This part's inventory
@@ -563,22 +562,21 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public Quaternion APIDTarget
protected Quaternion APIDTarget
{
get { return m_APIDTarget; }
set { m_APIDTarget = value; }
}
public float APIDDamp
protected float APIDDamp
{
get { return m_APIDDamp; }
set { m_APIDDamp = value; }
}
public float APIDStrength
protected float APIDStrength
{
get { return m_APIDStrength; }
set { m_APIDStrength = value; }
@@ -2696,11 +2694,6 @@ namespace OpenSim.Region.Framework.Scenes
}
public void RotLookAt(Quaternion target, float strength, float damping)
{
rotLookAt(target, strength, damping);
}
public void rotLookAt(Quaternion target, float strength, float damping)
{
if (ParentGroup.IsAttachment)
{
@@ -2716,17 +2709,26 @@ namespace OpenSim.Region.Framework.Scenes
APIDDamp = damping;
APIDStrength = strength;
APIDTarget = target;
if (APIDStrength <= 0)
{
m_log.WarnFormat("[SceneObjectPart] Invalid rotation strength {0}",APIDStrength);
return;
}
m_APIDIterations = 1 + (int)(Math.PI * APIDStrength);
}
// Necessary to get the lookat deltas applied
ParentGroup.QueueForUpdateCheck();
}
public void startLookAt(Quaternion rot, float damp, float strength)
public void StartLookAt(Quaternion target, float strength, float damping)
{
APIDDamp = damp;
APIDStrength = strength;
APIDTarget = rot;
RotLookAt(target,strength,damping);
}
public void stopLookAt()
public void StopLookAt()
{
APIDTarget = Quaternion.Identity;
}
@@ -3417,13 +3419,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public void StopLookAt()
{
ParentGroup.stopLookAt();
ParentGroup.ScheduleGroupForTerseUpdate();
}
/// <summary>
/// Set the text displayed for this part.
/// </summary>
@@ -4731,24 +4726,20 @@ namespace OpenSim.Region.Framework.Scenes
{
if (APIDTarget != Quaternion.Identity)
{
if (Single.IsNaN(APIDTarget.W) == true)
if (m_APIDIterations <= 1)
{
UpdateRotation(APIDTarget);
APIDTarget = Quaternion.Identity;
return;
}
Quaternion rot = RotationOffset;
Quaternion dir = (rot - APIDTarget);
float speed = ((APIDStrength / APIDDamp) * (float)(Math.PI / 180.0f));
if (dir.Z > speed)
{
rot.Z -= speed;
}
if (dir.Z < -speed)
{
rot.Z += speed;
}
rot.Normalize();
Quaternion rot = Quaternion.Slerp(RotationOffset,APIDTarget,1.0f/(float)m_APIDIterations);
UpdateRotation(rot);
m_APIDIterations--;
// This ensures that we'll check this object on the next iteration
ParentGroup.QueueForUpdateCheck();
}
}
catch (Exception ex)