本文整理汇总了C#中Vertices.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.Add方法的具体用法?C# Vertices.Add怎么用?C# Vertices.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvexPartition
/// <summary>
/// Decompose the polygon into several smaller non-concave polygons.
/// </summary>
/// <param name="vertices">The polygon to decompose.</param>
/// <param name="sheer">The sheer to use if you get bad results, try using a higher value.</param>
/// <returns>A list of triangles</returns>
public static List<Vertices> ConvexPartition(Vertices vertices, float sheer = 0.001f)
{
Debug.Assert(vertices.Count > 3);
List<Point> compatList = new List<Point>(vertices.Count);
foreach (Vector2 vertex in vertices)
{
compatList.Add(new Point(vertex.X, vertex.Y));
}
Triangulator t = new Triangulator(compatList, sheer);
List<Vertices> list = new List<Vertices>();
foreach (List<Point> triangle in t.Triangles)
{
Vertices outTriangles = new Vertices(triangle.Count);
foreach (Point outTriangle in triangle)
{
outTriangles.Add(new Vector2(outTriangle.X, outTriangle.Y));
}
list.Add(outTriangles);
}
return list;
}
示例2: SquareStack
public SquareStack(Vector2 pos, Vector2 size, Vector2 subSize, float rot, SpriteBatch batch, Texture2D texture, World world)
: base(pos, batch, texture, world)
{
this.size = size;
this.subSize = subSize;
this.rot = rot;
this.texture = texture;
this.color = Color.Green;
this.spriteOrigin = new Vector2(texture.Width / 2, texture.Height / 2);
this.backCol = new Color(color.R / 2, color.G / 2, color.B / 2);
rMat = Matrix.CreateRotationZ(rot);
if (Settings.MaxPolygonVertices < 24) Settings.MaxPolygonVertices = 24;
Vector2 leftTop = Vector2.Transform(new Vector2(-size.X / 2, -size.Y / 2), rMat);
Vector2 rightTop = Vector2.Transform(new Vector2(size.X / 2, -size.Y / 2), rMat);
Vector2 leftBottom = Vector2.Transform(new Vector2(-size.X / 2, size.Y / 2), rMat);
Vector2 rightBottom = Vector2.Transform(new Vector2(size.X / 2, size.Y / 2), rMat);
Vertices verts = new Vertices();
verts.Add(leftTop); verts.Add(rightTop); verts.Add(rightBottom); verts.Add(leftBottom);
FixtureFactory.AttachPolygon(verts, density, body);
this.width = max(max(leftTop.X, rightTop.X), max(leftBottom.X, rightBottom.X)) - min(min(leftTop.X, rightTop.X), min(leftBottom.X, rightBottom.X));
this.height = max(max(leftTop.Y, rightTop.Y), max(leftBottom.Y, rightBottom.Y)) - min(min(leftTop.Y, rightTop.Y), min(leftBottom.Y, rightBottom.Y));
}
示例3: RectanglePhysicsComponent
public RectanglePhysicsComponent(Engine engine, Rectangle rectangle, Vector2 gameWorldPosition, bool dynamic)
: base(engine)
{
// create vertices to create a rectangle in the physics world with
Vertices vertices = new Vertices();
vertices.Add(Engine.Physics.PositionToPhysicsWorld(new Vector2(rectangle.Left, rectangle.Top)));
vertices.Add(Engine.Physics.PositionToPhysicsWorld(new Vector2(rectangle.Right, rectangle.Top)));
vertices.Add(Engine.Physics.PositionToPhysicsWorld(new Vector2(rectangle.Right, rectangle.Bottom)));
vertices.Add(Engine.Physics.PositionToPhysicsWorld(new Vector2(rectangle.Left, rectangle.Bottom)));
MainFixture = FixtureFactory.CreatePolygon(Engine.Physics.World, vertices, 1.0f);
MainFixture.Body.Position = Engine.Physics.PositionToPhysicsWorld(gameWorldPosition);
if (dynamic)
{
MainFixture.Body.BodyType = BodyType.Dynamic;
}
else
{
MainFixture.Body.BodyType = BodyType.Static;
}
MainFixture.Restitution = 0.5f;
// adding some linear damping gives a max speed and seems to smooth out player motion really well
MainFixture.Body.LinearDamping = 1.0f;
}
示例4: NetworkCollisionRemnant
public NetworkCollisionRemnant(Vector2 position, float size, float angleOfStartForce, int ownerId, Color color, World world, Player creator)
: base(position, size, color, null, creator)
{
OwnerId = ownerId;
body = BodyFactory.CreateBody(world);
body.BodyType = BodyType.Dynamic;
body.Position = ConvertUnits.ToSimUnits(position);
body.FixedRotation = true;
body.LinearDamping = 0.8f;
//Create the vertices that will create the collision shape
Vertices verts = new Vertices();
verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
//Create the shape and attach it to the body
PolygonShape s = new PolygonShape(verts, 0);
body.CreateFixture(s);
body.FixtureList[0].IsSensor = true;
body.UserData = this;
body.CollidesWith = Category.Cat2;
body.CollisionCategories = Category.Cat2;
//body.OnSeparation += body_OnSeparation;
body.ApplyLinearImpulse(new Vector2((float)Math.Cos(angleOfStartForce),(float)Math.Sin(angleOfStartForce)) * 10f);
}
示例5: Platform
public Platform(float width, float height, Vector2 position, string name, bool slopeDirection)
: base(position, name, "Slope")
{
Vector2 bottomLeft = new Vector2(-width/2, height/2) / Camera.PixelsPerMeter;
Vector2 bottomRight = new Vector2(width / 2, height / 2) / Camera.PixelsPerMeter;
Vector2 top = Vector2.Zero;
if (slopeDirection) //SLOPE //Remove top left vertex
{
top = new Vector2(width / 2, -height / 2) / Camera.PixelsPerMeter;
}
else //INVERSLOPE //Remove top right vertex
{
top = new Vector2(-width / 2, -height / 2) / Camera.PixelsPerMeter;
}
Vertices vertices = new Vertices(3);
vertices.Add(top);
vertices.Add(bottomRight);
vertices.Add(bottomLeft);
Body body = BodyFactory.CreatePolygon(GameManager.game.world, vertices, 1f, position/ Camera.PixelsPerMeter);
body.IsStatic = true;
body.Restitution = 0f;
body.Friction = 0.5f;
this.AddBody(body);
}
示例6: Goalie
public Goalie(World world, GoalieData spawn)
{
var body = new Body(world);
var angle = spawn.End - spawn.Begin;
body.Rotation = FMath.Atan2(angle.Y, angle.X);
segment.A = spawn.Begin;
segment.B = spawn.End;
var normal = new Vector2(-angle.Y, angle.X);
normal.Normalize();
delta = normal * .5f;
segmentOut.A = spawn.Begin + delta;
segmentOut.B = spawn.End + delta;
segmentIn.A = spawn.Begin - delta;
segmentIn.B = spawn.End - delta;
body.Position = spawn.Begin;
var verts = new Vertices();
verts.Add(new Vector2(left, bottom));
verts.Add(new Vector2(right, bottom));
verts.Add(new Vector2(right, top));
verts.Add(new Vector2(left, top));
var shape = new PolygonShape(verts, 1f);
body.FixedRotation = true;
body.BodyType = BodyType.Dynamic;
Fixture = body.CreateFixture(shape);
}
示例7: Border
public Border(World world, ScreenManager screenManager, Camera2D camera)
{
_screenManager = screenManager;
_camera = camera;
float halfWidth = ConvertUnits.ToSimUnits(screenManager.GraphicsDevice.Viewport.Width) / 2f - 0.75f;
float halfHeight = ConvertUnits.ToSimUnits(screenManager.GraphicsDevice.Viewport.Height) / 2f - 0.75f;
Vertices borders = new Vertices(4);
borders.Add(new Vector2(-halfWidth, halfHeight));
borders.Add(new Vector2(halfWidth, halfHeight));
borders.Add(new Vector2(halfWidth, -halfHeight));
borders.Add(new Vector2(-halfWidth, -halfHeight));
_anchor = BodyFactory.CreateLoopShape(world, borders);
_anchor.CollisionCategories = Category.All;
_anchor.CollidesWith = Category.All;
_basicEffect = new BasicEffect(screenManager.GraphicsDevice);
_basicEffect.VertexColorEnabled = true;
_basicEffect.TextureEnabled = true;
_basicEffect.Texture = screenManager.Content.Load<Texture2D>("Materials/pavement");
VertexPositionColorTexture[] vertice = new VertexPositionColorTexture[8];
vertice[0] = new VertexPositionColorTexture(new Vector3(-halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, -halfHeight) / 5.25f);
vertice[1] = new VertexPositionColorTexture(new Vector3(halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, -halfHeight) / 5.25f);
vertice[2] = new VertexPositionColorTexture(new Vector3(halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, halfHeight) / 5.25f);
vertice[3] = new VertexPositionColorTexture(new Vector3(-halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, halfHeight) / 5.25f);
vertice[4] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, -halfHeight - 2f) / 5.25f);
vertice[5] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, -halfHeight - 2f) / 5.25f);
vertice[6] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, halfHeight + 2f) / 5.25f);
vertice[7] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, halfHeight + 2f) / 5.25f);
_borderVerts = new VertexPositionColorTexture[24];
_borderVerts[0] = vertice[0];
_borderVerts[1] = vertice[5];
_borderVerts[2] = vertice[4];
_borderVerts[3] = vertice[0];
_borderVerts[4] = vertice[1];
_borderVerts[5] = vertice[5];
_borderVerts[6] = vertice[1];
_borderVerts[7] = vertice[6];
_borderVerts[8] = vertice[5];
_borderVerts[9] = vertice[1];
_borderVerts[10] = vertice[2];
_borderVerts[11] = vertice[6];
_borderVerts[12] = vertice[2];
_borderVerts[13] = vertice[7];
_borderVerts[14] = vertice[6];
_borderVerts[15] = vertice[2];
_borderVerts[16] = vertice[3];
_borderVerts[17] = vertice[7];
_borderVerts[18] = vertice[3];
_borderVerts[19] = vertice[4];
_borderVerts[20] = vertice[7];
_borderVerts[21] = vertice[3];
_borderVerts[22] = vertice[0];
_borderVerts[23] = vertice[4];
}
示例8: MakeVertices
private static Vertices MakeVertices(Vector2 sz)
{
Vertices v = new Vertices();
v.Add(new Vector2(0, 0));
v.Add(new Vector2(sz.X, 0));
v.Add(new Vector2(sz.X, sz.Y));
v.Add(new Vector2(0,sz.Y));
return v;
}
示例9: CreateRectangle
/// <summary>
/// Build vertices to represent an axis-aligned box.
/// </summary>
/// <param name="hx">the half-width.</param>
/// <param name="hy">the half-height.</param>
public static Vertices CreateRectangle(float hx, float hy)
{
Vertices vertices = new Vertices(4);
vertices.Add(new Vector2(-hx, -hy));
vertices.Add(new Vector2(hx, -hy));
vertices.Add(new Vector2(hx, hy));
vertices.Add(new Vector2(-hx, hy));
return vertices;
}
示例10: RevoluteTest
private RevoluteTest()
{
//Ground
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
Body bodyB = BodyFactory.CreateCircle(World, 0.5f, 5f, new Vector2(-10.0f, 20.0f));
bodyB.BodyType = BodyType.Dynamic;
const float w = 100.0f;
bodyB.AngularVelocity = w;
bodyB.LinearVelocity = new Vector2(-8.0f * w, 0.0f);
_joint = new RevoluteJoint(ground, bodyB, new Vector2(-10.0f, 12.0f), true);
_joint.MotorSpeed = 1.0f * Settings.Pi;
_joint.MaxMotorTorque = 10000.0f;
_joint.MotorEnabled = false;
_joint.LowerLimit = -0.25f * Settings.Pi;
_joint.UpperLimit = 0.5f * Settings.Pi;
_joint.LimitEnabled = true;
_joint.CollideConnected = true;
World.AddJoint(_joint);
}
{
Body ball = BodyFactory.CreateCircle(World, 3.0f, 5.0f, new Vector2(5.0f, 30.0f));
ball.BodyType = BodyType.Dynamic;
ball.CollisionCategories = Category.Cat1;
Vertices polygonVertices = PolygonTools.CreateRectangle(10.0f, 0.2f, new Vector2(-10.0f, 0.0f), 0.0f);
Body polygonBody = BodyFactory.CreatePolygon(World, polygonVertices, 2, new Vector2(20, 10));
polygonBody.BodyType = BodyType.Dynamic;
polygonBody.IsBullet = true;
RevoluteJoint joint = new RevoluteJoint(ground, polygonBody, new Vector2(20, 10), true);
joint.LowerLimit = -0.25f * Settings.Pi;
joint.UpperLimit = 0.0f * Settings.Pi;
joint.LimitEnabled = true;
World.AddJoint(joint);
}
// Tests mass computation of a small object far from the origin
{
Vertices verts = new Vertices(3);
verts.Add(new Vector2(17.63f, 36.31f));
verts.Add(new Vector2(17.52f, 36.69f));
verts.Add(new Vector2(17.19f, 36.36f));
Body polyShape = BodyFactory.CreatePolygon(World, verts, 1);
polyShape.BodyType = BodyType.Dynamic;
}
}
示例11: CreateBorder
private void CreateBorder(float width, float height, float borderWidth)
{
width = Math.Abs(width);
height = Math.Abs(height);
_anchor = BodyFactory.CreateBody(_world);
left = BodyFactory.CreateBody(_world);
right = BodyFactory.CreateBody(_world);
up = BodyFactory.CreateBody(_world);
down = BodyFactory.CreateBody(_world);
UserData userData = new UserData(-1, 3, true);
Vertices vert = new Vertices();
// top
// counterclockwise
Vertices vup = new Vertices();
vup.Add(new Vector2(0, 10));
vup.Add(new Vector2(0, 0));
vup.Add(new Vector2(1000, 0));
vup.Add(new Vector2(1000, 10));
up.CreateFixture(new PolygonShape(vup, 0.0f), userData);
//Bottom
down.CreateFixture(new PolygonShape(vup, 0.0f), userData);
down.Position = new Vector2(0, 990);
//Left
Vertices vl = new Vertices();
vl.Add(new Vector2(0, 1000));
vl.Add(new Vector2(0, 0));
vl.Add(new Vector2(10, 0));
vl.Add(new Vector2(10, 1000));
left.CreateFixture(new PolygonShape(vl, 0.0f), userData);
//Right
right.CreateFixture(new PolygonShape(vl, 0.0f), userData);
right.Position = new Vector2(990, 0);
foreach (Fixture t in _anchor.FixtureList)
{
t.CollisionFilter.CollisionCategories = Category.All;
t.CollisionFilter.CollidesWith = Category.All;
t.Friction = _frictionValue;
t.Restitution = _bouncyValue;
}
ContentManager content = Master.theMaster.game.Content;
topBorder = content.Load<Texture2D>("images/BoarderHorizontal");
bottomBorder = content.Load<Texture2D>("images/BoarderHorizontal");
rightBorder = content.Load<Texture2D>("images/BoarderVertical");
leftBorder = content.Load<Texture2D>("images/BoarderVertical");
}
示例12: InitBorders
public void InitBorders()
{
Vertices borders = new Vertices(4);
borders.Add(new Vector2(0, 0));
borders.Add(new Vector2(width, 0));
borders.Add(new Vector2(width, height));
borders.Add(new Vector2(0, height));
borderBody = BodyFactory.CreateLoopShape(_world, borders);
borderBody.CollisionCategories = Category.All;
borderBody.CollidesWith = Category.All;
}
示例13: addQuad
public void addQuad(World world, WallCompiled wall, int a, int b)
{
var verts = new Vertices(4);
verts.Add(wall.Verts1[a]);
verts.Add(wall.Verts4[a]);
verts.Add(wall.Verts4[b]);
verts.Add(wall.Verts1[b]);
var wallBody = new Body(world);
var wallShape = new PolygonShape(verts, 1f);
Fixtures[a] = wallBody.CreateFixture(wallShape);
Fixtures[a].Friction = 0f;
}
示例14: BuildEntity
public Entity BuildEntity(Entity e, params object[] args)
{
e.Tag = "Chassis";
#region Body
Body Chassis = e.AddComponent<Body>(new Body(_World, e));
{
Vertices vertices = new Vertices(8);
vertices.Add(new Vector2(-2.5f, 0.08f));
vertices.Add(new Vector2(-2.375f, -0.46f));
vertices.Add(new Vector2(-0.58f, -0.92f));
vertices.Add(new Vector2(0.46f, -0.92f));
vertices.Add(new Vector2(2.5f, -0.17f));
vertices.Add(new Vector2(2.5f, 0.205f));
vertices.Add(new Vector2(2.3f, 0.33f));
vertices.Add(new Vector2(-2.25f, 0.35f));
PolygonShape chassisShape = new PolygonShape(vertices, 2f);
Chassis.BodyType = BodyType.Dynamic;
Chassis.Position = new Vector2(0.0f, -1.0f);
Chassis.CreateFixture(chassisShape);
}
#endregion
#region Sprite
e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, (Rectangle)args[1],
Chassis, 1, Color.White, 0f));
#endregion
return e;
}
示例15: CreateBodyFixture
private void CreateBodyFixture()
{
//Create the vertices that will create the collision shape
Vertices verts = new Vertices();
verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(-ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), -ConvertUnits.ToSimUnits(size / 2f)));
verts.Add(new Vector2(ConvertUnits.ToSimUnits(size / 2f), ConvertUnits.ToSimUnits(size / 2f)));
//Create the shape and attach it to the body
PolygonShape s = new PolygonShape(verts, 0);
body.CreateFixture(s);
body.FixtureList[0].IsSensor = true;
}