本文整理汇总了C#中FarseerPhysics.Collision.Shapes.EdgeShape类的典型用法代码示例。如果您正苦于以下问题:C# EdgeShape类的具体用法?C# EdgeShape怎么用?C# EdgeShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdgeShape类属于FarseerPhysics.Collision.Shapes命名空间,在下文中一共展示了EdgeShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SensorTest
private SensorTest()
{
{
Body ground = BodyFactory.CreateBody(World);
{
EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape);
}
{
CircleShape shape = new CircleShape(5.0f, 1);
shape.Position = new Vector2(0.0f, 10.0f);
_sensor = ground.CreateFixture(shape);
_sensor.IsSensor = true;
}
}
{
CircleShape shape = new CircleShape(1.0f, 1);
for (int i = 0; i < Count; ++i)
{
_touching[i] = false;
_bodies[i] = BodyFactory.CreateBody(World);
_bodies[i].BodyType = BodyType.Dynamic;
_bodies[i].Position = new Vector2(-10.0f + 3.0f * i, 20.0f);
_bodies[i].UserData = i;
_bodies[i].CreateFixture(shape);
}
}
}
示例2: RopeTest
private RopeTest()
{
Body ground;
{
ground = new Body(World);
EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape);
}
{
Body prevBody = ground;
PolygonShape largeShape = new PolygonShape(PolygonTools.CreateRectangle(1.5f, 1.5f), 100);
PolygonShape smallShape = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.125f), 20);
const int N = 10;
const float y = 15;
for (int i = 0; i < N; ++i)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.5f + 1.0f * i, y);
if (i == N - 1)
{
Fixture fixture = body.CreateFixture(largeShape);
fixture.Friction = 0.2f;
fixture.CollisionCategories = Category.Cat2;
fixture.CollidesWith = Category.All & ~Category.Cat2;
body.Position = new Vector2(1.0f * i, y);
body.AngularDamping = 0.4f;
}
else
{
Fixture fixture = body.CreateFixture(smallShape);
fixture.Friction = 0.2f;
fixture.CollisionCategories = Category.Cat1;
fixture.CollidesWith = Category.All & ~Category.Cat2;
}
Vector2 anchor = new Vector2(i, y);
RevoluteJoint jd = new RevoluteJoint(prevBody, body, prevBody.GetLocalPoint(ref anchor),
body.GetLocalPoint(ref anchor));
jd.CollideConnected = false;
World.AddJoint(jd);
prevBody = body;
}
_rj = new RopeJoint(ground, prevBody, new Vector2(0, y), Vector2.Zero);
//FPE: The two following lines are actually not needed as FPE sets the MaxLength to a default value
const float extraLength = 0.01f;
_rj.MaxLength = N - 1.0f + extraLength;
World.AddJoint(_rj);
}
}
示例3: CircleBenchmarkTest
private CircleBenchmarkTest()
{
Body ground = BodyFactory.CreateBody(World);
// Floor
EdgeShape ashape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(ashape);
// Left wall
ashape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(-40.0f, 45.0f));
ground.CreateFixture(ashape);
// Right wall
ashape = new EdgeShape(new Vector2(40.0f, 0.0f), new Vector2(40.0f, 45.0f));
ground.CreateFixture(ashape);
// Roof
ashape = new EdgeShape(new Vector2(-40.0f, 45.0f), new Vector2(40.0f, 45.0f));
ground.CreateFixture(ashape);
CircleShape shape = new CircleShape(1.0f, 1);
for (int i = 0; i < XCount; i++)
{
for (int j = 0; j < YCount; ++j)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(-38f + 2.1f * i, 2.0f + 2.0f * j);
body.CreateFixture(shape);
}
}
}
示例4: PrismaticTest
private PrismaticTest()
{
Body ground;
{
ground = BodyFactory.CreateBody(World);
EdgeShape shape3 = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
ground.CreateFixture(shape3);
}
PolygonShape shape = new PolygonShape(5);
shape.SetAsBox(2.0f, 0.5f);
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 10.0f);
body.CreateFixture(shape);
_fixedJoint = new FixedPrismaticJoint(body, body.Position, new Vector2(0.5f, 1.0f));
_fixedJoint.MotorSpeed = 5.0f;
_fixedJoint.MaxMotorForce = 1000.0f;
_fixedJoint.MotorEnabled = true;
_fixedJoint.LowerLimit = -10.0f;
_fixedJoint.UpperLimit = 20.0f;
_fixedJoint.LimitEnabled = true;
World.AddJoint(_fixedJoint);
PolygonShape shape2 = new PolygonShape(5);
shape2.SetAsBox(2.0f, 0.5f);
Body body2 = BodyFactory.CreateBody(World);
body2.BodyType = BodyType.Dynamic;
body2.Position = new Vector2(10.0f, 10.0f);
body2.CreateFixture(shape2);
_joint = new PrismaticJoint(ground, body2, ground.GetLocalPoint(body2.Position), Vector2.Zero,
new Vector2(0.5f, 1.0f));
_joint.MotorSpeed = 5.0f;
_joint.MaxMotorForce = 1000.0f;
_joint.MotorEnabled = true;
_joint.LowerLimit = -10.0f;
_joint.UpperLimit = 20.0f;
_joint.LimitEnabled = true;
World.AddJoint(_joint);
}
示例5: Initialize
public void Initialize(Map.Map map)
{
var collision = new CollisionMap(map);
if (_world == null)
_world = new World(new Vector2(0, 0));
else
_world.Clear();
var obstacles = collision.GetObstacles();
var layer2Obstacles = obstacles.GetObstacles(2);
foreach (var obstacle in layer2Obstacles)
{
var body = new Body(_world) { BodyType = BodyType.Static };
_json.SetName(body, "Building" + obstacle.Z);
Shape shape;
Fixture fixture;
switch (obstacle.Type)
{
case ObstacleType.Line:
var lineObstacle = (LineObstacle)obstacle;
shape = new EdgeShape(lineObstacle.Start.ToMeters(), lineObstacle.End.ToMeters());
fixture = body.CreateFixture(shape);
_json.SetName(fixture, "Building" + obstacle.Z);
break;
case ObstacleType.Polygon:
var polygonObstacle = (PolygonObstacle)obstacle;
var convexPolygons = BayazitDecomposer.ConvexPartition(polygonObstacle.Vertices);
foreach (var convexPolygon in convexPolygons)
{
shape = new PolygonShape(convexPolygon.ToMeters(), 1);
fixture = body.CreateFixture(shape);
_json.SetName(fixture, "Building" + obstacle.Z);
}
break;
case ObstacleType.Rectangle:
var rectangleObstacle = (RectangleObstacle)obstacle;
shape = new PolygonShape(rectangleObstacle.Vertices.ToMeters(), 1);
fixture = body.CreateFixture(shape);
_json.SetName(fixture, "Building" + obstacle.Z);
break;
}
}
}
示例6: ConfinedTest
private ConfinedTest()
{
{
Body ground = BodyFactory.CreateBody(World);
// Floor
EdgeShape shape = new EdgeShape(new Vector2(-10.0f, 0.0f), new Vector2(10.0f, 0.0f));
ground.CreateFixture(shape);
// Left wall
shape = new EdgeShape(new Vector2(-10.0f, 0.0f), new Vector2(-10.0f, 20.0f));
ground.CreateFixture(shape);
// Right wall
shape = new EdgeShape(new Vector2(10.0f, 0.0f), new Vector2(10.0f, 20.0f));
ground.CreateFixture(shape);
// Roof
shape = new EdgeShape(new Vector2(-10.0f, 20.0f), new Vector2(10.0f, 20.0f));
ground.CreateFixture(shape);
}
const float radius = 0.5f;
CircleShape shape2 = new CircleShape(radius, 1);
shape2.Position = Vector2.Zero;
for (int j = 0; j < ColumnCount; ++j)
{
for (int i = 0; i < RowCount; ++i)
{
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(-10.0f + (2.1f * j + 1.0f + 0.01f * i) * radius,
(2.0f * i + 1.0f) * radius);
Fixture fixture = body.CreateFixture(shape2);
fixture.Friction = 0.1f;
}
}
World.Gravity = Vector2.Zero;
}
示例7: AttachCompoundPolygon
public static List<Fixture> AttachCompoundPolygon(List<Vertices> list, float density, Body body, object userData)
{
List<Fixture> res = new List<Fixture>(list.Count);
//Then we create several fixtures using the body
foreach (Vertices vertices in list)
{
if (vertices.Count == 2)
{
EdgeShape shape = new EdgeShape(vertices[0], vertices[1]);
res.Add(body.CreateFixture(shape, userData));
}
else
{
PolygonShape shape = new PolygonShape(vertices, density);
res.Add(body.CreateFixture(shape, userData));
}
}
return res;
}
示例8: EdgeShapeBenchmark
private EdgeShapeBenchmark()
{
// Ground body
{
Body ground = BodyFactory.CreateBody(World);
float x1 = -20.0f;
float y1 = 2.0f * (float)Math.Cos(x1 / 10.0f * (float)Math.PI);
for (int i = 0; i < 80; ++i)
{
float x2 = x1 + 0.5f;
float y2 = 2.0f * (float)Math.Cos(x2 / 10.0f * (float)Math.PI);
EdgeShape shape = new EdgeShape(new Vector2(x1, y1), new Vector2(x2, y2));
ground.CreateFixture(shape);
x1 = x2;
y1 = y2;
}
}
const float w = 1.0f;
const float t = 2.0f;
float b = w / (2.0f + (float)Math.Sqrt(t));
float s = (float)Math.Sqrt(t) * b;
Vertices vertices = new Vertices(8);
vertices.Add(new Vector2(0.5f * s, 0.0f));
vertices.Add(new Vector2(0.5f * w, b));
vertices.Add(new Vector2(0.5f * w, b + s));
vertices.Add(new Vector2(0.5f * s, w));
vertices.Add(new Vector2(-0.5f * s, w));
vertices.Add(new Vector2(-0.5f * w, b + s));
vertices.Add(new Vector2(-0.5f * w, b));
vertices.Add(new Vector2(-0.5f * s, 0.0f));
_polyShape = new PolygonShape(20);
_polyShape.Set(vertices);
}
示例9: GetChildEdge
/// <summary>
/// Get a child edge.
/// </summary>
/// <param name="edge">The edge.</param>
/// <param name="index">The index.</param>
public void GetChildEdge(ref EdgeShape edge, int index)
{
Debug.Assert(2 <= Vertices.Count);
Debug.Assert(0 <= index && index < Vertices.Count);
edge.ShapeType = ShapeType.Edge;
edge.Radius = Radius;
edge.HasVertex0 = true;
edge.HasVertex3 = true;
int i0 = index - 1 >= 0 ? index - 1 : Vertices.Count - 1;
int i1 = index;
int i2 = index + 1 < Vertices.Count ? index + 1 : 0;
int i3 = index + 2;
while (i3 >= Vertices.Count)
{
i3 -= Vertices.Count;
}
edge.Vertex0 = Vertices[i0];
edge.Vertex1 = Vertices[i1];
edge.Vertex2 = Vertices[i2];
edge.Vertex3 = Vertices[i3];
}
示例10: GetChildEdge
/// <summary>
/// This method has been optimized to reduce garbage.
/// </summary>
/// <param name="edge">The cached edge to set properties on.</param>
/// <param name="index">The index.</param>
internal void GetChildEdge(EdgeShape edge, int index)
{
Debug.Assert(0 <= index && index < Vertices.Count - 1);
Debug.Assert(edge != null);
edge.ShapeType = ShapeType.Edge;
edge._radius = _radius;
edge.Vertex1 = Vertices[index + 0];
edge.Vertex2 = Vertices[index + 1];
if (index > 0)
{
edge.Vertex0 = Vertices[index - 1];
edge.HasVertex0 = true;
}
else
{
edge.Vertex0 = _prevVertex;
edge.HasVertex0 = _hasPrevVertex;
}
if (index < Vertices.Count - 2)
{
edge.Vertex3 = Vertices[index + 2];
edge.HasVertex3 = true;
}
else
{
edge.Vertex3 = _nextVertex;
edge.HasVertex3 = _hasNextVertex;
}
}
示例11: CollideEdgeAndPolygon
/// <summary>
/// Collides and edge and a polygon, taking into account edge adjacency.
/// </summary>
/// <param name="manifold">The manifold.</param>
/// <param name="edgeA">The edge A.</param>
/// <param name="xfA">The xf A.</param>
/// <param name="polygonB">The polygon B.</param>
/// <param name="xfB">The xf B.</param>
public static void CollideEdgeAndPolygon(ref Manifold manifold, EdgeShape edgeA, ref Transform xfA, PolygonShape polygonB, ref Transform xfB)
{
EPCollider collider = new EPCollider();
collider.Collide(ref manifold, edgeA, ref xfA, polygonB, ref xfB);
}
示例12: Clone
public override Shape Clone()
{
EdgeShape edge = new EdgeShape();
edge._radius = _radius;
edge._density = _density;
edge.HasVertex0 = HasVertex0;
edge.HasVertex3 = HasVertex3;
edge.Vertex0 = Vertex0;
edge._vertex1 = _vertex1;
edge._vertex2 = _vertex2;
edge.Vertex3 = Vertex3;
edge.MassData = MassData;
return edge;
}
示例13: Clone
public override Shape Clone()
{
EdgeShape clone = new EdgeShape();
clone.ShapeType = ShapeType;
clone._radius = _radius;
clone._density = _density;
clone.HasVertex0 = HasVertex0;
clone.HasVertex3 = HasVertex3;
clone.Vertex0 = Vertex0;
clone._vertex1 = _vertex1;
clone._vertex2 = _vertex2;
clone.Vertex3 = Vertex3;
clone.MassData = MassData;
return clone;
}
示例14: ApplyForceTest
private ApplyForceTest()
{
World.Gravity = Vector2.Zero;
const float restitution = 0.4f;
Body ground;
{
ground = BodyFactory.CreateBody(World);
ground.Position = new Vector2(0.0f, 20.0f);
EdgeShape shape = new EdgeShape(new Vector2(-20.0f, -20.0f), new Vector2(-20.0f, 20.0f));
// Left vertical
Fixture fixture = ground.CreateFixture(shape);
fixture.Restitution = restitution;
// Right vertical
shape = new EdgeShape(new Vector2(20.0f, -20.0f), new Vector2(20.0f, 20.0f));
ground.CreateFixture(shape);
// Top horizontal
shape = new EdgeShape(new Vector2(-20.0f, 20.0f), new Vector2(20.0f, 20.0f));
ground.CreateFixture(shape);
// Bottom horizontal
shape = new EdgeShape(new Vector2(-20.0f, -20.0f), new Vector2(20.0f, -20.0f));
ground.CreateFixture(shape);
}
{
Transform xf1 = new Transform();
xf1.q.Set(0.3524f * Settings.Pi);
xf1.p = MathUtils.Mul(ref xf1.q, new Vector2(1.0f, 0.0f));
Vertices vertices = new Vertices(3);
vertices.Add(MathUtils.Mul(ref xf1, new Vector2(-1.0f, 0.0f)));
vertices.Add(MathUtils.Mul(ref xf1, new Vector2(1.0f, 0.0f)));
vertices.Add(MathUtils.Mul(ref xf1, new Vector2(0.0f, 0.5f)));
PolygonShape poly1 = new PolygonShape(vertices, 4);
Transform xf2 = new Transform();
xf2.q.Set(-0.3524f * Settings.Pi);
xf2.p = MathUtils.Mul(ref xf2.q, new Vector2(-1.0f, 0.0f));
vertices[0] = MathUtils.Mul(ref xf2, new Vector2(-1.0f, 0.0f));
vertices[1] = MathUtils.Mul(ref xf2, new Vector2(1.0f, 0.0f));
vertices[2] = MathUtils.Mul(ref xf2, new Vector2(0.0f, 0.5f));
PolygonShape poly2 = new PolygonShape(vertices, 2);
_body = BodyFactory.CreateBody(World);
_body.BodyType = BodyType.Dynamic;
_body.Position = new Vector2(0.0f, 2.0f);
_body.Rotation = Settings.Pi;
_body.AngularDamping = 5.0f;
_body.LinearDamping = 0.8f;
_body.SleepingAllowed = true;
_body.CreateFixture(poly1);
_body.CreateFixture(poly2);
}
{
Vertices box = PolygonTools.CreateRectangle(0.5f, 0.5f);
PolygonShape shape = new PolygonShape(box, 1);
for (int i = 0; i < 10; ++i)
{
Body body = BodyFactory.CreateBody(World);
body.Position = new Vector2(0.0f, 5.0f + 1.54f * i);
body.BodyType = BodyType.Dynamic;
Fixture fixture = body.CreateFixture(shape);
fixture.Friction = 0.3f;
const float gravity = 10.0f;
float I = body.Inertia;
float mass = body.Mass;
// For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
float radius = (float)Math.Sqrt(2.0 * (I / mass));
FrictionJoint jd = new FrictionJoint(ground, body, Vector2.Zero);
jd.CollideConnected = true;
jd.MaxForce = mass * gravity;
jd.MaxTorque = mass * radius * gravity;
World.AddJoint(jd);
}
}
}
示例15: EdgeTest
private EdgeTest()
{
{
Body ground = BodyFactory.CreateBody(World);
Vector2 v1 = new Vector2(-10.0f, 0.0f);
Vector2 v2 = new Vector2(-7.0f, -2.0f);
Vector2 v3 = new Vector2(-4.0f, 0.0f);
Vector2 v4 = Vector2.Zero;
Vector2 v5 = new Vector2(4.0f, 0.0f);
Vector2 v6 = new Vector2(7.0f, 2.0f);
Vector2 v7 = new Vector2(10.0f, 0.0f);
EdgeShape shape = new EdgeShape(v1, v2);
shape.HasVertex3 = true;
shape.Vertex3 = v3;
ground.CreateFixture(shape);
shape.Set(v2, v3);
shape.HasVertex0 = true;
shape.HasVertex3 = true;
shape.Vertex0 = v1;
shape.Vertex3 = v4;
ground.CreateFixture(shape);
shape.Set(v3, v4);
shape.HasVertex0 = true;
shape.HasVertex3 = true;
shape.Vertex0 = v2;
shape.Vertex3 = v5;
ground.CreateFixture(shape);
shape.Set(v4, v5);
shape.HasVertex0 = true;
shape.HasVertex3 = true;
shape.Vertex0 = v3;
shape.Vertex3 = v6;
ground.CreateFixture(shape);
shape.Set(v5, v6);
shape.HasVertex0 = true;
shape.HasVertex3 = true;
shape.Vertex0 = v4;
shape.Vertex3 = v7;
ground.CreateFixture(shape);
shape.Set(v6, v7);
shape.HasVertex0 = true;
shape.Vertex0 = v5;
ground.CreateFixture(shape);
}
{
Body body = BodyFactory.CreateBody(World, new Vector2(-0.5f, 0.6f));
body.BodyType = BodyType.Dynamic;
body.SleepingAllowed = false;
CircleShape shape = new CircleShape(0.5f, 1);
_circleFixture = body.CreateFixture(shape);
}
{
Body body = BodyFactory.CreateBody(World, new Vector2(1.0f, 0.6f));
body.BodyType = BodyType.Dynamic;
body.SleepingAllowed = false;
PolygonShape shape = new PolygonShape(1);
shape.Vertices = PolygonTools.CreateRectangle(0.5f, 0.5f);
body.CreateFixture(shape);
}
}