本文整理汇总了C#中Box2D.Vec2.SetZero方法的典型用法代码示例。如果您正苦于以下问题:C# Vec2.SetZero方法的具体用法?C# Vec2.SetZero怎么用?C# Vec2.SetZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2D.Vec2
的用法示例。
在下文中一共展示了Vec2.SetZero方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RayCast
public bool RayCast(out RayCastOutput output, RayCastInput input) {
float tmin = -Single.MaxValue;
float tmax = Single.MaxValue;
Vec2 p = input.p1;
Vec2 d = input.p2 - input.p1;
Vec2 absD = Utilities.Abs(d);
output = new RayCastOutput();
Vec2 normal = new Vec2();
for (int i = 0; i < 2; ++i) {
if (Math.Abs(i) < Single.Epsilon) {
// Parallel.
if (p[i] < lowerBound[i] || upperBound[i] < p[i]) {
return false;
}
} else {
float inv_d = 1.0f / d[i];
float t1 = (lowerBound[i] - p[i]) * inv_d;
float t2 = (upperBound[i] - p[i]) * inv_d;
// Sign of the normal vector.
float s = -1.0f;
if (t1 > t2) {
float temp = t1;
t1 = t2;
t2 = temp;
s = 1.0f;
}
// Push the min up
if (t1 > tmin) {
normal.SetZero();
normal[i] = s;
tmin = t1;
}
// Pull the max down
tmax = Math.Min(tmax, t2);
if (tmin > tmax) {
return false;
}
}
}
// Does the ray start inside the box?
// Does the ray intersect beyond the max fraction?
if (tmin < 0.0f || input.maxFraction < tmin) {
return false;
}
// Intersection.
output.fraction = tmin;
output.normal = normal;
return true;
}
示例2: SolvePositionConstraints
internal override bool SolvePositionConstraints(SolverData data){
Vec2 cA = data.positions[m_indexA].c;
float aA = data.positions[m_indexA].a;
Vec2 cB = data.positions[m_indexB].c;
float aB = data.positions[m_indexB].a;
Vec2 cC = data.positions[m_indexC].c;
float aC = data.positions[m_indexC].a;
Vec2 cD = data.positions[m_indexD].c;
float aD = data.positions[m_indexD].a;
Rot qA = new Rot(aA);
Rot qB = new Rot(aB);
Rot qC= new Rot(aC);
Rot qD = new Rot(aD);
float linearError = 0.0f;
float coordinateA, coordinateB;
Vec2 JvAC = new Vec2();
Vec2 JvBD = new Vec2();
float JwA, JwB, JwC, JwD;
float mass = 0.0f;
if (m_typeA == JointType.e_revoluteJoint)
{
JvAC.SetZero();
JwA = 1.0f;
JwC = 1.0f;
mass += m_iA + m_iC;
coordinateA = aA - aC - m_referenceAngleA;
}
else
{
Vec2 u = Utilities.Mul(qC, m_localAxisC);
Vec2 rC = Utilities.Mul(qC, m_localAnchorC - m_lcC);
Vec2 rA = Utilities.Mul(qA, m_localAnchorA - m_lcA);
JvAC = u;
JwC = Utilities.Cross(rC, u);
JwA = Utilities.Cross(rA, u);
mass += m_mC + m_mA + m_iC * JwC * JwC + m_iA * JwA * JwA;
Vec2 pC = m_localAnchorC - m_lcC;
Vec2 pA = Utilities.MulT(qC, rA + (cA - cC));
coordinateA = Utilities.Dot(pA - pC, m_localAxisC);
}
if (m_typeB == JointType.e_revoluteJoint)
{
JvBD.SetZero();
JwB = m_ratio;
JwD = m_ratio;
mass += m_ratio * m_ratio * (m_iB + m_iD);
coordinateB = aB - aD - m_referenceAngleB;
}
else
{
Vec2 u = Utilities.Mul(qD, m_localAxisD);
Vec2 rD = Utilities.Mul(qD, m_localAnchorD - m_lcD);
Vec2 rB = Utilities.Mul(qB, m_localAnchorB - m_lcB);
JvBD = m_ratio * u;
JwD = m_ratio * Utilities.Cross(rD, u);
JwB = m_ratio * Utilities.Cross(rB, u);
mass += m_ratio * m_ratio * (m_mD + m_mB) + m_iD * JwD * JwD + m_iB * JwB * JwB;
Vec2 pD = m_localAnchorD - m_lcD;
Vec2 pB = Utilities.MulT(qD, rB + (cB - cD));
coordinateB = Utilities.Dot(pB - pD, m_localAxisD);
}
float C = (coordinateA + m_ratio * coordinateB) - m_constant;
float impulse = 0.0f;
if (mass > 0.0f)
{
impulse = -C / mass;
}
cA += m_mA * impulse * JvAC;
aA += m_iA * impulse * JwA;
cB += m_mB * impulse * JvBD;
aB += m_iB * impulse * JwB;
cC -= m_mC * impulse * JvAC;
aC -= m_iC * impulse * JwC;
cD -= m_mD * impulse * JvBD;
aD -= m_iD * impulse * JwD;
data.positions[m_indexA].c = cA;
data.positions[m_indexA].a = aA;
data.positions[m_indexB].c = cB;
data.positions[m_indexB].a = aB;
data.positions[m_indexC].c = cC;
data.positions[m_indexC].a = aC;
data.positions[m_indexD].c = cD;
data.positions[m_indexD].a = aD;
// TODO_ERIN not implemented
return linearError <Settings._linearSlop;
//.........这里部分代码省略.........