本文整理汇总了C#中Box2D.Collision.Shapes.b2EdgeShape类的典型用法代码示例。如果您正苦于以下问题:C# b2EdgeShape类的具体用法?C# b2EdgeShape怎么用?C# b2EdgeShape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
b2EdgeShape类属于Box2D.Collision.Shapes命名空间,在下文中一共展示了b2EdgeShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VaryingRestitution
public VaryingRestitution()
{
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
{
b2CircleShape shape = new b2CircleShape();
shape.Radius = 1.0f;
b2FixtureDef fd = new b2FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
float[] restitution = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f};
for (int i = 0; i < 7; ++i)
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(-10.0f + 3.0f * i, 20.0f);
b2Body body = m_world.CreateBody(bd);
fd.restitution = restitution[i];
body.CreateFixture(fd);
}
}
}
示例2: Breakable
public Breakable()
{
// Ground body
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
// Breakable dynamic body
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position = new b2Vec2(0.0f, 40.0f);
bd.angle = 0.25f * b2Settings.b2_pi;
m_body1 = m_world.CreateBody(bd);
m_shape1.SetAsBox(0.5f, 0.5f, new b2Vec2(-0.5f, 0.0f), 0.0f);
m_piece1 = m_body1.CreateFixture(m_shape1, 1.0f);
m_shape2.SetAsBox(0.5f, 0.5f, new b2Vec2(0.5f, 0.0f), 0.0f);
m_piece2 = m_body1.CreateFixture(m_shape2, 1.0f);
}
m_break = false;
m_broke = false;
}
示例3: SphereStack
public SphereStack()
{
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
{
b2CircleShape shape = new b2CircleShape();
shape.Radius = 1.0f;
for (int i = 0; i < e_count; ++i)
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(0.0f, 4.0f + 3.0f * i);
m_bodies[i] = m_world.CreateBody(bd);
m_bodies[i].CreateFixture(shape, 1.0f);
m_bodies[i].LinearVelocity = new b2Vec2(0.0f, -50.0f);
}
}
}
示例4: InitPhysics
void InitPhysics()
{
var gravity = new b2Vec2(0.0f, -10.0f);
world = new b2World(gravity);
world.SetAllowSleeping(true);
world.SetContinuousPhysics(true);
var def = new b2BodyDef();
def.allowSleep = true;
def.position = b2Vec2.Zero;
def.type = b2BodyType.b2_staticBody;
b2Body groundBody = world.CreateBody(def);
groundBody.SetActive(true);
b2EdgeShape groundBox = new b2EdgeShape();
groundBox.Set(b2Vec2.Zero, new b2Vec2(900, 100));
b2FixtureDef fd = new b2FixtureDef();
fd.friction = 0.3f;
fd.restitution = 0.1f;
fd.shape = groundBox;
groundBody.CreateFixture(fd);
}
示例5: b2EdgeShape
public b2EdgeShape(b2EdgeShape e)
: base((b2Shape)e)
{
m_vertex1 = e.m_vertex1;
m_vertex2 = e.m_vertex2;
m_vertex3 = e.m_vertex3;
m_vertex0 = e.m_vertex0;
m_hasVertex0 = e.m_hasVertex0;
m_hasVertex3 = e.m_hasVertex3;
}
示例6: b2EdgeShape
public b2EdgeShape(b2EdgeShape e)
: base((b2Shape)e)
{
Vertex1 = e.Vertex1;
Vertex2 = e.Vertex2;
Vertex3 = e.Vertex3;
Vertex0 = e.Vertex0;
HasVertex0 = e.HasVertex0;
HasVertex3 = e.HasVertex3;
}
示例7: ContinuousTest
public ContinuousTest()
{
{
b2BodyDef bd = new b2BodyDef();
bd.position.Set(0.0f, 0.0f);
b2Body body = m_world.CreateBody(bd);
b2EdgeShape edge = new b2EdgeShape();
edge.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(10.0f, 0.0f));
body.CreateFixture(edge, 0.0f);
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(0.2f, 1.0f, new b2Vec2(0.5f, 1.0f), 0.0f);
body.CreateFixture(shape, 0.0f);
}
#if true
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(0.0f, 20.0f);
//bd.angle = 0.1f;
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(2.0f, 0.1f);
m_body = m_world.CreateBody(bd);
m_body.CreateFixture(shape, 1.0f);
m_angularVelocity = Rand.RandomFloat(-50.0f, 50.0f);
//m_angularVelocity = 46.661274f;
m_body.LinearVelocity = new b2Vec2(0.0f, -100.0f);
m_body.AngularVelocity = m_angularVelocity;
}
#else
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(0.0f, 2.0f);
b2Body body = m_world.CreateBody(bd);
b2CircleShape shape = new b2CircleShape();
shape.Position = b2Vec2.Zero;
shape.Radius = 0.5f;
body.CreateFixture(shape, 1.0f);
bd.bullet = true;
bd.position.Set(0.0f, 10.0f);
body = m_world.CreateBody(bd);
body.CreateFixture(shape, 1.0f);
body.LinearVelocity = new b2Vec2(0.0f, -100.0f);
}
#endif
}
示例8: Pulleys
public Pulleys()
{
float y = 16.0f;
float L = 12.0f;
float a = 1.0f;
float b = 2.0f;
b2Body ground = null;
{
b2BodyDef bd = new b2BodyDef();
ground = m_world.CreateBody(bd);
b2EdgeShape edge = new b2EdgeShape();
edge.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
//ground->CreateFixture(&shape, 0.0f);
b2CircleShape circle = new b2CircleShape();
circle.Radius = 2.0f;
circle.Position = new b2Vec2(-10.0f, y + b + L);
ground.CreateFixture(circle, 0.0f);
circle.Position = new b2Vec2(10.0f, y + b + L);
ground.CreateFixture(circle, 0.0f);
}
{
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(a, b);
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
//bd.fixedRotation = true;
bd.position.Set(-10.0f, y);
b2Body body1 = m_world.CreateBody(bd);
body1.CreateFixture(shape, 5.0f);
bd.position.Set(10.0f, y);
b2Body body2 = m_world.CreateBody(bd);
body2.CreateFixture(shape, 5.0f);
b2PulleyJointDef pulleyDef = new b2PulleyJointDef();
b2Vec2 anchor1 = new b2Vec2(-10.0f, y + b);
b2Vec2 anchor2 = new b2Vec2(10.0f, y + b);
b2Vec2 groundAnchor1 = new b2Vec2(-10.0f, y + b + L);
b2Vec2 groundAnchor2 = new b2Vec2(10.0f, y + b + L);
pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 1.5f);
m_joint1 = (b2PulleyJoint) m_world.CreateJoint(pulleyDef);
}
}
示例9: SensorTest
public SensorTest()
{
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
{
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
#if false
{
b2FixtureDef sd = new b2FixtureDef();
sd.SetAsBox(10.0f, 2.0f, new b2Vec2(0.0f, 20.0f), 0.0f);
sd.isSensor = true;
m_sensor = ground.CreateFixture(sd);
}
#else
{
b2CircleShape shape = new b2CircleShape();
shape.Radius = 5.0f;
shape.Position = new b2Vec2(0.0f, 10.0f);
b2FixtureDef fd = new b2FixtureDef();
fd.shape = shape;
fd.isSensor = true;
m_sensor = ground.CreateFixture(fd);
}
#endif
}
{
b2CircleShape shape = new b2CircleShape();
shape.Radius = 1.0f;
for (int i = 0; i < e_count; ++i)
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(-10.0f + 3.0f * i, 20.0f);
bd.userData = i; // m_touching[i];
m_touching[i] = false;
m_bodies[i] = m_world.CreateBody(bd);
m_bodies[i].CreateFixture(shape, 1.0f);
}
}
}
示例10: Confined
public Confined()
{
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
// Floor
shape.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(10.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
// Left wall
shape.Set(new b2Vec2(-10.0f, 0.0f), new b2Vec2(-10.0f, 20.0f));
ground.CreateFixture(shape, 0.0f);
// Right wall
shape.Set(new b2Vec2(10.0f, 0.0f), new b2Vec2(10.0f, 20.0f));
ground.CreateFixture(shape, 0.0f);
// Roof
shape.Set(new b2Vec2(-10.0f, 20.0f), new b2Vec2(10.0f, 20.0f));
ground.CreateFixture(shape, 0.0f);
}
float radius = 0.5f;
b2CircleShape shape1 = new b2CircleShape();
shape1.Position = b2Vec2.Zero;
shape1.Radius = radius;
b2FixtureDef fd = new b2FixtureDef();
fd.shape = shape1;
fd.density = 1.0f;
fd.friction = 0.1f;
for (int j = 0; j < e_columnCount; ++j)
{
for (int i = 0; i < e_rowCount; ++i)
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(-10.0f + (2.1f * j + 1.0f + 0.01f * i) * radius, (2.0f * i + 1.0f) * radius);
b2Body body = m_world.CreateBody(bd);
body.CreateFixture(fd);
}
}
m_world.Gravity = new b2Vec2(0.0f, 0.0f);
}
示例11: VerticalStack
//public const int e_columnCount = 1;
//public const int e_rowCount = 1;
public VerticalStack()
{
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
shape.Set(new b2Vec2(20.0f, 0.0f), new b2Vec2(20.0f, 20.0f));
ground.CreateFixture(shape, 0.0f);
}
float[] xs = {0.0f, -10.0f, -5.0f, 5.0f, 10.0f};
for (int j = 0; j < e_columnCount; ++j)
{
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(0.5f, 0.5f);
b2FixtureDef fd = new b2FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.3f;
for (int i = 0; i < e_rowCount; ++i)
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
int n = j * e_rowCount + i;
Debug.Assert(n < e_rowCount * e_columnCount);
m_indices[n] = n;
bd.userData = m_indices[n];
float x = 0.0f;
//float32 x = RandomFloat(-0.02f, 0.02f);
//float32 x = i % 2 == 0 ? -0.025f : 0.025f;
bd.position.Set(xs[j] + x, 0.752f + 1.54f * i);
b2Body body = m_world.CreateBody(bd);
m_bodies[n] = body;
body.CreateFixture(fd);
}
}
m_bullet = null;
}
示例12: Prismatic
public Prismatic()
{
b2Body ground = null;
{
b2BodyDef bd = new b2BodyDef();
ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
{
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(2.0f, 0.5f);
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(-10.0f, 10.0f);
bd.angle = 0.5f * b2Settings.b2_pi;
bd.allowSleep = false;
b2Body body = m_world.CreateBody(bd);
body.CreateFixture(shape, 5.0f);
b2PrismaticJointDef pjd = new b2PrismaticJointDef();
// Bouncy limit
b2Vec2 axis = new b2Vec2(2.0f, 1.0f);
axis.Normalize();
pjd.Initialize(ground, body, new b2Vec2(0.0f, 0.0f), axis);
// Non-bouncy limit
//pjd.Initialize(ground, body, b2Vec2(-10.0f, 10.0f), b2Vec2(1.0f, 0.0f));
pjd.motorSpeed = 10.0f;
pjd.maxMotorForce = 10000.0f;
pjd.enableMotor = true;
pjd.lowerTranslation = 0.0f;
pjd.upperTranslation = 20.0f;
pjd.enableLimit = true;
m_joint = (b2PrismaticJoint) m_world.CreateJoint(pjd);
}
}
示例13: OneSidedPlatform
public OneSidedPlatform()
{
// Ground
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-20.0f, 0.0f), new b2Vec2(20.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
// Platform
{
b2BodyDef bd = new b2BodyDef();
bd.position.Set(0.0f, 10.0f);
b2Body body = m_world.CreateBody(bd);
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(3.0f, 0.5f);
m_platform = body.CreateFixture(shape, 0.0f);
m_bottom = 10.0f - 0.5f;
m_top = 10.0f + 0.5f;
}
// Actor
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(0.0f, 12.0f);
b2Body body = m_world.CreateBody(bd);
m_radius = 0.5f;
b2CircleShape shape = new b2CircleShape();
shape.Radius = m_radius;
m_character = body.CreateFixture(shape, 20.0f);
body.LinearVelocity = new b2Vec2(0.0f, -50.0f);
m_state = State.e_unknown;
}
}
示例14: Chain
public Chain()
{
b2Body ground = null;
{
b2BodyDef bd = new b2BodyDef();
ground = m_world.CreateBody(bd);
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
}
{
b2PolygonShape shape = new b2PolygonShape();
shape.SetAsBox(0.6f, 0.125f);
b2FixtureDef fd = new b2FixtureDef();
fd.shape = shape;
fd.density = 20.0f;
fd.friction = 0.2f;
b2RevoluteJointDef jd = new b2RevoluteJointDef();
jd.CollideConnected = false;
const float y = 25.0f;
b2Body prevBody = ground;
for (int i = 0; i < 30; ++i)
{
b2BodyDef bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(0.5f + i, y);
b2Body body = m_world.CreateBody(bd);
body.CreateFixture(fd);
b2Vec2 anchor = new b2Vec2(i, y);
jd.Initialize(prevBody, body, anchor);
m_world.CreateJoint(jd);
prevBody = body;
}
}
}
示例15: CircleBenchmarkTest
public CircleBenchmarkTest()
{
b2BodyDef bd = new b2BodyDef();
b2Body ground = m_world.CreateBody(bd);
// Floor
b2EdgeShape shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(40.0f, 0.0f));
ground.CreateFixture(shape, 0.0f);
// Left wall
shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 0.0f), new b2Vec2(-40.0f, 45.0f));
ground.CreateFixture(shape, 0.0f);
// Right wall
shape = new b2EdgeShape();
shape.Set(new b2Vec2(40.0f, 0.0f), new b2Vec2(40.0f, 45.0f));
ground.CreateFixture(shape, 0.0f);
// Roof
shape = new b2EdgeShape();
shape.Set(new b2Vec2(-40.0f, 45.0f), new b2Vec2(40.0f, 45.0f));
ground.CreateFixture(shape, 0.0f);
var sphere = new b2CircleShape();
sphere.Radius = 1.0f;
for (int i = 0; i < XCount; i++)
{
for (int j = 0; j < YCount; ++j)
{
bd = new b2BodyDef();
bd.type = b2BodyType.b2_dynamicBody;
bd.position.Set(-38f + 2.1f * i, 2.0f + 2.0f * j);
var body = m_world.CreateBody(bd);
body.CreateFixture(sphere, 1.0f);
}
}
}