本文整理汇总了C#中System.Windows.Vector.IsValid方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.IsValid方法的具体用法?C# Vector.IsValid怎么用?C# Vector.IsValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Vector
的用法示例。
在下文中一共展示了Vector.IsValid方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AngleRad
public static double AngleRad(Vector v1, Vector v2)
{
Debug.Assert(v1.IsValid());
Debug.Assert(v2.IsValid());
double dot = Dot(v1, v2);
double dotNormalize = dot / (v1.Length * v2.Length);
double acos = Math.Acos(dotNormalize);
return acos;
}
示例2: Dot
public static double Dot(Vector v1, Vector v2)
{
Debug.Assert(v1.IsValid());
Debug.Assert(v2.IsValid());
return v1.X * v2.X + v1.Y * v2.Y;
}
示例3: Animate
public static bool Animate(
Point currentValue, Vector currentVelocity, Point targetValue,
double attractionFator, double dampening,
double terminalVelocity, double minValueDelta, double minVelocityDelta,
out Point newValue, out Vector newVelocity)
{
Debug.Assert(currentValue.IsValid());
Debug.Assert(currentVelocity.IsValid());
Debug.Assert(targetValue.IsValid());
Debug.Assert(dampening.IsValid());
Debug.Assert(dampening > 0 && dampening < 1);
Debug.Assert(attractionFator.IsValid());
Debug.Assert(attractionFator > 0);
Debug.Assert(terminalVelocity > 0);
Debug.Assert(minValueDelta > 0);
Debug.Assert(minVelocityDelta > 0);
Vector diff = targetValue.Subtract(currentValue);
if (diff.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
{
newVelocity = currentVelocity * (1 - dampening);
newVelocity += diff * attractionFator;
if (currentVelocity.Length > terminalVelocity)
{
newVelocity *= terminalVelocity / currentVelocity.Length;
}
newValue = currentValue + newVelocity;
return true;
}
else
{
newValue = targetValue;
newVelocity = new Vector();
return false;
}
}
示例4: TickData
public bool TickData(Vector lastMouse, bool isFlipped)
{
bool somethingChanged = false;
//active means nothing in the "flipped" mode
bool isActiveItem = IsMouseOver && !isFlipped;
bool goodMouse = lastMouse.IsValid();
#region rotation
Quaternion rotationTarget = new Quaternion(new Vector3D(1, 0, 0), 0);
//apply forces
rotationTarget.Normalize();
m_rotationCurrent.Normalize();
double angle = 0;
Vector3D axis = new Vector3D(0, 0, 1);
if (lastMouse.IsValid() && !isFlipped)
{
Point3D mouse = new Point3D(lastMouse.X, lastMouse.Y, 1);
Vector3D line = mouse - m_locationCurrent;
Vector3D straight = new Vector3D(0, 0, 1);
angle = Vector3D.AngleBetween(line, straight);
axis = Vector3D.CrossProduct(line, straight);
}
Quaternion rotationForceTowardsMouse = new Quaternion(axis, -angle);
Quaternion rotationForceToDesired = rotationTarget - m_rotationCurrent;
Quaternion rotationForce = rotationForceToDesired + rotationForceTowardsMouse;
m_rotationVelocity *= new Quaternion(rotationForce.Axis, rotationForce.Angle * .2);
//dampenning
m_rotationVelocity = new Quaternion(m_rotationVelocity.Axis, m_rotationVelocity.Angle * (m_weird - .3));
//apply terminal velocity
m_rotationVelocity = new Quaternion(m_rotationVelocity.Axis, m_rotationVelocity.Angle);
m_rotationVelocity.Normalize();
//apply to position
m_rotationCurrent *= m_rotationVelocity;
m_rotationCurrent.Normalize();
//see if there is any real difference between what we calculated and what actually exists
if (AnyDiff(m_quaternionRotation3D.Quaternion.Axis, m_rotationCurrent.Axis, c_diff) ||
AnyDiff(m_quaternionRotation3D.Quaternion.Angle, m_rotationCurrent.Angle, c_diff))
{
//if the angles are both ~0, the axis may be way off but the result is basically the same
//check for this and forget animating in this case
if (AnyDiff(m_quaternionRotation3D.Quaternion.Angle, 0, c_diff) || AnyDiff(m_rotationCurrent.Angle, 0, c_diff))
{
m_quaternionRotation3D.Quaternion = m_rotationCurrent;
somethingChanged = true;
}
}
#endregion
#region flip
double verticalFlipTarget = isFlipped ? 180 : 0;
double verticalFlipCurrent = m_verticalFlipRotation.Angle;
//force
double verticalFlipForce = verticalFlipTarget - verticalFlipCurrent;
//velocity
m_flipVerticalVelocity += .3 * verticalFlipForce;
//dampening
m_flipVerticalVelocity *= (m_weird - .3);
//terminal velocity
m_flipVerticalVelocity = limitDouble(m_flipVerticalVelocity, 10);
//apply
verticalFlipCurrent += m_flipVerticalVelocity;
if (AnyDiff(verticalFlipCurrent, m_verticalFlipRotation.Angle, c_diff) && AnyDiff(m_flipVerticalVelocity, 0, c_diff))
{
m_verticalFlipRotation.Angle = verticalFlipCurrent;
}
#endregion
#region scale
if (isActiveItem && !isFlipped)
{
this.m_scaleDesired = 2;
}
else
{
this.m_scaleDesired = 1;
}
double scaleForce = this.m_scaleDesired - this.m_scaleCurrent;
this.m_scaleVelocity += .1 * scaleForce;
//.........这里部分代码省略.........
示例5: Normalize
private static Vector Normalize(Vector v)
{
v.Normalize();
Debug.Assert(v.IsValid());
return v;
}
示例6: GetSpringForce
private static Vector GetSpringForce(Vector x)
{
Vector force = new Vector();
//negative is attraction
force += GetAttractionForce(x);
//positive is repulsion
force += GetRepulsiveForce(x);
Debug.Assert(force.IsValid());
return force;
}
示例7: GetCurrentValueCore
/// <summary/>
protected override Vector GetCurrentValueCore(Vector baseFromValue, Vector baseToValue, AnimationClock animationClock) {
var progress = animationClock.CurrentProgress;
if (!progress.HasValue || Interpolator == null) {
return base.GetCurrentValueCore(baseFromValue, baseToValue, animationClock);
}
var fromValue = new Vector();
var toValue = new Vector();
var offset = new Vector();
var isValid = true;
if (From.HasValue) {
fromValue = From.Value;
if (To.HasValue) {
// from ... to
toValue = To.Value;
if (IsAdditive) {
offset = baseFromValue;
isValid = offset.IsValid();
}
} else if (By.HasValue) {
// from ... from+by
toValue = fromValue + By.Value;
if (IsAdditive) {
offset = baseFromValue;
isValid = offset.IsValid();
}
} else {
// from ... base
toValue = baseToValue;
isValid = toValue.IsValid();
}
} else if (To.HasValue) {
// base ... to
fromValue = baseFromValue;
toValue = To.Value;
isValid = fromValue.IsValid();
} else if (By.HasValue) {
// base ... base+by
toValue = By.Value;
offset = baseFromValue;
isValid = offset.IsValid();
} else {
// base ... base
fromValue = baseFromValue;
toValue = baseToValue;
isValid = fromValue.IsValid() && toValue.IsValid();
}
if (!isValid) {
throw new InvalidOperationException("GetCurrentValueCore");
}
if (IsCumulative) {
var iteration = animationClock.CurrentIteration;
if (iteration.HasValue && iteration.Value > 1) {
offset += (toValue - fromValue) * (iteration.Value - 1);
}
}
var interpolator = Interpolator ?? Interpolators.Linear;
return fromValue + (toValue - fromValue) * interpolator(progress.Value, 0.0, 1.0) + offset;
}