本文整理汇总了C#中BEPUutilities.Matrix3x3类的典型用法代码示例。如果您正苦于以下问题:C# Matrix3x3类的具体用法?C# Matrix3x3怎么用?C# Matrix3x3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matrix3x3类属于BEPUutilities命名空间,在下文中一共展示了Matrix3x3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobianA = Matrix3x3.Identity;
//The jacobian entries are is [ La, Aa, -Lb, -Ab ] because the relative velocity is computed using A-B. So, negate B's jacobians!
linearJacobianB = new Matrix3x3 { M11 = -1, M22 = -1, M33 = -1 };
System.Numerics.Vector3 rA;
QuaternionEx.Transform(ref LocalOffsetA, ref ConnectionA.Orientation, out rA);
Matrix3x3.CreateCrossProduct(ref rA, out angularJacobianA);
//Transposing a skew-symmetric matrix is equivalent to negating it.
Matrix3x3.Transpose(ref angularJacobianA, out angularJacobianA);
System.Numerics.Vector3 worldPositionA;
Vector3Ex.Add(ref ConnectionA.Position, ref rA, out worldPositionA);
System.Numerics.Vector3 rB;
QuaternionEx.Transform(ref LocalOffsetB, ref ConnectionB.Orientation, out rB);
Matrix3x3.CreateCrossProduct(ref rB, out angularJacobianB);
System.Numerics.Vector3 worldPositionB;
Vector3Ex.Add(ref ConnectionB.Position, ref rB, out worldPositionB);
System.Numerics.Vector3 linearError;
Vector3Ex.Subtract(ref worldPositionB, ref worldPositionA, out linearError);
Vector3Ex.Multiply(ref linearError, errorCorrectionFactor, out velocityBias);
}
示例2: TransformableShape
///<summary>
/// Constructs a new transformable shape.
///</summary>
/// <param name="shape">Base shape to transform.</param>
/// <param name="transform">Transform to use.</param>
/// <param name="description">Cached information about the shape. Assumed to be correct; no extra processing or validation is performed.</param>
public TransformableShape(ConvexShape shape, Matrix3x3 transform, ConvexShapeDescription description)
{
this.shape = shape;
this.transform = transform;
UpdateConvexShapeInfo(description);
}
示例3: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobian = new Matrix3x3();
Vector3 boneAxis;
Quaternion.Transform(ref BoneLocalAxis, ref TargetBone.Orientation, out boneAxis);
Vector3 jacobian;
Vector3.Cross(ref boneAxis, ref PlaneNormal, out jacobian);
angularJacobian = new Matrix3x3
{
M11 = jacobian.X,
M12 = jacobian.Y,
M13 = jacobian.Z,
};
Vector3.Dot(ref boneAxis, ref PlaneNormal, out velocityBias.X);
velocityBias.X = -errorCorrectionFactor * velocityBias.X;
}
示例4: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobianA = linearJacobianB = new Matrix3x3();
angularJacobianA = new Matrix3x3 { M11 = 1, M22 = 1, M33 = 1 };
angularJacobianB = new Matrix3x3 { M11 = -1, M22 = -1, M33 = -1 };
//The error is computed using this equation:
//GoalRelativeOrientation * ConnectionA.Orientation * Error = ConnectionB.Orientation
//GoalRelativeOrientation is the original rotation from A to B in A's local space.
//Multiplying by A's orientation gives us where B *should* be.
//Of course, B won't be exactly where it should be after initialization.
//The Error component holds the difference between what is and what should be.
//Error = (GoalRelativeOrientation * ConnectionA.Orientation)^-1 * ConnectionB.Orientation
Quaternion bTarget;
Quaternion.Concatenate(ref GoalRelativeOrientation, ref ConnectionA.Orientation, out bTarget);
Quaternion bTargetConjugate;
Quaternion.Conjugate(ref bTarget, out bTargetConjugate);
Quaternion error;
Quaternion.Concatenate(ref bTargetConjugate, ref ConnectionB.Orientation, out error);
//Convert the error into an axis-angle vector usable for bias velocity.
float angle;
Vector3 axis;
Quaternion.GetAxisAngleFromQuaternion(ref error, out axis, out angle);
velocityBias.X = errorCorrectionFactor * axis.X * angle;
velocityBias.Y = errorCorrectionFactor * axis.Y * angle;
velocityBias.Z = errorCorrectionFactor * axis.Z * angle;
}
示例5: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobian = new Matrix3x3();
Vector3 boneAxis;
Quaternion.Transform(ref BoneLocalFreeAxis, ref TargetBone.Orientation, out boneAxis);
angularJacobian = new Matrix3x3
{
M11 = constrainedAxis1.X,
M12 = constrainedAxis1.Y,
M13 = constrainedAxis1.Z,
M21 = constrainedAxis2.X,
M22 = constrainedAxis2.Y,
M23 = constrainedAxis2.Z
};
Vector3 error;
Vector3.Cross(ref boneAxis, ref freeAxis, out error);
Vector2 constraintSpaceError;
Vector3.Dot(ref error, ref constrainedAxis1, out constraintSpaceError.X);
Vector3.Dot(ref error, ref constrainedAxis2, out constraintSpaceError.Y);
velocityBias.X = errorCorrectionFactor * constraintSpaceError.X;
velocityBias.Y = errorCorrectionFactor * constraintSpaceError.Y;
}
示例6: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobian = new Matrix3x3();
angularJacobian = Matrix3x3.Identity;
//Error is in world space. It gets projected onto the jacobians later.
System.Numerics.Quaternion errorQuaternion;
QuaternionEx.Conjugate(ref TargetBone.Orientation, out errorQuaternion);
QuaternionEx.Multiply(ref TargetOrientation, ref errorQuaternion, out errorQuaternion);
float angle;
System.Numerics.Vector3 angularError;
QuaternionEx.GetAxisAngleFromQuaternion(ref errorQuaternion, out angularError, out angle);
Vector3Ex.Multiply(ref angularError, angle, out angularError);
//This is equivalent to projecting the error onto the angular jacobian. The angular jacobian just happens to be the identity matrix!
Vector3Ex.Multiply(ref angularError, errorCorrectionFactor, out velocityBias);
}
示例7: MobileChunkShape
public MobileChunkShape(Vector3i csize, BlockInternal[] blocks, out Vector3 center)
{
Matrix3x3 boxMat = new BoxShape(csize.X, csize.Y, csize.Z).VolumeDistribution;
ChunkSize = csize;
Blocks = blocks;
double weightInv = 1f / blocks.Length;
center = new Vector3(csize.X / 2f, csize.Y / 2f, csize.Z / 2f);
// TODO: More accurately get center of weight based on which blocks are solid or not!?
Matrix3x3 volumeDistribution = new Matrix3x3();
RigidTransform transform = new RigidTransform(center);
Matrix3x3 contribution;
CompoundShape.TransformContribution(ref transform, ref center, ref boxMat, blocks.Length, out contribution);
Matrix3x3.Add(ref volumeDistribution, ref contribution, out volumeDistribution);
Matrix3x3.Multiply(ref volumeDistribution, weightInv, out volumeDistribution);
UpdateEntityShapeVolume(new EntityShapeVolumeDescription() { Volume = csize.X * csize.Y * csize.Z, VolumeDistribution = volumeDistribution });
Center = center;
}
示例8: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
linearJacobianA = linearJacobianB = new Matrix3x3();
//There are two free axes and one restricted axis.
//The constraint attempts to keep the hinge axis attached to connection A and the twist axis attached to connection B perpendicular to each other.
//The restricted axis is the cross product between the twist and hinge axes.
Vector3 worldTwistAxis, worldHingeAxis;
Quaternion.Transform(ref LocalHingeAxis, ref ConnectionA.Orientation, out worldHingeAxis);
Quaternion.Transform(ref LocalTwistAxis, ref ConnectionB.Orientation, out worldTwistAxis);
Vector3 restrictedAxis;
Vector3.Cross(ref worldHingeAxis, ref worldTwistAxis, out restrictedAxis);
//Attempt to normalize the restricted axis.
float lengthSquared = restrictedAxis.LengthSquared();
if (lengthSquared > Toolbox.Epsilon)
{
Vector3.Divide(ref restrictedAxis, (float)Math.Sqrt(lengthSquared), out restrictedAxis);
}
else
{
restrictedAxis = new Vector3();
}
angularJacobianA = new Matrix3x3
{
M11 = restrictedAxis.X,
M12 = restrictedAxis.Y,
M13 = restrictedAxis.Z,
};
Matrix3x3.Negate(ref angularJacobianA, out angularJacobianB);
float error;
Vector3.Dot(ref worldHingeAxis, ref worldTwistAxis, out error);
error = (float)Math.Acos(MathHelper.Clamp(error, -1, 1)) - MathHelper.PiOver2;
velocityBias = new Vector3(errorCorrectionFactor * error, 0, 0);
}
示例9: UpdateJacobiansAndVelocityBias
protected internal override void UpdateJacobiansAndVelocityBias()
{
//This constraint doesn't consider linear motion.
linearJacobianA = linearJacobianB = new Matrix3x3();
//Compute the world axes.
Vector3 axisA, axisB;
Quaternion.Transform(ref LocalAxisA, ref ConnectionA.Orientation, out axisA);
Quaternion.Transform(ref LocalAxisB, ref ConnectionB.Orientation, out axisB);
float dot;
Vector3.Dot(ref axisA, ref axisB, out dot);
//Yes, we could avoid this acos here. Performance is not the highest goal of this system; the less tricks used, the easier it is to understand.
float angle = (float)Math.Acos(MathHelper.Clamp(dot, -1, 1));
//One angular DOF is constrained by this limit.
Vector3 hingeAxis;
Vector3.Cross(ref axisA, ref axisB, out hingeAxis);
angularJacobianA.M1 = hingeAxis;
hingeAxis.Invert( out angularJacobianB.M1 );
//Note how we've computed the jacobians despite the limit being potentially inactive.
//This is to enable 'speculative' limits.
if (angle >= maximumAngle)
{
velocityBias = new Vector3(errorCorrectionFactor * (angle - maximumAngle), 0, 0);
}
else
{
//The constraint is not yet violated. But, it may be- allow only as much motion as could occur without violating the constraint.
//Limits can't 'pull,' so this will not result in erroneous sticking.
velocityBias = new Vector3(angle - maximumAngle, 0, 0);
}
}
示例10: Update
/// <summary>
/// Calculates necessary information for velocity solving.
/// Called automatically by space.
/// </summary>
/// <param name="dt">Time in seconds since the last update.</param>
public override void Update(float dt)
{
usedSoftness = softness / dt;
effectiveMassMatrix = entity.inertiaTensorInverse;
effectiveMassMatrix.M11 += usedSoftness;
effectiveMassMatrix.M22 += usedSoftness;
effectiveMassMatrix.M33 += usedSoftness;
Matrix3x3.Invert(ref effectiveMassMatrix, out effectiveMassMatrix);
//Determine maximum force
if (maximumForce < float.MaxValue)
{
maxForceDt = maximumForce * dt;
maxForceDtSquared = maxForceDt * maxForceDt;
}
else
{
maxForceDt = float.MaxValue;
maxForceDtSquared = float.MaxValue;
}
}
示例11: ComputeEffectiveMass
protected internal override void ComputeEffectiveMass()
{
//For all constraints, the effective mass matrix is 1 / (J * M^-1 * JT).
//For two bone constraints, J has 4 3x3 matrices. M^-1 (W below) is a 12x12 matrix with 4 3x3 block diagonal matrices.
//To compute the whole denominator,
Matrix3x3 linearW;
Matrix3x3 linearA, angularA, linearB, angularB;
if (!ConnectionA.Pinned)
{
Matrix3x3.CreateScale(ConnectionA.inverseMass, out linearW);
Matrix3x3.Multiply(ref linearJacobianA, ref linearW, out linearA); //Compute J * M^-1 for linear component
Matrix3x3.MultiplyByTransposed(ref linearA, ref linearJacobianA, out linearA); //Compute (J * M^-1) * JT for linear component
Matrix3x3.Multiply(ref angularJacobianA, ref ConnectionA.inertiaTensorInverse, out angularA); //Compute J * M^-1 for angular component
Matrix3x3.MultiplyByTransposed(ref angularA, ref angularJacobianA, out angularA); //Compute (J * M^-1) * JT for angular component
}
else
{
//Treat pinned bones as if they have infinite inertia.
linearA = new Matrix3x3();
angularA = new Matrix3x3();
}
if (!ConnectionB.Pinned)
{
Matrix3x3.CreateScale(ConnectionB.inverseMass, out linearW);
Matrix3x3.Multiply(ref linearJacobianB, ref linearW, out linearB); //Compute J * M^-1 for linear component
Matrix3x3.MultiplyByTransposed(ref linearB, ref linearJacobianB, out linearB); //Compute (J * M^-1) * JT for linear component
Matrix3x3.Multiply(ref angularJacobianB, ref ConnectionB.inertiaTensorInverse, out angularB); //Compute J * M^-1 for angular component
Matrix3x3.MultiplyByTransposed(ref angularB, ref angularJacobianB, out angularB); //Compute (J * M^-1) * JT for angular component
}
else
{
//Treat pinned bones as if they have infinite inertia.
linearB = new Matrix3x3();
angularB = new Matrix3x3();
}
//A nice side effect of the block diagonal nature of M^-1 is that the above separated components are now combined into the complete denominator matrix by addition!
Matrix3x3.Add(ref linearA, ref angularA, out effectiveMass);
Matrix3x3.Add(ref effectiveMass, ref linearB, out effectiveMass);
Matrix3x3.Add(ref effectiveMass, ref angularB, out effectiveMass);
//Incorporate the constraint softness into the effective mass denominator. This pushes the matrix away from singularity.
//Softness will also be incorporated into the velocity solve iterations to complete the implementation.
if (effectiveMass.M1.X != 0)
effectiveMass.M1.X += softness;
if (effectiveMass.M2.Y != 0)
effectiveMass.M2.Y += softness;
if (effectiveMass.M3.Z != 0)
effectiveMass.M3.Z += softness;
//Invert! Takes us from J * M^-1 * JT to 1 / (J * M^-1 * JT).
Matrix3x3.AdaptiveInvert(ref effectiveMass, out effectiveMass);
}
示例12: MultiplyTransposed
/// <summary>
/// Multiplies a transposed matrix with another matrix.
/// </summary>
/// <param name="matrix">Matrix to be multiplied.</param>
/// <param name="transpose">Matrix to be transposed and multiplied.</param>
/// <param name="result">Product of the multiplication.</param>
public static void MultiplyTransposed(ref Matrix3x3 transpose, ref Matrix3x3 matrix, out Matrix3x3 result)
{
float resultM11 = transpose.M11 * matrix.M11 + transpose.M21 * matrix.M21 + transpose.M31 * matrix.M31;
float resultM12 = transpose.M11 * matrix.M12 + transpose.M21 * matrix.M22 + transpose.M31 * matrix.M32;
float resultM13 = transpose.M11 * matrix.M13 + transpose.M21 * matrix.M23 + transpose.M31 * matrix.M33;
float resultM21 = transpose.M12 * matrix.M11 + transpose.M22 * matrix.M21 + transpose.M32 * matrix.M31;
float resultM22 = transpose.M12 * matrix.M12 + transpose.M22 * matrix.M22 + transpose.M32 * matrix.M32;
float resultM23 = transpose.M12 * matrix.M13 + transpose.M22 * matrix.M23 + transpose.M32 * matrix.M33;
float resultM31 = transpose.M13 * matrix.M11 + transpose.M23 * matrix.M21 + transpose.M33 * matrix.M31;
float resultM32 = transpose.M13 * matrix.M12 + transpose.M23 * matrix.M22 + transpose.M33 * matrix.M32;
float resultM33 = transpose.M13 * matrix.M13 + transpose.M23 * matrix.M23 + transpose.M33 * matrix.M33;
result.M11 = resultM11;
result.M12 = resultM12;
result.M13 = resultM13;
result.M21 = resultM21;
result.M22 = resultM22;
result.M23 = resultM23;
result.M31 = resultM31;
result.M32 = resultM32;
result.M33 = resultM33;
}
示例13: Multiply
/// <summary>
/// Multiplies the two matrices.
/// </summary>
/// <param name="a">First matrix to multiply.</param>
/// <param name="b">Second matrix to multiply.</param>
/// <param name="result">Product of the multiplication.</param>
public static void Multiply(ref Matrix3x3 a, ref Matrix3x2 b, out Matrix3x2 result)
{
float resultM11 = a.M11 * b.M11 + a.M12 * b.M21 + a.M13 * b.M31;
float resultM12 = a.M11 * b.M12 + a.M12 * b.M22 + a.M13 * b.M32;
float resultM21 = a.M21 * b.M11 + a.M22 * b.M21 + a.M23 * b.M31;
float resultM22 = a.M21 * b.M12 + a.M22 * b.M22 + a.M23 * b.M32;
float resultM31 = a.M31 * b.M11 + a.M32 * b.M21 + a.M33 * b.M31;
float resultM32 = a.M31 * b.M12 + a.M32 * b.M22 + a.M33 * b.M32;
result.M11 = resultM11;
result.M12 = resultM12;
result.M21 = resultM21;
result.M22 = resultM22;
result.M31 = resultM31;
result.M32 = resultM32;
}
示例14: ToMatrix4X4
/// <summary>
/// Creates a 4x4 matrix from a 3x3 matrix.
/// </summary>
/// <param name="a">3x3 matrix.</param>
/// <returns>Created 4x4 matrix.</returns>
public static Matrix ToMatrix4X4(Matrix3x3 a)
{
#if !WINDOWS
Matrix b = new Matrix();
#else
Matrix b;
#endif
b.M11 = a.M11;
b.M12 = a.M12;
b.M13 = a.M13;
b.M21 = a.M21;
b.M22 = a.M22;
b.M23 = a.M23;
b.M31 = a.M31;
b.M32 = a.M32;
b.M33 = a.M33;
b.M44 = 1;
b.M14 = 0;
b.M24 = 0;
b.M34 = 0;
b.M41 = 0;
b.M42 = 0;
b.M43 = 0;
return b;
}
示例15: Subtract
/// <summary>
/// Subtracts the two matrices from each other on a per-element basis.
/// </summary>
/// <param name="a">First matrix to subtract.</param>
/// <param name="b">Second matrix to subtract.</param>
/// <param name="result">Difference of the two matrices.</param>
public static void Subtract(ref Matrix3x3 a, ref Matrix3x3 b, out Matrix3x3 result)
{
float m11 = a.M11 - b.M11;
float m12 = a.M12 - b.M12;
float m13 = a.M13 - b.M13;
float m21 = a.M21 - b.M21;
float m22 = a.M22 - b.M22;
float m23 = a.M23 - b.M23;
float m31 = a.M31 - b.M31;
float m32 = a.M32 - b.M32;
float m33 = a.M33 - b.M33;
result.M11 = m11;
result.M12 = m12;
result.M13 = m13;
result.M21 = m21;
result.M22 = m22;
result.M23 = m23;
result.M31 = m31;
result.M32 = m32;
result.M33 = m33;
}