本文整理汇总了C#中FarseerGames.FarseerPhysics.Dynamics.Body类的典型用法代码示例。如果您正苦于以下问题:C# Body类的具体用法?C# Body怎么用?C# Body使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Body类属于FarseerGames.FarseerPhysics.Dynamics命名空间,在下文中一共展示了Body类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public void Load(ContentManager content)
{
_splatTexture = content.Load<Texture2D>("Content/Terrain");
//Create an array to hold the data from the texture
uint[] data = new uint[_splatTexture.Width * _splatTexture.Height];
//Transfer the texture data to the array
_splatTexture.GetData(data);
// get a set of vertices from a texture
PolygonCreationAssistance pca = new PolygonCreationAssistance(data, _splatTexture.Width, _splatTexture.Height);
pca.HullTolerance = 6f;
pca.HoleDetection = false;
pca.MultipartDetection = false;
pca.AlphaTolerance = 20;
// extract those vertices into a Vertices structure
_splatTextureVertices = Vertices.CreatePolygon(ref pca)[0];
// create a body
_splatBody = BodyFactory.Instance.CreatePolygonBody(_physicsSimulator, _splatTextureVertices, 1);
_splatBody.Position = _position;
// use AutoDivide to find up to 25 convex geoms from a set of vertices
GeomFactory.Instance.CreateSATPolygonGeom(_physicsSimulator, _splatBody, _splatTextureVertices, 25);
}
示例2: Load
public void Load(TangramWindow window, PhysicsSimulator physicsSimulator)
{
//use the body factory to create the physics body
this._borderBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, this._width, this._height, 1);
this._borderBody.IsStatic = true;
this._borderBody.Position = _position;
LoadBorderGeom(physicsSimulator);
float left = (_position.X - this._width / 2f);
float right = (_position.X + this._width / 2f);
float top = (_position.Y - this._height / 2f);
float bottom = (_position.Y + this._height / 2f);
// rectangle's position should be the point left and top most
Rectangle leftBorder = window.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(this._borderWidth, this._height));
TangramWindow.PositionTopLeft(leftBorder, new Vector2(left, top));
Rectangle rightBorder = window.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(this._borderWidth, this._height));
TangramWindow.PositionTopLeft(rightBorder, new Vector2(right - _borderWidth, top));
Rectangle topBorder = window.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(this._width, this._borderWidth));
TangramWindow.PositionTopLeft(topBorder, new Vector2(left, top));
Rectangle bottomBorder = window.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255), new Vector2(this._width, this._borderWidth));
TangramWindow.PositionTopLeft(bottomBorder, new Vector2(left, bottom - _borderWidth));
}
示例3: CreateAngleLimitJoint
public AngleLimitJoint CreateAngleLimitJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2,
float min, float max)
{
AngleLimitJoint angleLimitJoint = CreateAngleLimitJoint(body1, body2, min, max);
physicsSimulator.Add(angleLimitJoint);
return angleLimitJoint;
}
示例4: CreateAngleSpring
public AngleSpring CreateAngleSpring(PhysicsSimulator physicsSimulator, Body body1, Body body2,
float springConstant, float dampingConstant)
{
AngleSpring angleSpring = CreateAngleSpring(body1, body2, springConstant, dampingConstant);
physicsSimulator.Add(angleSpring);
return angleSpring;
}
示例5: CreateAngleJoint
public AngleJoint CreateAngleJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2, float softness,
float biasFactor)
{
AngleJoint angleJoint = CreateAngleJoint(body1, body2, softness, biasFactor);
physicsSimulator.Add(angleJoint);
return angleJoint;
}
示例6: sprite
//use this constructor when you want to add a sprite from the content pipeline
//sprites should have a pure magenta background for
//transparency
public sprite(theGame reference, String contentAssetName, float width, float height, float X, float Y)
{
asset = reference.Content.Load<Texture2D>(contentAssetName);
spriteOrigin = new Vector2(asset.Width / 2f, asset.Height / 2f);
this.X = X;
this.Y = Y;
this.width = width;
this.height = height;
rectangle = new Rectangle((int)this.X, (int)this.Y, (int)width, (int)height);
this.identity = identity;
this.reference = reference;
rectBody = BodyFactory.Instance.CreateRectangleBody(reference.ps, width, height, 1);//PHYSICS
rectBody.Position = new FarseerGames.FarseerPhysics.Mathematics.Vector2(this.X, this.Y);//PHYSICS
rectGeom = GeomFactory.Instance.CreateRectangleGeom(reference.ps,rectBody, this.width, this.height);//PHYSICS
rectGeom.SetBody(rectBody);
rectGeom.CollisionEnabled = true;
this.rectGeom.CollisionResponseEnabled = true;
this.rectGeom.CollisionCategories = CollisionCategory.All;
this.rectGeom.CollidesWith = CollisionCategory.All;
rectBody.Enabled = true;//PHYSICS
rectGeom.OnSeparation += OnSeperation;
rectGeom.OnCollision += OnCollision;
reference.ps.BroadPhaseCollider.OnBroadPhaseCollision += OnBroadPhaseCollision;
reference.ps.Add(rectBody);
reference.ps.Add(rectGeom);
}
示例7: CreateRevoluteJoint
public RevoluteJoint CreateRevoluteJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2,
Vector2 initialAnchorPosition)
{
RevoluteJoint revoluteJoint = CreateRevoluteJoint(body1, body2, initialAnchorPosition);
physicsSimulator.Add(revoluteJoint);
return revoluteJoint;
}
示例8: CreatePinJoint
public PinJoint CreatePinJoint(PhysicsSimulator physicsSimulator, Body body1, Vector2 anchor1, Body body2,
Vector2 anchor2)
{
PinJoint pinJoint = CreatePinJoint(body1, anchor1, body2, anchor2);
physicsSimulator.Add(pinJoint);
return pinJoint;
}
示例9: Initialize
public override void Initialize()
{
ClearCanvas();
physicsSimulator = new PhysicsSimulator(new Vector2(0, 100));
physicsSimulator.BiasFactor = .4f;
int borderWidth = (int) (ScreenManager.ScreenHeight*.05f);
_border = new Border(ScreenManager.ScreenWidth + borderWidth*2, ScreenManager.ScreenHeight + borderWidth*2,
borderWidth, ScreenManager.ScreenCenter);
_border.Load(this, physicsSimulator);
_rectangleBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 32, 32, 1f);
_rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rectangleBody, 32, 32);
_rectangleGeom.FrictionCoefficient = .4f;
_rectangleGeom.RestitutionCoefficient = 0f;
//create the pyramid near the bottom of the screen.
_pyramid = new Pyramid(_rectangleBody, _rectangleGeom, 32f/3f, 32f/3f, 32, 32, _pyramidBaseBodyCount,
new Vector2(ScreenManager.ScreenCenter.X - _pyramidBaseBodyCount*.5f*(32 + 32/3),
ScreenManager.ScreenHeight - 125));
_pyramid.Load(this, physicsSimulator);
_floor = new Floor(ScreenManager.ScreenWidth, 100,
new Vector2(ScreenManager.ScreenCenter.X, ScreenManager.ScreenHeight - 50));
_floor.Load(this, physicsSimulator);
_agent = new Agent(ScreenManager.ScreenCenter - new Vector2(320, 300));
_agent.Load(this, physicsSimulator);
controlledBody = _agent.Body;
base.Initialize();
}
示例10: CreateFixedAngleSpring
public FixedAngleSpring CreateFixedAngleSpring(PhysicsSimulator physicsSimulator, Body body,
float springConstant, float dampningConstant)
{
FixedAngleSpring fixedAngleSpring = CreateFixedAngleSpring(body, springConstant, dampningConstant);
physicsSimulator.Add(fixedAngleSpring);
return fixedAngleSpring;
}
示例11: Load
public void Load(Demo demo, PhysicsSimulator physicsSimulator)
{
//use the body factory to create the physics body
borderBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, width, height, 1);
borderBody.IsStatic = true;
borderBody.Position = position;
LoadBorderGeom(physicsSimulator);
float left = (position.X - width / 2f);
float top = (position.Y - height / 2f);
float right = (position.X + width / 2f);
float bottom = (position.Y + height / 2f);
Rectangle leftBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
new Vector2(borderWidth, height));
Demo.PositionTopLeft(leftBorder, new Vector2(left, top));
Rectangle rightBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
new Vector2(borderWidth, height));
Demo.PositionTopLeft(rightBorder, new Vector2(right-borderWidth, top));
Rectangle topBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
new Vector2(width, borderWidth));
Demo.PositionTopLeft(topBorder, new Vector2(left, top));
Rectangle bottomBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
new Vector2(width, borderWidth));
Demo.PositionTopLeft(bottomBorder, new Vector2(left, bottom - borderWidth));
}
示例12: CreateLinearSpring
public LinearSpring CreateLinearSpring(Body body1, Vector2 attachPoint1, Body body2, Vector2 attachPoint2,
float springConstant, float dampingConstant)
{
LinearSpring linearSpring = new LinearSpring(body1, attachPoint1, body2, attachPoint2, springConstant,
dampingConstant);
return linearSpring;
}
示例13: Table
public Table(Vector2 position, float width, float height)
{
Random rand = new Random();
_topBody = BodyFactory.Instance.CreateRectangleBody(width, 10, 6);
_rightLegBody = BodyFactory.Instance.CreateRectangleBody(10, height, 3);
_leftLegBody = BodyFactory.Instance.CreateRectangleBody(10, height, 3);
_topGeom = GeomFactory.Instance.CreateRectangleGeom(_topBody, width, 10);
_rightLegGeom = GeomFactory.Instance.CreateRectangleGeom(_rightLegBody, 10, height);
_leftLegGeom = GeomFactory.Instance.CreateRectangleGeom(_leftLegBody, 10, height);
_topBody.Position = position;
_leftLegBody.Position = new Vector2(position.X - (width / 2) + 10, position.Y + (height / 2) + 5);
_rightLegBody.Position = new Vector2(position.X + (width / 2) - 10, position.Y + (height / 2) + 5);
int group = rand.Next(1, 100);
_rightLegGeom.CollisionGroup = group;
_leftLegGeom.CollisionGroup = group;
_topGeom.CollisionGroup = group;
_rightLegGeom.RestitutionCoefficient = 0;
_leftLegGeom.RestitutionCoefficient = 0;
_topGeom.RestitutionCoefficient = 0;
_height = height;
}
示例14: AnimatedSprite
public AnimatedSprite(Texture2D texture, Body body, int frameWidth, int frameHeight) : base(texture, body)
{
this.frameWidth = frameWidth;
this.frameHeight = frameHeight;
Init();
}
示例15: Load
public void Load(Demo demo, PhysicsSimulator physicsSimulator)
{
agentBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 80, 80, 5);
agentBody.Position = _position;
demo.AddAgentToCanvas(agentBody);
agentGeom = new Geom[7];
agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, agentBody, 16, 10,
new Vector2(-40, -40), 0);
agentGeom[0].RestitutionCoefficient = .4f;
agentGeom[0].FrictionCoefficient = .2f;
agentGeom[0].CollisionGroup = 1;
agentGeom[0].CollisionCategories = collisionCategory;
agentGeom[0].CollidesWith = collidesWith;
agentGeom[1] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
new Vector2(-40, 40), 0);
agentGeom[2] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
new Vector2(40, -40), 0);
agentGeom[3] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
new Vector2(40, 40), 0);
agentGeom[4] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
new Vector2(0, 0),
0);
agentGeom[5] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, agentBody, 16, 120, Vector2.Zero,
MathHelper.PiOver4);
agentGeom[5].CollisionGroup = 1;
agentGeom[5].CollisionCategories = collisionCategory;
agentGeom[5].CollidesWith = collidesWith;
agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, agentBody, 16, 120, Vector2.Zero,
-MathHelper.PiOver4);
agentGeom[6].CollisionGroup = 1;
agentGeom[6].CollisionCategories = collisionCategory;
agentGeom[6].CollidesWith = collidesWith;
}