本文整理汇总了C#中Box2D.Common.b2Vec2类的典型用法代码示例。如果您正苦于以下问题:C# b2Vec2类的具体用法?C# b2Vec2怎么用?C# b2Vec2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
b2Vec2类属于Box2D.Common命名空间,在下文中一共展示了b2Vec2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Set
public virtual void Set(b2Vec2 v1, b2Vec2 v2)
{
Vertex1 = v1;
Vertex2 = v2;
HasVertex0 = false;
HasVertex3 = false;
}
示例3: Draw
protected override void Draw(Settings settings)
{
base.Draw(settings);
b2Manifold manifold = new b2Manifold();
b2Collision.b2CollidePolygons(manifold, m_polygonA, ref m_transformA, m_polygonB, ref m_transformB);
b2WorldManifold worldManifold = new b2WorldManifold();
worldManifold.Initialize(manifold, ref m_transformA, m_polygonA.Radius, ref m_transformB, m_polygonB.Radius);
m_debugDraw.DrawString(5, m_textLine, "point count = {0}", manifold.pointCount);
m_textLine += 15;
{
b2Color color = new b2Color(0.9f, 0.9f, 0.9f);
b2Vec2[] v = new b2Vec2[b2Settings.b2_maxPolygonVertices];
for (int i = 0; i < m_polygonA.VertexCount; ++i)
{
v[i] = b2Math.b2Mul(m_transformA, m_polygonA.Vertices[i]);
}
m_debugDraw.DrawPolygon(v, m_polygonA.VertexCount, color);
for (int i = 0; i < m_polygonB.VertexCount; ++i)
{
v[i] = b2Math.b2Mul(m_transformB, m_polygonB.Vertices[i]);
}
m_debugDraw.DrawPolygon(v, m_polygonB.VertexCount, color);
}
for (int i = 0; i < manifold.pointCount; ++i)
{
m_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, new b2Color(0.9f, 0.3f, 0.3f));
}
}
示例4: JumpPad
public JumpPad(b2Vec2 JumpImpuls, CCPoint Position, b2World gameWorld)
{
this.Texture = new CCTexture2D ("jumppad");
this.Scale = SpriteScale;
this.Position = Position;
this.IsAntialiased = false;
jumpImpuls = JumpImpuls;
totalJumps = 0;
//box2d
b2BodyDef jumpPadDef = new b2BodyDef ();
jumpPadDef.type = b2BodyType.b2_kinematicBody;
jumpPadDef.position = new b2Vec2 ((Position.X + this.ScaledContentSize.Width/2)/PhysicsHandler.pixelPerMeter, (Position.Y + this.ScaledContentSize.Height/4) / PhysicsHandler.pixelPerMeter);
JumpPadBody = gameWorld.CreateBody (jumpPadDef);
b2PolygonShape jumpPadShape = new b2PolygonShape ();
jumpPadShape.SetAsBox ((float)this.ScaledContentSize.Width / PhysicsHandler.pixelPerMeter / 2, (float)this.ScaledContentSize.Height / PhysicsHandler.pixelPerMeter / 4);// /4 weil die hitbox nur die hälfte der textur ist
b2FixtureDef jumpPadFixture = new b2FixtureDef ();
jumpPadFixture.shape = jumpPadShape;
jumpPadFixture.density = 0.0f; //Dichte
jumpPadFixture.restitution = 0f; //Rückprall
jumpPadFixture.friction = 0f;
jumpPadFixture.userData = WorldFixtureData.jumppad;
JumpPadBody.CreateFixture (jumpPadFixture);
//
}
示例5: Initialize
public void Initialize(b2Body bA, b2Body bB, b2Vec2 anchor)
{
BodyA = bA;
BodyB = bB;
localAnchorA = BodyA.GetLocalPoint(anchor);
localAnchorB = BodyB.GetLocalPoint(anchor);
}
示例6: b2Mat22
/// Construct this matrix using scalars.
public b2Mat22(float a11, float a12, float a21, float a22)
{
ex = b2Vec2.Zero;
ey = b2Vec2.Zero;
ex.x = a11; ex.y = a21;
ey.x = a12; ey.y = a22;
}
示例7: DrawFixture
public void DrawFixture(b2Fixture fixture)
{
b2Color color = new b2Color(0.95f, 0.95f, 0.6f);
b2Transform xf = fixture.Body.Transform;
switch (fixture.ShapeType)
{
case b2ShapeType.e_circle:
{
b2CircleShape circle = (b2CircleShape) fixture.Shape;
b2Vec2 center = b2Math.b2Mul(xf, circle.Position);
float radius = circle.Radius;
m_debugDraw.DrawCircle(center, radius, color);
}
break;
case b2ShapeType.e_polygon:
{
b2PolygonShape poly = (b2PolygonShape) fixture.Shape;
int vertexCount = poly.VertexCount;
Debug.Assert(vertexCount <= b2Settings.b2_maxPolygonVertices);
b2Vec2[] vertices = new b2Vec2[b2Settings.b2_maxPolygonVertices];
for (int i = 0; i < vertexCount; ++i)
{
vertices[i] = b2Math.b2Mul(xf, poly.Vertices[i]);
}
m_debugDraw.DrawPolygon(vertices, vertexCount, color);
}
break;
}
}
示例8: b2ClipSegmentToLine
/// Clipping for contact manifolds.
public static int b2ClipSegmentToLine(b2ClipVertex[] vOut, b2ClipVertex[] vIn,
b2Vec2 normal, float offset, byte vertexIndexA)
{
// Start with no output points
int numOut = 0;
// Calculate the distance of end points to the line
float distance0 = b2Math.b2Dot(normal, vIn[0].v) - offset;
float distance1 = b2Math.b2Dot(normal, vIn[1].v) - offset;
// If the points are behind the plane
if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
// If the points are on different sides of the plane
if (distance0 * distance1 < 0.0f)
{
// Find intersection point of edge and plane
float interp = distance0 / (distance0 - distance1);
vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);
// VertexA is hitting edgeB.
vOut[numOut].id.indexA = vertexIndexA;
vOut[numOut].id.indexB = vIn[0].id.indexB;
vOut[numOut].id.typeA = b2ContactFeatureType.e_vertex;
vOut[numOut].id.typeB = b2ContactFeatureType.e_face;
++numOut;
}
return numOut;
}
示例9: b2Mat22
/// Construct this matrix using scalars.
public b2Mat22(float a11, float a12, float a21, float a22)
{
_ex = new b2Vec2();
_ey = new b2Vec2();
_ex.x = a11; _ex.y = a21;
_ey.x = a12; _ey.y = a22;
}
示例10: Rope
public Rope()
{
const int N = 40;
b2Vec2[] vertices = new b2Vec2[N];
float[] masses = new float[N];
for (int i = 0; i < N; ++i)
{
vertices[i].Set(0.0f, 20.0f - 0.25f * i);
masses[i] = 1.0f;
}
masses[0] = 0.0f;
masses[1] = 0.0f;
b2RopeDef def = new b2RopeDef();
def.vertices = vertices;
def.count = N;
def.gravity.Set(0.0f, -10.0f);
def.masses = masses;
def.damping = 0.1f;
def.k2 = 1.0f;
def.k3 = 0.5f;
m_rope.Initialize(def);
m_angle = 0.0f;
m_rope.SetAngle(m_angle);
}
示例11: Set
public virtual void Set(b2Vec2 v1, b2Vec2 v2)
{
m_vertex1 = v1;
m_vertex2 = v2;
m_hasVertex0 = false;
m_hasVertex3 = false;
}
示例12: WorldToScreen
public static CCPoint WorldToScreen(b2Vec2 worldPos, CCPoint actualPosition, float actualScale, CCSize wSize)
{
worldPos *= actualScale;
CCPoint layerOffset = actualPosition;
CCPoint p = new CCPoint(worldPos.x + layerOffset.X, worldPos.y + layerOffset.Y);
p.Y = wSize.Height - p.Y;
return p;
}
示例13: SetTarget
public virtual void SetTarget(b2Vec2 target)
{
if (m_bodyB.IsAwake() == false)
{
m_bodyB.SetAwake(true);
}
m_targetA = target;
}
示例14: Initialize
/// Initialize the bodies, anchors, and reference angle using a world
/// anchor point.
public void Initialize(b2Body bA, b2Body bB, b2Vec2 anchor)
{
BodyA = bA;
BodyB = bB;
localAnchorA = BodyA.GetLocalPoint(anchor);
localAnchorB = BodyB.GetLocalPoint(anchor);
referenceAngle = BodyB.Angle - BodyA.Angle;
}
示例15: CreateChain
public virtual void CreateChain(b2Vec2[] vertices, int count)
{
Count = count;
Vertices = new b2Vec2[count];
Array.Copy(vertices, Vertices, count);
HasPrevVertex = false;
HasNextVertex = false;
}