本文整理汇总了C#中FarseerPhysics.Collision.Shapes.EdgeShape类的典型用法代码示例。如果您正苦于以下问题:C# EdgeShape类的具体用法?C# EdgeShape怎么用?C# EdgeShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EdgeShape类属于FarseerPhysics.Collision.Shapes命名空间,在下文中一共展示了EdgeShape类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:34,代码来源:SensorTest.cs
示例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);
}
}
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:60,代码来源:RopeTest.cs
示例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);
}
}
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:34,代码来源:CircleBenchmarkTest.cs
示例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);
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:49,代码来源:PrismaticTest.cs
示例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;
}
}
}
开发者ID:spritefun,项目名称:gta2net,代码行数:43,代码来源:Physics.cs
示例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;
}
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:42,代码来源:ConfinedTest.cs
示例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;
}
开发者ID:BraveSirAndrew,项目名称:farseerduality,代码行数:21,代码来源:FixtureFactory.cs
示例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);
}
开发者ID:Ratel13,项目名称:cocos2d-xna,代码行数:39,代码来源:EdgeShapeBenchmark.cs
示例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];
}
开发者ID:dvgamer,项目名称:GhostLegend-XNA,代码行数:28,代码来源:LoopShape.cs
示例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;
}
}
开发者ID:TIHan,项目名称:MemeFighter,代码行数:38,代码来源:ChainShape.cs
示例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);
}
开发者ID:Alexz18z35z,项目名称:Gibbo2D,代码行数:13,代码来源:Collision.cs
示例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;
}
开发者ID:HaKDMoDz,项目名称:Zazumo,代码行数:14,代码来源:EdgeShape.cs
示例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;
}
开发者ID:ImmortalJINX,项目名称:Project-EGOR,代码行数:15,代码来源:EdgeShape.cs
示例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);
}
}
}
开发者ID:boris2,项目名称:mmogameproject2,代码行数:93,代码来源:ApplyForceTest.cs
示例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);
}
}
开发者ID:RCGame,项目名称:FarseerPhysics,代码行数:72,代码来源:EdgeTest.cs
示例16: EdgeShapes
private EdgeShapes()
{
// 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;
}
}
{
Vertices vertices = new Vertices(3);
vertices.Add(new Vector2(-0.5f, 0.0f));
vertices.Add(new Vector2(0.5f, 0.0f));
vertices.Add(new Vector2(0.0f, 1.5f));
_polygons[0] = new PolygonShape(20);
_polygons[0].Set(vertices);
}
{
Vertices vertices = new Vertices(3);
vertices.Add(new Vector2(-0.1f, 0.0f));
vertices.Add(new Vector2(0.1f, 0.0f));
vertices.Add(new Vector2(0.0f, 1.5f));
_polygons[1] = new PolygonShape(20);
_polygons[1].Set(vertices);
}
{
const float w = 1.0f;
float b = w / (2.0f + (float)Math.Sqrt(2.0f));
float s = (float)Math.Sqrt(2.0f) * 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));
_polygons[2] = new PolygonShape(20);
_polygons[2].Set(vertices);
}
{
_polygons[3] = new PolygonShape(20);
_polygons[3].SetAsBox(0.5f, 0.5f);
}
{
_circle = new CircleShape(0.5f, 1);
}
_bodyIndex = 0;
_angle = 0.0f;
}
开发者ID:hilts-vaughan,项目名称:Farseer-Physics,代码行数:69,代码来源:EdgeShapesTest.cs
示例17: CharacterCollisionTest
private CharacterCollisionTest()
{
//Ground body
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
// Collinear edges
EdgeShape shape = new EdgeShape(new Vector2(-8.0f, 1.0f), new Vector2(-6.0f, 1.0f));
ground.CreateFixture(shape);
shape = new EdgeShape(new Vector2(-6.0f, 1.0f), new Vector2(-4.0f, 1.0f));
ground.CreateFixture(shape);
shape = new EdgeShape(new Vector2(-4.0f, 1.0f), new Vector2(-2.0f, 1.0f));
ground.CreateFixture(shape);
// Square tiles
PolygonShape tile = new PolygonShape(1);
tile.SetAsBox(1.0f, 1.0f, new Vector2(4.0f, 3.0f), 0.0f);
ground.CreateFixture(tile);
tile.SetAsBox(1.0f, 1.0f, new Vector2(6.0f, 3.0f), 0.0f);
ground.CreateFixture(tile);
tile.SetAsBox(1.0f, 1.0f, new Vector2(8.0f, 3.0f), 0.0f);
ground.CreateFixture(tile);
// Square made from an edge loop.
Vertices vertices = new Vertices(4);
vertices.Add(new Vector2(-1.0f, 3.0f));
vertices.Add(new Vector2(1.0f, 3.0f));
vertices.Add(new Vector2(1.0f, 5.0f));
vertices.Add(new Vector2(-1.0f, 5.0f));
LoopShape loopShape = new LoopShape(vertices);
ground.CreateFixture(loopShape);
// Edge loop.
vertices = new Vertices(10);
vertices.Add(new Vector2(0.0f, 0.0f));
vertices.Add(new Vector2(6.0f, 0.0f));
vertices.Add(new Vector2(6.0f, 2.0f));
vertices.Add(new Vector2(4.0f, 1.0f));
vertices.Add(new Vector2(2.0f, 2.0f));
vertices.Add(new Vector2(-2.0f, 2.0f));
vertices.Add(new Vector2(-4.0f, 3.0f));
vertices.Add(new Vector2(-6.0f, 2.0f));
vertices.Add(new Vector2(-6.0f, 0.0f));
BodyFactory.CreateLoopShape(World, vertices, new Vector2(-10, 4));
// Square character
Body squareCharacter = BodyFactory.CreateRectangle(World, 1, 1, 20);
squareCharacter.Position = new Vector2(-3.0f, 5.0f);
squareCharacter.BodyType = BodyType.Dynamic;
squareCharacter.FixedRotation = true;
squareCharacter.SleepingAllowed = false;
squareCharacter.OnCollision += CharacterOnCollision;
squareCharacter.OnSeparation += CharacterOnSeparation;
// Square character 2
Body squareCharacter2 = BodyFactory.CreateRectangle(World, 0.5f, 0.5f, 20);
squareCharacter2.Position = new Vector2(-5.0f, 5.0f);
squareCharacter2.BodyType = BodyType.Dynamic;
squareCharacter2.FixedRotation = true;
squareCharacter2.SleepingAllowed = false;
// Hexagon character
float angle = 0.0f;
const float delta = Settings.Pi / 3.0f;
vertices = new Vertices(6);
for (int i = 0; i < 6; ++i)
{
vertices.Add(new Vector2(0.5f * (float)Math.Cos(angle), 0.5f * (float)Math.Sin(angle)));
angle += delta;
}
Body hexCharacter = BodyFactory.CreatePolygon(World, vertices, 20);
hexCharacter.Position = new Vector2(-5.0f, 8.0f);
hexCharacter.BodyType = BodyType.Dynamic;
hexCharacter.FixedRotation = true;
hexCharacter.SleepingAllowed = false;
// Circle character
Body circleCharacter = BodyFactory.CreateCircle(World, 0.5f, 20);
circleCharacter.Position = new Vector2(3.0f, 5.0f);
circleCharacter.BodyType = BodyType.Dynamic;
circleCharacter.FixedRotation = true;
circleCharacter.SleepingAllowed = false;
}
开发者ID:h7ing,项目名称:CocosSharp,代码行数:86,代码来源:CharacterCollisionTest.cs
示例18: CompareTo
public bool CompareTo( EdgeShape shape )
{
return ( hasVertex0 == shape.hasVertex0 &&
hasVertex3 == shape.hasVertex3 &&
vertex0 == shape.vertex0 &&
vertex1 == shape.vertex1 &&
vertex2 == shape.vertex2 &&
vertex3 == shape.vertex3 );
}
开发者ID:prime31,项目名称:Nez,代码行数:9,代码来源:EdgeShape.cs
示例19: Deserialize
public void Deserialize(World world, Stream stream)
{
world.Clear();
XMLFragmentElement root = XMLFragmentParser.LoadFromStream(stream);
if (root.Name.ToLower() != "world")
throw new Exception();
foreach (XMLFragmentElement main in root.Elements)
{
if (main.Name.ToLower() == "gravity")
{
world.Gravity = ReadVector(main);
}
}
foreach (XMLFragmentElement shapeElement in root.Elements)
{
if (shapeElement.Name.ToLower() == "shapes")
{
foreach (XMLFragmentElement n in shapeElement.Elements)
{
if (n.Name.ToLower() != "shape")
throw new Exception();
ShapeType type = (ShapeType)Enum.Parse(typeof(ShapeType), n.Attributes[0].Value, true);
switch (type)
{
case ShapeType.Circle:
{
CircleShape shape = new CircleShape();
foreach (XMLFragmentElement sn in n.Elements)
{
switch (sn.Name.ToLower())
{
case "radius":
shape.Radius = float.Parse(sn.Value);
break;
case "position":
shape.Position = ReadVector(sn);
break;
default:
throw new Exception();
}
}
_shapes.Add(shape);
}
break;
case ShapeType.Polygon:
{
PolygonShape shape = new PolygonShape();
foreach (XMLFragmentElement sn in n.Elements)
{
switch (sn.Name.ToLower())
{
case "vertices":
{
List<Vector2> verts = new List<Vector2>();
foreach (XMLFragmentElement vert in sn.Elements)
verts.Add(ReadVector(vert));
shape.Set(new Vertices(verts.ToArray()));
}
break;
case "centroid":
shape.MassData.Centroid = ReadVector(sn);
break;
}
}
_shapes.Add(shape);
}
break;
case ShapeType.Edge:
{
EdgeShape shape = new EdgeShape();
foreach (XMLFragmentElement sn in n.Elements)
{
switch (sn.Name.ToLower())
{
case "hasvertex0":
shape.HasVertex0 = bool.Parse(sn.Value);
break;
case "hasvertex3":
shape.HasVertex0 = bool.Parse(sn.Value);
break;
case "vertex0":
shape.Vertex0 = ReadVector(sn);
break;
case "vertex1":
shape.Vertex1 = ReadVector(sn);
break;
case "vertex2":
shape.Vertex2 = ReadVector(sn);
//.........这里部分代码省略.........
开发者ID:vvnurmi,项目名称:assaultwing,代码行数:101,代码来源:Serialization.cs
示例20: AttachEdge
public static Fixture AttachEdge(Vector2 start, Vector2 end, Body body, object userData)
{
EdgeShape edgeShape = new EdgeShape(start, end);
return body.CreateFixture(edgeShape, userData);
}
开发者ID:HaKDMoDz,项目名称:Zazumo,代码行数:5,代码来源:FixtureFactory.cs
注:本文中的FarseerPhysics.Collision.Shapes.EdgeShape类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论