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); }
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)); }
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; }
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; }
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; }
//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); }
public RevoluteJoint CreateRevoluteJoint(PhysicsSimulator physicsSimulator, Body body1, Body body2, Vector2 initialAnchorPosition) { RevoluteJoint revoluteJoint = CreateRevoluteJoint(body1, body2, initialAnchorPosition); physicsSimulator.Add(revoluteJoint); return revoluteJoint; }
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; }
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(); }
public FixedAngleSpring CreateFixedAngleSpring(PhysicsSimulator physicsSimulator, Body body, float springConstant, float dampningConstant) { FixedAngleSpring fixedAngleSpring = CreateFixedAngleSpring(body, springConstant, dampningConstant); physicsSimulator.Add(fixedAngleSpring); return fixedAngleSpring; }
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)); }
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; }
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; }
public AngleJoint CreateAngleJoint(Body body1, Body body2, float softness, float biasFactor) { AngleJoint angleJoint = new AngleJoint(body1, body2); angleJoint.Softness = softness; angleJoint.BiasFactor = biasFactor; return angleJoint; }
public AnimatedSprite(Texture2D texture, Body body, int frameWidth, int frameHeight) : base(texture, body) { this.frameWidth = frameWidth; this.frameHeight = frameHeight; Init(); }
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; }
public override void LoadContent() { _lineBrush.Load(ScreenManager.GraphicsDevice); _rectangleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 32, 32, 2, 0, 0, Color.White, Color.Black); _rectangleBody = BodyFactory.Instance.CreateRectangleBody(32, 32, 1f); //template _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(_rectangleBody, 32, 32); //template _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(PhysicsSimulator); _floor = new Floor(ScreenManager.ScreenWidth, 100, new Vector2(ScreenManager.ScreenCenter.X, ScreenManager.ScreenHeight - 50)); _floor.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _agent = new Agent(ScreenManager.ScreenCenter - new Vector2(320, 300)); _agent.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); base.LoadContent(); }
public FixedLinearSpring CreateFixedLinearSpring(Body body, Vector2 bodyAttachPoint, Vector2 worldAttachPoint, float springConstant, float dampingConstant) { FixedLinearSpring fixedSpring = new FixedLinearSpring(body, bodyAttachPoint, worldAttachPoint, springConstant, dampingConstant); return fixedSpring; }
public void LoadAgent() { _agentTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 16, Color.Gold, Color.Black); _agentOrigin = new Vector2(_agentTexture.Width / 2f, _agentTexture.Height / 2f); _agentCrossBeamTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 16, 120, Color.DarkGray, Color.Black); _agentCrossBeamOrigin = new Vector2(_agentCrossBeamTexture.Width / 2f, _agentCrossBeamTexture.Height / 2f); _agentBody = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 80, 80, 5); _agentBody.Position = new Vector2(ScreenManager.ScreenCenter.X, 110); _agentGeom = new Geom[7]; _agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _agentBody, 16, 10, new Vector2(-40, -40), 0); _agentGeom[0].RestitutionCoefficient = .2f; _agentGeom[0].FrictionCoefficient = .2f; _agentGeom[0].CollisionGroup = 1; _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, 130, Vector2.Zero, MathHelper.PiOver4); _agentGeom[5].CollisionGroup = 1; _agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _agentBody, 16, 130, Vector2.Zero, -MathHelper.PiOver4); _agentGeom[6].CollisionGroup = 1; }
public void LoadAgent() { _agentBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 80, 80, 5); _agentBody.Position = new Vector2(512, 110); _agentGeom = new Geom[7]; _agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _agentBody, 16, 10, new Vector2(-40, -40), 0); _agentGeom[0].RestitutionCoefficient = .2f; _agentGeom[0].FrictionCoefficient = .2f; _agentGeom[0].CollisionGroup = 1; _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, 130, Vector2.Zero, MathHelper.PiOver4); _agentGeom[5].CollisionGroup = 1; _agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _agentBody, 16, 130, Vector2.Zero, -MathHelper.PiOver4); _agentGeom[6].CollisionGroup = 1; controlledBody = _agentBody; AddAgentToCanvas(_agentBody); }
public AgentBrush AddAgentToCanvas(Body body) { AgentBrush agent = new AgentBrush(); agent.Extender.Body = body; Children.Add(agent); drawingList.Add(agent); return agent; }
public void load(ContentManager Content) { Vector2 origin; texture = Content.Load<Texture2D>(textureName); body = BodyFactory.Instance.CreateBody(1f, 1f); geom = GeomFactory.Instance.CreateRectangleGeom(body, texture.Width, texture.Height); geom.Tag = _id; }
void ItemBase.InitSelf() { X = 200; Y = 100; body = BodyFactory.Instance.CreateRectangleBody(PhysicsSys.Instance.PhysicsSimulator,100.0f, 100.0f,100.0f); body.Position = new Vector2(X, Y); geom = GeomFactory.Instance.CreateRectangleGeom(PhysicsSys.Instance.PhysicsSimulator, body, 100, 100); }
public Planet(PhysicsSimulator sim, Texture2D tex, Vector2 pos, float size, float mass) { body = BodyFactory.Instance.CreateCircleBody(sim, size, mass); geometry = GeomFactory.Instance.CreateCircleGeom(body, size, 64); body.Position = pos; geometry.RestitutionCoefficient = 0.2f; geometry.FrictionCoefficient = 0.9f; texture = tex; }
public BodyVisualHelper(FrameworkElement visual, Body body) { this.visual = visual; this.body = body; //update when moves/rotates or resized body.Updated += delegate { Update(); }; visual.SizeChanged += delegate { Update(); }; }
public FixedLinearSpring CreateFixedLinearSpring(PhysicsSimulator physicsSimulator, Body body, Vector2 bodyAttachPoint, Vector2 worldAttachPoint, float springConstant, float dampingConstant) { FixedLinearSpring fixedSpring = CreateFixedLinearSpring(body, bodyAttachPoint, worldAttachPoint, springConstant, dampingConstant); physicsSimulator.Add(fixedSpring); return fixedSpring; }
public Sprite() { position = new Vector2(0.0f, 0.0f); rotation = 0.0f; origin = new Vector2(0.0f, 0.0f); currentTexture = null; body = null; geom = null; }
public LinearSpring CreateLinearSpring(PhysicsSimulator physicsSimulator, Body body1, Vector2 attachPoint1, Body body2, Vector2 attachPoint2, float springConstant, float dampingConstant) { LinearSpring linearSpring = CreateLinearSpring(body1, attachPoint1, body2, attachPoint2, springConstant, dampingConstant); physicsSimulator.Add(linearSpring); return linearSpring; }
public CircleBrush AddCircleToCanvas(Body body, float radius) { CircleBrush circle = new CircleBrush(); circle.Radius = radius; circle.Extender.Body = body; Children.Add(circle); drawingList.Add(circle); return circle; }
/// <exception cref="InvalidOperationException">Fixed joints cannot be created on static bodies</exception> public FixedRevoluteJoint CreateFixedRevoluteJoint(Body body, Vector2 anchor) { FixedRevoluteJoint revoluteJoint = new FixedRevoluteJoint(body, anchor); if (body.isStatic) { //throw new InvalidOperationException("Fixed joints cannot be created on static bodies"); revoluteJoint.Enabled = false; // if you create a joint of a static body it is created as disabled. } return revoluteJoint; }