本文整理汇总了C#中FarseerPhysics.Dynamics.Joints.RevoluteJoint类的典型用法代码示例。如果您正苦于以下问题:C# RevoluteJoint类的具体用法?C# RevoluteJoint怎么用?C# RevoluteJoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RevoluteJoint类属于FarseerPhysics.Dynamics.Joints命名空间,在下文中一共展示了RevoluteJoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HumanoidBody
public HumanoidBody(World world, Vector2 dimensions, object userData)
{
_torsoHeight = dimensions.Y - dimensions.X/2f;
Torso = BodyFactory.CreateRectangle(
world: world,
width: dimensions.X,
height: _torsoHeight,
density: 1f,
position: Vector2.UnitX*20,
userData: userData);
Torso.BodyType = BodyType.Dynamic;
Wheel = BodyFactory.CreateCircle(
world: world,
radius: dimensions.X/2f,
density: 1f,
position: Torso.Position + new Vector2(0, _torsoHeight/2),
userData: userData);
Wheel.BodyType = BodyType.Dynamic;
Wheel.Friction = float.MaxValue;
Wheel.Restitution = float.MinValue;
JointFactory.CreateFixedAngleJoint(world, Torso);
Motor = JointFactory.CreateRevoluteJoint(world, Torso, Wheel, Vector2.Zero);
Motor.MotorEnabled = true;
Motor.MaxMotorTorque = 10;
}
示例2: AttachBodiesWithRevoluteJoint
/// <summary>
/// Attaches the bodies with revolute joints.
/// </summary>
/// <param name="world">The world.</param>
/// <param name="bodies">The bodies.</param>
/// <param name="localAnchorA">The local anchor A.</param>
/// <param name="localAnchorB">The local anchor B.</param>
/// <param name="connectFirstAndLast">if set to <c>true</c> [connect first and last].</param>
/// <param name="collideConnected">if set to <c>true</c> [collide connected].</param>
public static List<RevoluteJoint> AttachBodiesWithRevoluteJoint(World world, List<Body> bodies,
Vector2 localAnchorA,
Vector2 localAnchorB, bool connectFirstAndLast,
bool collideConnected)
{
List<RevoluteJoint> joints = new List<RevoluteJoint>(bodies.Count + 1);
for (int i = 1; i < bodies.Count; i++)
{
RevoluteJoint joint = new RevoluteJoint(bodies[i], bodies[i - 1], localAnchorA, localAnchorB);
joint.CollideConnected = collideConnected;
world.AddJoint(joint);
joints.Add(joint);
}
if (connectFirstAndLast)
{
RevoluteJoint lastjoint = new RevoluteJoint(bodies[0], bodies[bodies.Count - 1], localAnchorA,
localAnchorB);
lastjoint.CollideConnected = collideConnected;
world.AddJoint(lastjoint);
joints.Add(lastjoint);
}
return joints;
}
示例3: CreateRevoluteJoint
/// <summary>
/// Creates a revolute joint and adds it to the world
/// </summary>
/// <param name="world"></param>
/// <param name="bodyA"></param>
/// <param name="bodyB"></param>
/// <param name="anchorB"></param>
/// <returns></returns>
public static RevoluteJoint CreateRevoluteJoint(World world, Body bodyA, Body bodyB, Vector2 anchorB)
{
Vector2 localanchorA = bodyA.GetLocalPoint(bodyB.GetWorldPoint(anchorB));
RevoluteJoint joint = new RevoluteJoint(bodyA, bodyB, localanchorA, anchorB);
world.AddJoint(joint);
return joint;
}
示例4: ChainTest
private ChainTest()
{
//Ground
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
const float y = 25.0f;
Body prevBody = ground;
for (int i = 0; i < 30; ++i)
{
Body body = BodyFactory.CreateRectangle(World, 1.2f, 0.25f, 20, new Vector2(0.5f + i, y));
body.BodyType = BodyType.Dynamic;
body.Friction = 0.2f;
Vector2 anchor = new Vector2(i, y);
RevoluteJoint joint = new RevoluteJoint(prevBody, body, anchor, true);
//The chain is breakable
joint.Breakpoint = 10000f;
World.AddJoint(joint);
prevBody = body;
}
}
}
示例5: CreateRevoluteJoint
public static RevoluteJoint CreateRevoluteJoint( World world, Body bodyA, Body bodyB, Vector2 anchor )
{
var localanchorA = bodyA.getLocalPoint( bodyB.getWorldPoint( anchor ) );
var joint = new RevoluteJoint( bodyA, bodyB, localanchorA, anchor );
world.addJoint( joint );
return joint;
}
示例6: CreatePlayerPhysicsObjects
private void CreatePlayerPhysicsObjects(Vector2 gameWorldPosition)
{
MainFixture = FixtureFactory.CreateRectangle(Engine.Physics.World, 0.5f, 0.5f, 1);
MainFixture.CollisionFilter.CollisionCategories = (Category)(Global.CollisionCategories.Player);
Bodies.Add(MainFixture.Body);
MainFixture.Body.Position = Engine.Physics.PositionToPhysicsWorld(gameWorldPosition);
MainFixture.Body.BodyType = BodyType.Dynamic;
MainFixture.Body.SleepingAllowed = false;
WheelFixture = FixtureFactory.CreateCircle(Engine.Physics.World, 0.3f, 1.0f);
WheelFixture.CollisionFilter.CollisionCategories = (Category)(Global.CollisionCategories.Player);
Bodies.Add(WheelFixture.Body);
WheelFixture.Body.Position = MainFixture.Body.Position + new Vector2(0.0f, 0.6f);
WheelFixture.Body.BodyType = BodyType.Dynamic;
WheelFixture.Body.SleepingAllowed = false;
WheelFixture.Friction = 0.5f;
playerFAJ = JointFactory.CreateFixedAngleJoint(Engine.Physics.World, MainFixture.Body);
playerFAJ.BodyB = WheelFixture.Body;
wheelMotorRevJoint = JointFactory.CreateRevoluteJoint(MainFixture.Body, WheelFixture.Body, Vector2.Zero);
wheelMotorRevJoint.MaxMotorTorque = 10.0f;
wheelMotorRevJoint.MotorEnabled = true;
Engine.Physics.World.AddJoint(wheelMotorRevJoint);
}
示例7: Tumbler
private Tumbler()
{
var ground = BodyFactory.CreateBody(World);
var body = BodyFactory.CreateBody(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 10.0f);
PolygonShape shape = new PolygonShape(5);
shape.SetAsBox(0.5f, 10.0f, new Vector2(10.0f, 0.0f), 0.0f);
body.CreateFixture(shape);
shape.SetAsBox(0.5f, 10.0f, new Vector2(-10.0f, 0.0f), 0.0f);
body.CreateFixture(shape);
shape.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, 10.0f), 0.0f);
body.CreateFixture(shape);
shape.SetAsBox(10.0f, 0.5f, new Vector2(0.0f, -10.0f), 0.0f);
body.CreateFixture(shape);
var jd = new RevoluteJoint(ground, body, new Vector2(0.0f, 10.0f), new Vector2(0.0f, 0.0f));
jd.ReferenceAngle = 0.0f;
jd.MotorSpeed = 0.05f * MathHelper.Pi;
jd.MaxMotorTorque = 1e8f;
jd.MotorEnabled = true;
World.AddJoint(jd);
}
示例8: RopeGrabComponent
public RopeGrabComponent(int entityId, RopeComponent ropeComponent, RevoluteJoint joint, float progress)
{
_entityId = entityId;
_ropeComponent = ropeComponent;
_joint = joint;
_progress = progress;
}
示例9: RopeNode
public RopeNode(Body body, RevoluteJoint joint, float halfLength)
{
_ropeNodeTextures = ropeNodeTextures;
_body = body;
_joint = joint;
_halfLength = halfLength;
}
示例10: CompositePhysicsObject
public CompositePhysicsObject(World world, PhysicsObject physObA, PhysicsObject physObB, Vector2 relativeJointPosition)
{
this.physObA = physObA;
this.physObB = physObB;
revJoint = JointFactory.CreateRevoluteJoint(world, physObA.fixture.Body, physObB.fixture.Body, ConvertUnits.ToSimUnits(relativeJointPosition));
physObA.fixture.IgnoreCollisionWith(physObB.fixture);
physObB.fixture.IgnoreCollisionWith(physObA.fixture);
}
示例11: CharacterComponent
public CharacterComponent(int entityId, Body body, Body feet, RevoluteJoint feetJoint, CharacterClass characterClass)
{
_entityId = entityId;
_body = body;
_feet = feet;
_feetJoint = feetJoint;
_characterClass = characterClass;
}
示例12: RevoluteTest
private RevoluteTest()
{
//Ground
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
Body bodyB = BodyFactory.CreateCircle(World, 0.5f, 5f, new Vector2(-10.0f, 20.0f));
bodyB.BodyType = BodyType.Dynamic;
const float w = 100.0f;
bodyB.AngularVelocity = w;
bodyB.LinearVelocity = new Vector2(-8.0f * w, 0.0f);
_joint = new RevoluteJoint(ground, bodyB, new Vector2(-10.0f, 12.0f), true);
_joint.MotorSpeed = 1.0f * Settings.Pi;
_joint.MaxMotorTorque = 10000.0f;
_joint.MotorEnabled = false;
_joint.LowerLimit = -0.25f * Settings.Pi;
_joint.UpperLimit = 0.5f * Settings.Pi;
_joint.LimitEnabled = true;
_joint.CollideConnected = true;
World.AddJoint(_joint);
}
{
Body ball = BodyFactory.CreateCircle(World, 3.0f, 5.0f, new Vector2(5.0f, 30.0f));
ball.BodyType = BodyType.Dynamic;
ball.CollisionCategories = Category.Cat1;
Vertices polygonVertices = PolygonTools.CreateRectangle(10.0f, 0.2f, new Vector2(-10.0f, 0.0f), 0.0f);
Body polygonBody = BodyFactory.CreatePolygon(World, polygonVertices, 2, new Vector2(20, 10));
polygonBody.BodyType = BodyType.Dynamic;
polygonBody.IsBullet = true;
RevoluteJoint joint = new RevoluteJoint(ground, polygonBody, new Vector2(20, 10), true);
joint.LowerLimit = -0.25f * Settings.Pi;
joint.UpperLimit = 0.0f * Settings.Pi;
joint.LimitEnabled = true;
World.AddJoint(joint);
}
// Tests mass computation of a small object far from the origin
{
Vertices verts = new Vertices(3);
verts.Add(new Vector2(17.63f, 36.31f));
verts.Add(new Vector2(17.52f, 36.69f));
verts.Add(new Vector2(17.19f, 36.36f));
Body polyShape = BodyFactory.CreatePolygon(World, verts, 1);
polyShape.BodyType = BodyType.Dynamic;
}
}
示例13: RevoluteTest
private RevoluteTest()
{
//Ground
var ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
//The big fixed wheel
CircleShape shape = new CircleShape(5.0f, 5);
Body body = BodyFactory.CreateBody(World);
body.Position = new Vector2(-10.0f, 15.0f);
body.BodyType = BodyType.Dynamic;
body.CreateFixture(shape);
_fixedJoint = new FixedRevoluteJoint(body, Vector2.Zero, body.Position);
_fixedJoint.MotorSpeed = 0.25f * Settings.Pi;
_fixedJoint.MaxMotorTorque = 5000.0f;
_fixedJoint.MotorEnabled = true;
World.AddJoint(_fixedJoint);
// The small gear attached to the big one
Body body1 = BodyFactory.CreateGear(World, 1.5f, 10, 0.1f, 1, 1);
body1.Position = new Vector2(-10.0f, 12.0f);
body1.BodyType = BodyType.Dynamic;
_joint = new RevoluteJoint(body, body1, body.GetLocalPoint(body1.Position),
Vector2.Zero);
_joint.MotorSpeed = 1.0f * Settings.Pi;
_joint.MaxMotorTorque = 5000.0f;
_joint.MotorEnabled = true;
_joint.CollideConnected = false;
World.AddJoint(_joint);
CircleShape circle_shape = new CircleShape(3.0f, 5);
var circleBody = BodyFactory.CreateBody(World);
circleBody.Position = new Vector2(5.0f, 30.0f);
circleBody.BodyType = BodyType.Dynamic;
circleBody.CreateFixture(circle_shape);
PolygonShape polygonShape = new PolygonShape(2.0f);
polygonShape.SetAsBox(10.0f, 0.2f, new Vector2(-10.0f, 0.0f), 0.0f);
var polygon_body = BodyFactory.CreateBody(World);
polygon_body.Position = new Vector2(20.0f, 10.0f);
polygon_body.BodyType = BodyType.Dynamic;
polygon_body.IsBullet = true;
polygon_body.CreateFixture(polygonShape);
RevoluteJoint rjd = new RevoluteJoint(ground, polygon_body, new Vector2(20.0f, 10.0f));
rjd.LowerLimit = -0.25f * Settings.Pi;
rjd.UpperLimit = 0.0f;
rjd.LimitEnabled = true;
World.AddJoint(rjd);
}
}
示例14: RopeTest
private RopeTest()
{
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
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, anchor, true);
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);
}
}
示例15: physic_wheel_Initialysed
void physic_wheel_Initialysed(object sender, EventArgs e)
{
var RectangleA2 = BodyFactory.CreateRectangle(physic_wheel.world, 999999f, 999999f, 1.0f);
RectangleA2.BodyType = BodyType.Static;
RectangleA2.Position = new Vector2(0f, 0f);
RectangleA2.Rotation = 0f;
RectangleA2.CollisionCategories = Category.None;
var joint = new RevoluteJoint(physic_wheel.Body, RectangleA2, physic_wheel.physicWorld.UIToPhysic(wheel_cont,
new Point(wheel_cont.RenderSize.Width / 2.0, wheel_cont.RenderSize.Height / 2.0)), true)
{ MotorEnabled = true, MotorSpeed = -0.2f , MaxMotorTorque = 10};
physic_wheel.world.AddJoint(joint);
}