The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Farseer Chains
Posted by: Daniel | September 6, 2009 @ 7:55am
C# Code
[
Download
]
//Here is the code i use for calling the rope into existance... LeftRopeLinks = ComplexFactory.Instance.CreateChain(g_Game.GET.physicsSimulator, Body.Position, TargetPos, 30, 10, 0.5f, true, false, LinkType.RevoluteJoint, Body, true, 3f); LeftRopeLinks.CreateGeoms(CollisionCategory.Cat10, CollisionCategory.Cat1, g_Game.GET.physicsSimulator); //Here is the modified Createchain class (im using revolute joints) it creates the chain and then shoots it out like a grappiling hook public Path CreateChain(PhysicsSimulator physicsSimulator, Vector2 start, Vector2 end, float width, float height, float mass, bool pinStart, bool pinEnd, LinkType type, Body FirstObject, bool SpitOut, float PullUpPower) { float PullPowerMulti = 180000; float LinkBias = 0.1f; float LinkSoftness = 2.5f; Path path; if (type == LinkType.PinJoint) { PullPowerMulti = 600000; LinkBias = 0.2f; LinkSoftness = 0.4f; path = new Path(width, height, width / PullUpPower * 2, mass, false); } else if (type == LinkType.SliderJoint) { PullPowerMulti = 300000; LinkBias = 0.05f; LinkSoftness = 0.4f; path = new Path(width, height, width / PullUpPower, mass, false); } else { path = new Path(width, height, width / PullUpPower, mass, false); } path.Add(start); path.Add(Path.FindMidpoint(start, end)); path.Add(end); path.Update(); path.LinkBodies(type, Min, Max, SpringConstant, DampingConstant); Vector2 Offset = start - end; float Angle = (float)Math.Atan2(Offset.Y, Offset.X); for (int i = 0; i < path.Bodies.Count; i++) { path.Bodies[i].position = start; path.Bodies[i].ApplyForce(GetOffset(Angle + MathHelper.PiOver2, (i * i * i * (PullPowerMulti / (path.Bodies.Count * path.Bodies.Count * path.Bodies.Count))) + 1)); } if (pinStart) path.Add(JointFactory.Instance.CreateRevoluteJoint(path.Bodies[0], FirstObject, start - new Vector2(0, -0))); if (pinEnd) path.Add(JointFactory.Instance.CreateFixedRevoluteJoint(path.Bodies[path.Bodies.Count - 1], path.ControlPoints[2])); foreach (Joint j in path.Joints) { j.BiasFactor = LinkBias; j.Softness = LinkSoftness; } path.AddToPhysicsSimulator(physicsSimulator); return (path); } // Here is my create geom function public void CreateGeoms(CollisionCategory collisionCategory, CollisionCategory collidesWith, PhysicsSimulator physicsSimulator) { _BodyLength = _bodies.Count; for (int i = 0; i < _BodyLength; i++) { //TODO: Cache this value. RopeLinkVerts = Vertices.CreateSimpleRectangle(_width, _height); _geoms.Add(new Geom(_bodies[i], RopeLinkVerts, Vector2.Zero, 0, 0)); _geoms[i].CollisionCategories = collisionCategory; _geoms[i].CollidesWith = collidesWith; physicsSimulator.Add(_geoms[i]); } }
Syntax Highlighting
[
Open in new window
]
Author Comments
Chain Code
Rating
4.28 / 8
80 Votes