本文整理汇总了C#中Box2D.Vec2.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vec2.Normalize方法的具体用法?C# Vec2.Normalize怎么用?C# Vec2.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2D.Vec2
的用法示例。
在下文中一共展示了Vec2.Normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Prismatic
public Prismatic() {
Body ground = null;
{
BodyDef bd = new BodyDef();
ground = m_world.CreateBody(bd);
EdgeShape shape = new EdgeShape();
shape.Set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
shape.Density = 0;
ground.CreateFixture(shape);
}
{
PolygonShape shape = new PolygonShape();
shape.SetAsBox(2.0f, 0.5f);
shape.Density = 5;
BodyDef bd = new BodyDef();
bd.type = BodyType._dynamicBody;
bd.Position.Set(-10.0f, 10.0f);
bd.angle = 0.5f * (float)Math.PI;
bd.allowSleep = false;
Body body = m_world.CreateBody(bd);
body.CreateFixture(shape);
PrismaticJointDef pjd = new PrismaticJointDef();
// Bouncy limit
Vec2 axis = new Vec2(2.0f, 1.0f);
axis.Normalize();
pjd.Initialize(ground, body, new Vec2(0.0f, 0.0f), axis);
// Non-bouncy limit
//pjd.Initialize(ground, body, new Vec2(-10.0f, 10.0f), new Vec2(1.0f, 0.0f));
pjd.motorSpeed = 10.0f;
pjd.maxMotorForce = 10000.0f;
pjd.enableMotor = true;
pjd.lowerTranslation = 0.0f;
pjd.upperTranslation = 20.0f;
pjd.enableLimit = true;
m_joint = (PrismaticJoint)m_world.CreateJoint(pjd);
}
}
示例2: CollideEdgeAndCircle
//.........这里部分代码省略.........
{
return;
}
// Is there an edge connected to A?
if (edgeA.m_hasVertex0)
{
Vec2 A1 = edgeA.m_vertex0;
Vec2 B1 = A;
Vec2 e1 = B1 - A1;
float u1 = Utilities.Dot(e1, B1 - Q);
// Is the circle in Region AB of the previous edge?
if (u1 > 0.0f)
{
return;
}
}
cf.indexA = 0;
cf.typeA = ContactFeature.FeatureType.e_vertex;
manifold.points.Clear();
manifold.points.Add(new ManifoldPoint());
manifold.type = Manifold.ManifoldType.e_circles;
manifold.localNormal.SetZero();
manifold.localPoint = P;
manifold.points[0].id.key = 0;
manifold.points[0].id.cf = cf;
manifold.points[0].localPoint = circleB.m_p;
return;
}
// Region B
if (u <= 0.0f)
{
Vec2 P = B;
Vec2 d = Q - P;
float dd = Utilities.Dot(d, d);
if (dd > radius * radius)
{
return;
}
// Is there an edge connected to B?
if (edgeA.m_hasVertex3)
{
Vec2 B2 = edgeA.m_vertex3;
Vec2 A2 = B;
Vec2 e2 = B2 - A2;
float v2 = Utilities.Dot(e2, Q - A2);
// Is the circle in Region AB of the next edge?
if (v2 > 0.0f)
{
return;
}
}
cf.indexA = 1;
cf.typeA = ContactFeature.FeatureType.e_vertex;
manifold.points.Clear();
manifold.points.Add(new ManifoldPoint());
manifold.type = Manifold.ManifoldType.e_circles;
manifold.localNormal.SetZero();
manifold.localPoint = P;
manifold.points[0].id.key = 0;
manifold.points[0].id.cf = cf;
manifold.points[0].localPoint = circleB.m_p;
return;
}
// Region AB
float den = Utilities.Dot(e, e);
Utilities.Assert(den > 0.0f);
Vec2 Pb = (1.0f / den) * (u * A + v * B);
Vec2 db = Q - Pb;
float ddb = Utilities.Dot(db, db);
if (ddb > radius * radius)
{
return;
}
Vec2 n = new Vec2(-e.Y, e.X);
if (Utilities.Dot(n, Q - A) < 0.0f)
{
n.Set(-n.X, -n.Y);
}
n.Normalize();
cf.indexA = 0;
cf.typeA = ContactFeature.FeatureType.e_face;
manifold.points.Clear();
manifold.points.Add(new ManifoldPoint());
manifold.type = Manifold.ManifoldType.e_faceA;
manifold.localNormal = n;
manifold.localPoint = A;
manifold.points[0].id.key = 0;
manifold.points[0].id.cf = cf;
manifold.points[0].localPoint = circleB.m_p;
}