public InfoBody AddVert(float x, float y, Vec2[] vert, float angle, float density, float friction, float restetution, Bitmap image, Object userDate = null) { float max_w = vert[0].X; float max_h = vert[0].Y; for (int i = 0; i < vert.Length; i++) { if (vert[i].X > max_w) { max_w = vert[i].X; } if (vert[i].Y > max_h) { max_h = vert[i].Y; } vert[i].X /= 2; vert[i].Y /= 2; vert[i].X /= metric; vert[i].Y /= metric; } GImage g_image = new GImage(game); g_image.SetImage(image); g_image.SetWidth(max_w); g_image.SetHeight(max_h); BodyDef bDef = new BodyDef(); bDef.Position.Set(x / metric, y / metric); bDef.Angle = angle; PolygonDef pDef = new PolygonDef(); pDef.Restitution = restetution; pDef.Friction = friction; pDef.Density = density; pDef.SetAsBox(max_w / metric / 2, max_h / metric / 2); pDef.Vertices = vert; Body body = world.CreateBody(bDef); body.CreateShape(pDef); body.SetMassFromShapes(); InfoBody info = new InfoBody(); info.image = g_image; info.body = body; info.userDate = userDate; body.SetUserData(info); return(info); }
public InfoBody AddVert(float x, float y, Vec2[] vert, float angle, float density, float friction, float restetution, float mass, GImage image, bool IsBullet = true, bool IsSensor = false, bool AllowSleep = false, short group_index = 1, Object userDate = null) { for (int i = 0; i < vert.Length; i++) { vert[i].X /= 2; vert[i].Y /= 2; vert[i].X /= metric; vert[i].Y /= metric; } BodyDef bDef = new BodyDef(); bDef.Position.Set(x / metric, y / metric); bDef.Angle = angle; bDef.AllowSleep = AllowSleep; bDef.IsBullet = IsBullet; PolygonDef pDef = new PolygonDef(); pDef.Restitution = restetution; pDef.Friction = friction; pDef.Density = density; pDef.SetAsBox(image.GetWidth() / metric / 2, image.GetHeight() / metric / 2); pDef.Vertices = vert; pDef.Filter.GroupIndex = group_index; pDef.IsSensor = IsSensor; Body body = world.CreateBody(bDef); body.CreateShape(pDef); body.SetMassFromShapes(); float Inertia = body.GetInertia(); MassData md = new MassData(); md.I = Inertia; md.Mass = mass; body.SetMass(md); InfoBody info = new InfoBody(); info.image = image; info.body = body; info.userDate = userDate; body.SetUserData(info); return(info); }
public void Draw() { for (Body list = world.GetBodyList(); list != null; list = list.GetNext()) { InfoBody info = (InfoBody)list.GetUserData(); if (info != null) { info.image.SetX(list.GetPosition().X *metric); info.image.SetY(list.GetPosition().Y *metric); info.image.SetAndle(list.GetAngle()); info.image.Draw(); } } }
public InfoBody AddCircle(float x, float y, float radius, float angle, float density, float friction, float restetution, float mass, GImage image, bool IsBullet = true, bool IsSensor = false, bool AllowSleep = false, short group_index = 1, Object userDate = null) { BodyDef bDef = new BodyDef(); bDef.Position.Set(x / metric, y / metric); bDef.Angle = angle; bDef.AllowSleep = AllowSleep; bDef.IsBullet = IsBullet; CircleDef pDef = new CircleDef(); pDef.Restitution = restetution; pDef.Friction = friction; pDef.Density = density; pDef.Radius = radius / metric; pDef.Filter.GroupIndex = group_index; pDef.IsSensor = IsSensor; Body body = world.CreateBody(bDef); body.CreateShape(pDef); body.SetMassFromShapes(); float Inertia = body.GetInertia(); MassData md = new MassData(); md.I = Inertia; md.Mass = mass; body.SetMass(md); InfoBody info = new InfoBody(); info.image = image; info.body = body; info.userDate = userDate; body.SetUserData(info); return(info); }
public InfoBody AddCircle(float x, float y, float radius, float angle, float density, float friction, float restetution, float mass, GImage image, Object userDate = null) { BodyDef bDef = new BodyDef(); bDef.Position.Set(x / metric, y / metric); bDef.Angle = angle; CircleDef pDef = new CircleDef(); pDef.Restitution = restetution; pDef.Friction = friction; pDef.Density = density; pDef.Radius = radius / metric; Body body = world.CreateBody(bDef); body.CreateShape(pDef); body.SetMassFromShapes(); float Inertia = body.GetInertia(); MassData md = new MassData(); md.I = Inertia; md.Mass = mass; body.SetMass(md); InfoBody info = new InfoBody(); info.image = image; info.body = body; info.userDate = userDate; body.SetUserData(info); return(info); }
public InfoBody AddRect(float x, float y, float w, float h, float angle, float density, float friction, float restetution, Bitmap image, Object userDate = null) { GImage g_image = new GImage(game); g_image.SetImage(image); g_image.SetWidth(w); g_image.SetHeight(h); BodyDef bDef = new BodyDef(); bDef.Position.Set(x / metric, y / metric); bDef.Angle = angle; PolygonDef pDef = new PolygonDef(); pDef.Restitution = restetution; pDef.Friction = friction; pDef.Density = density; pDef.SetAsBox(w / metric / 2, h / metric / 2); Body body = world.CreateBody(bDef); body.CreateShape(pDef); body.SetMassFromShapes(); InfoBody info = new InfoBody(); info.image = g_image; info.body = body; info.userDate = userDate; body.SetUserData(info); return(info); }
public InfoBody AddCircle(float x, float y, float radius, float angle, float density, float friction, float restetution, Bitmap image, Object userDate = null) { GImage g_image = new GImage(game); g_image.SetImage(image); g_image.SetWidth(radius * 2); g_image.SetHeight(radius * 2); BodyDef bDef = new BodyDef(); bDef.Position.Set(x / metric, y / metric); bDef.Angle = angle; CircleDef pDef = new CircleDef(); pDef.Restitution = restetution; pDef.Friction = friction; pDef.Density = density; pDef.Radius = radius / metric; Body body = world.CreateBody(bDef); body.CreateShape(pDef); body.SetMassFromShapes(); InfoBody info = new InfoBody(); info.image = g_image; info.body = body; info.userDate = userDate; body.SetUserData(info); return(info); }