public override JabActor CreateBox(Vector2 dim, Vector2 pos, JabActor.BodyType bodytype) { try { dim /= 100; FarActor actor = new FarActor(); actor.body = new Body(world);// world.CreateBody(); actor.body.UserData = actor; Vector2 center = new Vector2(-dim.X, -dim.Y) / 2.0f; Vertices box = PolygonTools.CreateRectangle(dim.X / 2.0f, dim.Y / 2.0f, center, 0); for (int i = 0; i < box.Count(); i++) { Vector2 vert = box[i]; vert.X += dim.X / 2.0f; vert.Y += dim.Y / 2.0f; box[i] = vert; vert = box[i]; } PolygonShape shape = new PolygonShape(box, 1.0f); actor.BodyState = bodytype; actor.body.CreateFixture(shape, 1.0f); actor.Position = pos; actor.Width = dim.X * 100; actor.Height = dim.Y * 100; actors.Add(actor); return(actor); } catch (Exception e) { return(null); } }
public override JabActor CreateSphere(float radius, Vector2 pos, JabActor.BodyType bodytype) { try { radius /= 100; FarActor actor = new FarActor(); actor.body = new Body(world);// world.CreateBody(); actor.body.UserData = actor; Vector2 center = new Vector2(-radius, -radius) / 2.0f; // FarseerPhysics.Settings.MaxPolygonVertices = 33; Vertices sphere = PolygonTools.CreateCircle(radius, 32); PolygonShape shape = new PolygonShape(sphere, 1.0f); actor.BodyState = bodytype; actor.body.CreateFixture(shape, 1.0f); actor.Position = pos; actor.Width = radius; actor.Height = radius; actors.Add(actor); return(actor); } catch (Exception e) { return(null); } }
FarseerPhysics.Dynamics.BodyType GetBodyType(JabActor.BodyType type) { switch (type) { case BodyType.DYNAMIC: return(FarseerPhysics.Dynamics.BodyType.Dynamic); case BodyType.STATIC: return(FarseerPhysics.Dynamics.BodyType.Kinematic); } //System.Windows.MessageBox.Show("ERROR: Body type provided invalid for FarWorld"); return(FarseerPhysics.Dynamics.BodyType.Static); }
public PhysicSprite(Vector2 dim, Vector2 pos, bool dynamic, JabWorld world, string imagedir) : base() { TextureDir = imagedir; Width = dim.X; Height = dim.Y; JabActor.BodyType type = JabActor.BodyType.DYNAMIC; if (!dynamic) { type = JabActor.BodyType.STATIC; } body = world.CreateBox(dim, pos, type); body.UserData = this; this.world = world; DoDimensions = true; DoHandle = true; }
public PhysicSprite(float radius, Vector2 pos, bool dynamic, JabWorld world, string imagedir) : base() { TextureDir = imagedir; Width = radius; Height = radius; JabActor.BodyType type = JabActor.BodyType.DYNAMIC; if (!dynamic) { type = JabActor.BodyType.STATIC; } body = world.CreateSphere(radius / 2.0f, pos, type); body.UserData = this; this.world = world; // Initialize(); }
public abstract JabActor CreateFromTriangles(List <Vector2> triangles, Vector2 pos, JabActor.BodyType bodytype);
public abstract JabActor CreateSphere(float radius, Vector2 pos, JabActor.BodyType bodytype);
public abstract JabActor CreateBox(Vector2 dim, Vector2 pos, JabActor.BodyType bodytype);
public PhysicShape(JabWorld world, JabActor.BodyType bodytype) : base() { this.bodyType = bodytype; this.world = world; }
public override JabActor CreateFromTriangles(List <Vector2> triangles, Vector2 pos, JabActor.BodyType bodytype) { try { FarActor actor = new FarActor(); actor.body = new Body(world);// world.CreateBody(); actor.body.UserData = actor; //FarseerPhysics.Settings.MaxPolygonVertices = 33; for (int i = 0; i < triangles.Count; i++) { Vector2[] tri = new Vector2[3]; tri[0] = triangles[i] / 100.0f; ++i; tri[1] = triangles[i] / 100.0f; ++i; tri[2] = triangles[i] / 100.0f; Vertices vertices = new Vertices(tri); PolygonShape shape = new PolygonShape(vertices, 1.0f); actor.body.CreateFixture(shape, 1.0f); } actor.BodyState = bodytype; actor.Position = pos; actors.Add(actor); return(actor); } catch (Exception e) { //System.Windows.MessageBox.Show(e.ToString()); } return(null); }
public PhysicShape(JabWorld world, JabActor.BodyType bodytype) : base() { this.bodyType = bodytype; this.world = world; }
public List <JabActor> CreateBodies(XElement elements) { List <JabActor> bodies = new List <JabActor>(); var items = elements.Descendants("Items"); var element = elements.Descendants("CustomProperties").Descendants("Property"); float layerDepth = 0; float mass = 0.25f; string type = ""; float friction = 0.5f; float density = 15.0f; float restitution = 0; bool dynamic = true; float angulardamping = 0; foreach (var property in element) { if (property.Attribute("Name") != null) { string name = property.Attribute("Name").Value; if (name == "LayerDepth") { layerDepth = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture); } else if (name == "Mass") { mass = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture); } else if (name == "Friction") { friction = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture); } else if (name == "Type") { type = property.Descendants("string").First <XElement>().Value; } else if (name == "Density") { density = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture); } else if (name == "Restitution") { restitution = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture); } else if (name == "Dynamic") { dynamic = property.Descendants("string").First <XElement>().Value.ToLowerInvariant() == "true"; } else if (name == "AngularDamping") { angulardamping = float.Parse(property.Descendants("string").First <XElement>().Value, CultureInfo.InvariantCulture); } } } List <Sprite> baseSprites = CreateSprites(elements); for (int i = 0; i < baseSprites.Count; i++) { Sprite s = baseSprites[i]; float posx = s.PosX; float posy = s.PosY; float rot = s.Rot; float width = s.ScaleX * s.Width; float height = s.ScaleY * s.Height; JabActor.BodyType bodyState = JabActor.BodyType.DYNAMIC; JabActor actor = null; if (!dynamic) { bodyState = JabActor.BodyType.STATIC; } if (type == "Circle") { actor = world.CreateSphere(width, new Vector2(posx, posy), bodyState); } else { actor = world.CreateBox(new Vector2(width, height), new Vector2(posx, posy), bodyState); } actor.Friction = friction; actor.Mass = mass; actor.Restitution = restitution; actor.Mass = mass; actor.Rot = rot; actor.Friction = friction; actor.PosZ = layerDepth; actor.Restitution = restitution; actor.Density = density; actor.AngularDamping = angulardamping; bodies.Add(actor); } return(bodies); }