本文整理汇总了C#中FarseerPhysics.Common.Path类的典型用法代码示例。如果您正苦于以下问题:C# Path类的具体用法?C# Path怎么用?C# Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Path类属于FarseerPhysics.Common命名空间,在下文中一共展示了Path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateChain
/// <summary>
/// Creates a chain.
/// </summary>
/// <param name="world">The world.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <param name="linkWidth">The width.</param>
/// <param name="linkHeight">The height.</param>
/// <param name="fixStart">if set to <c>true</c> [fix start].</param>
/// <param name="fixEnd">if set to <c>true</c> [fix end].</param>
/// <param name="numberOfLinks">The number of links.</param>
/// <param name="linkDensity">The link density.</param>
/// <returns></returns>
public static Path CreateChain(World world, Vector2 start, Vector2 end, float linkWidth, float linkHeight, bool fixStart, bool fixEnd, int numberOfLinks, float linkDensity)
{
// Chain start / end
Path path = new Path();
path.Add(start);
path.Add(end);
// A single chainlink
PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(linkWidth, linkHeight));
// Use PathManager to create all the chainlinks based on the chainlink created before.
List<Body> chainLinks = PathManager.EvenlyDistibuteShapesAlongPath(world, path, shape, BodyType.Dynamic, numberOfLinks, linkDensity);
if (fixStart)
{
// Fix the first chainlink to the world
JointFactory.CreateFixedRevoluteJoint(world, chainLinks[0], new Vector2(0, -(linkHeight / 2)), chainLinks[0].Position);
}
if (fixEnd)
{
// Fix the last chainlink to the world
JointFactory.CreateFixedRevoluteJoint(world, chainLinks[chainLinks.Count - 1], new Vector2(0, (linkHeight / 2)), chainLinks[chainLinks.Count - 1].Position);
}
// Attach all the chainlinks together with a revolute joint
PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks, new Vector2(0, -linkHeight), new Vector2(0, linkHeight),
false, false);
return (path);
}
示例2: EvenlyDistributeShapesAlongPath
/// <summary>
/// Duplicates the given Body along the given path for approximatly the given copies.
/// </summary>
/// <param name="world">The world.</param>
/// <param name="path">The path.</param>
/// <param name="shapes">The shapes.</param>
/// <param name="type">The type.</param>
/// <param name="copies">The copies.</param>
/// <param name="userData"></param>
/// <returns></returns>
public static List<Body> EvenlyDistributeShapesAlongPath(World world, Path path, IEnumerable<Shape> shapes, BodyType type, int copies, object userData = null)
{
List<Vector3> centers = path.SubdivideEvenly(copies);
List<Body> bodyList = new List<Body>();
for (int i = 0; i < centers.Count; i++)
{
Body b = new Body(world);
// copy the type from original body
b.BodyType = type;
b.Position = new Vector2(centers[i].X, centers[i].Y);
b.Rotation = centers[i].Z;
b.UserData = userData;
foreach (Shape shape in shapes)
{
b.CreateFixture(shape);
}
bodyList.Add(b);
}
return bodyList;
}
示例3: Chain
public Chain(Path path, List<Body> bodies)
{
Path = path;
Bodies = bodies;
AddRange(bodies);
}
示例4: Robot
public Robot(Texture2D tex, Vector2 pos, World world)
{
this.tex = tex;
this.pos = pos;
robotBody = BodyFactory.CreateRectangle(world, 100f / 64f, 100f / 64f, 1f, pos / 64);
robotBody.BodyType = BodyType.Dynamic;
robotBody.FixedRotation = true;
robotBody.CollisionCategories = Category.Cat3;
robotBody.CollidesWith = Category.All ^ Category.Cat4;
robotBody.BodyId = 4;
robotBody.OnCollision += new OnCollisionEventHandler(OnCollision);
// path
{
pos = pos / 64;
path = new Path();
path.Add(pos);
path.Add(new Vector2(pos.X + 6.5f, pos.Y));
path.Add(new Vector2(pos.X + 6.5f, pos.Y + 0.1f));
path.Add(new Vector2(pos.X, pos.Y + 0.1f));
path.Closed = true;
}
}
示例5: LoadContent
public override void LoadContent()
{
base.LoadContent();
World.Gravity = new Vector2(0, 9.82f);
_border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport);
/* Bridge */
//We make a path using 2 points.
Path bridgePath = new Path();
bridgePath.Add(new Vector2(-15, 5));
bridgePath.Add(new Vector2(15, 5));
bridgePath.Closed = false;
Vertices box = PolygonTools.CreateRectangle(0.125f, 0.5f);
PolygonShape shape = new PolygonShape(box, 20);
_bridgeBodies = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePath, shape,
BodyType.Dynamic, 29);
_bridgeBox =
new Sprite(ScreenManager.Assets.TextureFromShape(shape, MaterialType.Dots, Color.SandyBrown, 1f));
//Attach the first and last fixtures to the world
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodies[0], new Vector2(0f, -0.5f),
_bridgeBodies[0].Position);
JointFactory.CreateFixedRevoluteJoint(World, _bridgeBodies[_bridgeBodies.Count - 1], new Vector2(0, 0.5f),
_bridgeBodies[_bridgeBodies.Count - 1].Position);
PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodies, new Vector2(0f, -0.5f),
new Vector2(0f, 0.5f),
false, true);
/* Soft body */
//We make a rectangular path.
Path rectanglePath = new Path();
rectanglePath.Add(new Vector2(-6, -11));
rectanglePath.Add(new Vector2(-6, 1));
rectanglePath.Add(new Vector2(6, 1));
rectanglePath.Add(new Vector2(6, -11));
rectanglePath.Closed = true;
//Creating two shapes. A circle to form the circle and a rectangle to stabilize the soft body.
List<Shape> shapes = new List<Shape>(2);
shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0f), 0f), 1f));
shapes.Add(new CircleShape(0.5f, 1f));
//We distribute the shapes in the rectangular path.
_softBodies = PathManager.EvenlyDistributeShapesAlongPath(World, rectanglePath, shapes,
BodyType.Dynamic, 30);
_softBodyBox =
new Sprite(ScreenManager.Assets.TextureFromShape(shapes[0], MaterialType.Blank, Color.Silver * 0.8f, 1f));
_softBodyBox.Origin += new Vector2(ConvertUnits.ToDisplayUnits(0.1f), 0f);
_softBodyCircle =
new Sprite(ScreenManager.Assets.TextureFromShape(shapes[1], MaterialType.Waves, Color.Silver, 1f));
//Attach the bodies together with revolute joints. The rectangular form will converge to a circular form.
PathManager.AttachBodiesWithRevoluteJoint(World, _softBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f),
true, true);
}
示例6: LoadContent
public override void LoadContent()
{
base.LoadContent();
World.Gravity = new Vector2(0, 9.82f);
_border = new Border(World, Lines, Framework.GraphicsDevice);
// Bridge
// We make a path using 2 points.
Path bridgePath = new Path();
bridgePath.Add(new Vector2(-15, 5));
bridgePath.Add(new Vector2(15, 5));
bridgePath.Closed = false;
Vertices box = PolygonTools.CreateRectangle(0.125f, 0.5f);
PolygonShape shape = new PolygonShape(box, 20);
_bridgeBodies = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePath, shape, BodyType.Dynamic, 29);
// Attach the first and last fixtures to the world
Body anchor = new Body(World, Vector2.Zero);
anchor.BodyType = BodyType.Static;
World.AddJoint(new RevoluteJoint(_bridgeBodies[0], anchor, _bridgeBodies[0].Position - new Vector2(0.5f, 0f), true));
World.AddJoint(new RevoluteJoint(_bridgeBodies[_bridgeBodies.Count - 1], anchor, _bridgeBodies[_bridgeBodies.Count - 1].Position + new Vector2(0.5f, 0f), true));
PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f), false, true);
// Soft body
// We make a rectangular path.
Path rectanglePath = new Path();
rectanglePath.Add(new Vector2(-6, -11));
rectanglePath.Add(new Vector2(-6, 1));
rectanglePath.Add(new Vector2(6, 1));
rectanglePath.Add(new Vector2(6, -11));
rectanglePath.Closed = true;
// Creating two shapes. A circle to form the circle and a rectangle to stabilize the soft body.
Shape[] shapes = new Shape[2];
shapes[0] = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0f), 0f), 1f);
shapes[1] = new CircleShape(0.5f, 1f);
// We distribute the shapes in the rectangular path.
_softBodies = PathManager.EvenlyDistributeShapesAlongPath(World, rectanglePath, shapes, BodyType.Dynamic, 30);
// Attach the bodies together with revolute joints. The rectangular form will converge to a circular form.
PathManager.AttachBodiesWithRevoluteJoint(World, _softBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f), true, true);
// GFX
_bridgeBox = new Sprite(ContentWrapper.TextureFromShape(shape, ContentWrapper.Orange, ContentWrapper.Brown));
_softBodyBox = new Sprite(ContentWrapper.TextureFromShape(shapes[0], ContentWrapper.Green, ContentWrapper.Black));
_softBodyBox.Origin += new Vector2(ConvertUnits.ToDisplayUnits(0.1f), 0f);
_softBodyCircle = new Sprite(ContentWrapper.TextureFromShape(shapes[1], ContentWrapper.Lime, ContentWrapper.Grey));
}
示例7: Whip
public Whip(Texture2D tex, Vector2 start, Vector2 end, World world )
{
this.tex = tex;
this.world = world;
this.start = start / 64;
this.end = end / 64;
Path path = new Path();
path.Add(this.start);
path.Add(this.end);
//A single chainlink
PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.125f, 0.125f),20);
// ChainLink shape = new ChainLink(100);
//Use PathFactory to create all the chainlinks based on the chainlink created before.
chainLinks = PathManager.EvenlyDistributeShapesAlongPath(world, path, shape, BodyType.Dynamic,30);
foreach (Body chainLink in chainLinks)
{
foreach (Fixture f in chainLink.FixtureList)
{
f.Friction = 0.2f;
f.CollisionCategories = Category.Cat3;
Category whipMask = Category.All ^ Category.Cat2;
f.CollidesWith = whipMask;
f.Body.BodyId = 8;
f.OnCollision += new OnCollisionEventHandler(OnCollision);
}
}
//Fix the first chainlink to the world
// FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(chainLinks[0], Vector2.Zero, chainLinks[0].Position);
// Game1.world.AddJoint(fixedJoint);
//Attach all the chainlinks together with a revolute joint. This is the spacing between links
joints = PathManager.AttachBodiesWithRevoluteJoint(world, chainLinks,
new Vector2(0, -0.1f),
new Vector2(0, 0.1f),
false, false);
//The chain is breakable
for (int i = 0; i < joints.Count; i++)
{
RevoluteJoint r = joints[i];
r.Breakpoint = 5000f;
}
}
示例8: PathTest
private PathTest()
{
//Single body that moves around path
_movingBody = BodyFactory.CreateBody(World);
_movingBody.Position = new Vector2(-25, 25);
_movingBody.BodyType = BodyType.Dynamic;
_movingBody.CreateFixture(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f), 1));
//Static shape made up of bodies
_path = new Path();
_path.Add(new Vector2(0, 20));
_path.Add(new Vector2(5, 15));
_path.Add(new Vector2(20, 18));
_path.Add(new Vector2(15, 1));
_path.Add(new Vector2(-5, 14));
_path.Closed = true;
CircleShape shape = new CircleShape(0.25f, 1);
PathManager.EvenlyDistributeShapesAlongPath(World, _path, shape, BodyType.Static, 100);
//Smaller shape that is movable. Created from small rectangles and circles.
Vector2 xform = new Vector2(0.5f, 0.5f);
_path.Scale(ref xform);
xform = new Vector2(5, 5);
_path.Translate(ref xform);
List<Shape> shapes = new List<Shape>(2);
shapes.Add(new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0), 0), 1));
shapes.Add(new CircleShape(0.5f, 1));
List<Body> bodies = PathManager.EvenlyDistributeShapesAlongPath(World, _path, shapes, BodyType.Dynamic, 20);
//Attach the bodies together with revolute joints
PathManager.AttachBodiesWithRevoluteJoint(World, bodies, new Vector2(0, 0.5f), new Vector2(0, -0.5f), true,
true);
xform = new Vector2(-25, 0);
_path.Translate(ref xform);
Body body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Static;
//Static shape made up of edges
PathManager.ConvertPathToEdges(_path, body, 25);
body.Position -= new Vector2(0, 10);
xform = new Vector2(0, 15);
_path.Translate(ref xform);
PathManager.ConvertPathToPolygon(_path, body, 1, 50);
}
示例9: convertPathToPolygon
/// <summary>
/// Convert a closed path into a polygon.
/// Convex decomposition is automatically performed.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="density">The density.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void convertPathToPolygon( Path path, Body body, float density, int subdivisions )
{
if( !path.isClosed )
throw new Exception( "The path must be closed to convert to a polygon." );
var verts = path.getVertices( subdivisions );
var decomposedVerts = Triangulate.convexPartition( new Vertices( verts ), TriangulationAlgorithm.Bayazit );
foreach( Vertices item in decomposedVerts )
{
body.createFixture( new PolygonShape( item, density ) );
}
}
示例10: ConvertPathToEdges
//Contributed by Matthew Bettcher
/// <summary>
/// Convert a path into a set of edges and attaches them to the specified body.
/// Note: use only for static edges.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void ConvertPathToEdges(Path path, Body body, int subdivisions)
{
List<Vector2> verts = path.GetVertices(subdivisions);
for (int i = 1; i < verts.Count; i++)
{
body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[i], verts[i - 1]), 0));
}
if (path.Closed)
{
body.CreateFixture(new PolygonShape(PolygonTools.CreateEdge(verts[verts.Count - 1], verts[0]), 0));
}
}
示例11: ConvertPathToPolygon
/// <summary>
/// Convert a closed path into a polygon.
/// Convex decomposition is automatically performed.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="density">The density.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void ConvertPathToPolygon(Path path, Body body, float density, int subdivisions)
{
if (!path.Closed)
throw new Exception("The path must be closed to convert to a polygon.");
List<Vector2> verts = path.GetVertices(subdivisions);
List<Vertices> decomposedVerts = Triangulate.ConvexPartition(new Vertices(verts), TriangulationAlgorithm.Earclip);
foreach (Vertices item in decomposedVerts)
{
body.CreateFixture(new PolygonShape(item, density));
}
}
示例12: ConvertPathToPolygon
/// <summary>
/// Convert a closed path into a polygon.
/// Convex decomposition is automatically performed.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="density">The density.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void ConvertPathToPolygon(Path path, Body body, float density, int subdivisions)
{
if (!path.Closed)
throw new Exception("The path must be closed to convert to a polygon.");
var verts = path.GetVertices(subdivisions);
List<Vertices> decomposedVerts = EarclipDecomposer.ConvexPartition(new Vertices(verts));
//List<Vertices> decomposedVerts = BayazitDecomposer.ConvexPartition(new Vertices(verts));
foreach (Vertices item in decomposedVerts)
{
body.CreateFixture(new PolygonShape(item, density));
}
}
示例13: convertPathToEdges
//Contributed by Matthew Bettcher
/// <summary>
/// Convert a path into a set of edges and attaches them to the specified body.
/// Note: use only for static edges.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void convertPathToEdges( Path path, Body body, int subdivisions )
{
var verts = path.getVertices( subdivisions );
if( path.isClosed )
{
var chain = new ChainShape( verts, true );
body.createFixture( chain );
}
else
{
for( int i = 1; i < verts.Count; i++ )
{
body.createFixture( new EdgeShape( verts[i], verts[i - 1] ) );
}
}
}
示例14: ConvertPathToEdges
//Contributed by Matthew Bettcher
/// <summary>
/// Convert a path into a set of edges and attaches them to the specified body.
/// Note: use only for static edges.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="body">The body.</param>
/// <param name="subdivisions">The subdivisions.</param>
public static void ConvertPathToEdges(Path path, Body body, int subdivisions)
{
Vertices verts = path.GetVertices(subdivisions);
if (path.Closed)
{
LoopShape loop = new LoopShape(verts);
body.CreateFixture(loop);
}
else
{
for (int i = 1; i < verts.Count; i++)
{
body.CreateFixture(new EdgeShape(verts[i], verts[i - 1]));
}
}
}
示例15: Bady
/// <summary>
/// Creates a bady
/// </summary>
/// <param name="tex"></param>
/// <param name="pos">Physcis units</param>
/// <param name="pathLenght"></param>
/// <param name="direction">true for an x - axis movement</param>
/// <param name="rotation">angle in degrees</param>
/// <param name="content"></param>
public Bady(Texture2D tex, Vector2 pos, int pathLenght, bool direction, float rotation ,ContentManager content,World world)
{
this.tex = tex;
this.pos = pos;
this.world = world;
Lasers = new List<Laser>();
laserTex = content.Load<Texture2D>("orangeLaser");
this.direction = direction;
// create the path the AI follows
if (this.direction)
{
path = new Path();
path.Add(pos);
path.Add(new Vector2(pos.X + pathLenght, pos.Y));
path.Add(new Vector2(pos.X + pathLenght, pos.Y + 0.1f));
path.Add(new Vector2(pos.X, pos.Y + 0.1f));
path.Closed = true;
}
else
{
path = new Path();
path.Add(this.pos);
path.Add(new Vector2(pos.X, pos.Y + pathLenght));
path.Add(new Vector2(pos.X - 0.1f, pos.Y + pathLenght));
path.Add(new Vector2(pos.X - 0.1f, pos.Y / 64));
path.Closed = true;
}
//Badybody
{
badyBody = BodyFactory.CreateRectangle(world, tex.Width / 64.0f, tex.Height / 64.0f, 1f, pos);
badyBody.BodyType = BodyType.Dynamic;
badyBody.Mass = 10f;
badyBody.CollisionCategories = Category.Cat4;
badyBody.CollidesWith = Category.All ^ Category.Cat2;
badyBody.Rotation = AngleToRads(rotation);
badyBody.FixedRotation = true;
badyBody.OnCollision += new OnCollisionEventHandler(OnCollision);
badyBody.BodyId = 9;
}
}