本文整理汇总了C#中Vertices.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.AddRange方法的具体用法?C# Vertices.AddRange怎么用?C# Vertices.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.AddRange方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateChainVertices
/// <summary>
/// Makes a set of vertices for the chain shape
/// by creating two offset vertices perpendicular
/// to the averaged direction from the current vertex
/// and it's two connected vertices. Returned vertices
/// are in counterclockwise order
/// </summary>
/// <param name="chain">chain shape to work on</param>
/// <returns>new Triangularizable Vertices for chain shape</returns>
private static Vertices CreateChainVertices(ChainShape chain)
{
Matrix rotMat = Matrix.CreateRotationZ(MathHelper.PiOver2);
Vertices chainTextVerts = new Vertices(chain.Vertices.Count * 2);
List<Vector2> posChainTextVerts = new List<Vector2>(chain.Vertices.Count);
List<Vector2> negChainTextVerts = new List<Vector2>(chain.Vertices.Count);
for (int i = 0; i < chain.Vertices.Count; i++)
{
var curVertex = chain.Vertices[i];
Vector2 direction = Vector2.Zero;
Vector2 distance = Vector2.Zero;
if (i == 0)
{
distance = chain.Vertices[i + 1] - curVertex;
}
else if (i < chain.Vertices.Count - 1)
{
distance = (chain.Vertices[i + 1] - curVertex) + (curVertex - chain.Vertices[i - 1]);
}
else
{
distance = curVertex - chain.Vertices[i - 1];
}
direction = Vector2.Normalize(Vector2.Transform(distance, rotMat)).ToSimUnits();
posChainTextVerts.Add(curVertex + (direction * 2f));
negChainTextVerts.Insert(0, curVertex - (direction * 2f));
}
chainTextVerts.AddRange(posChainTextVerts);
chainTextVerts.AddRange(negChainTextVerts);
return chainTextVerts;
}
示例2: CreateSimplePolygon
//.........这里部分代码省略.........
if (entrance == Vector2.Zero || !InBounds(ref entrance))
{
entranceFound = SearchHullEntrance(out entrance);
if (entranceFound)
{
current = new Vector2(entrance.X - 1f, entrance.Y);
}
}
else
{
if (IsSolid(ref entrance))
{
if (IsNearPixel(ref entrance, ref last))
{
current = last;
entranceFound = true;
}
else
{
Vector2 temp;
if (SearchNearPixels(false, ref entrance, out temp))
{
current = temp;
entranceFound = true;
}
else
{
entranceFound = false;
}
}
}
}
#endregion
if (entranceFound)
{
polygon.Add(entrance);
hullArea.Add(entrance);
Vector2 next = entrance;
do
{
// Search in the pre vision list for an outstanding point.
Vector2 outstanding;
if (SearchForOutstandingVertex(hullArea, out outstanding))
{
if (endOfHull)
{
// We have found the next pixel, but is it on the last bit of the hull?
if (endOfHullArea.Contains(outstanding))
{
// Indeed.
polygon.Add(outstanding);
}
// That's enough, quit.
break;
}
// Add it and remove all vertices that don't matter anymore
// (all the vertices before the outstanding).
polygon.Add(outstanding);
hullArea.RemoveRange(0, hullArea.IndexOf(outstanding));
}
// Last point gets current and current gets next. Our little spider is moving forward on the hull ;).
last = current;
current = next;
// Get the next point on hull.
if (GetNextHullPoint(ref last, ref current, out next))
{
// Add the vertex to a hull pre vision list.
hullArea.Add(next);
}
else
{
// Quit
break;
}
if (next == entrance && !endOfHull)
{
// It's the last bit of the hull, search on and exit at next found vertex.
endOfHull = true;
endOfHullArea.AddRange(hullArea);
// We don't want the last vertex to be the same as the first one, because it causes the triangulation code to crash.
if (endOfHullArea.Contains(entrance))
endOfHullArea.Remove(entrance);
}
} while (true);
}
return polygon;
}
示例3: j2b2Fixture
Fixture j2b2Fixture(Body body, JObject fixtureValue)
{
if (null == fixtureValue)
return null;
//Fixture fixtureDef = new Fixture();
var restitution = jsonToFloat("restitution", fixtureValue);
var friction = jsonToFloat("friction", fixtureValue);
var density = jsonToFloat("density", fixtureValue);
var isSensor = fixtureValue["sensor"] == null ? false : (bool)fixtureValue["sensor"];
var categoryBits = fixtureValue["filter-categoryBits"] == null ? 0x0001 : (int)fixtureValue["filter-categoryBits"];
var maskBits = fixtureValue["filter-maskBits"] == null ? 0xffff : (int)fixtureValue["filter-maskBits"];
var groupIndex = fixtureValue["filter-groupIndex"] == null ? (short)0 : (short)fixtureValue["filter-groupIndex"];
Fixture fixture = null;
if (null != fixtureValue["circle"])
{
JObject circleValue = (JObject)fixtureValue["circle"];
var radius = jsonToFloat("radius", circleValue);
var position = jsonToVec("center", circleValue);
fixture = FixtureFactory.AttachCircle(radius, density, body, position);
}
else if (null != fixtureValue["edge"])
{
JObject edgeValue = (JObject)fixtureValue["edge"];
var m_vertex1 = (jsonToVec("vertex1", edgeValue));
var m_vertex2 = (jsonToVec("vertex2", edgeValue));
fixture = FixtureFactory.AttachEdge(m_vertex1, m_vertex2, body);
((EdgeShape)fixture.Shape).HasVertex0 = edgeValue["hasVertex0"] == null ? false : (bool)edgeValue["hasVertex0"];
((EdgeShape)fixture.Shape).HasVertex3 = edgeValue["hasVertex3"] == null ? false : (bool)edgeValue["hasVertex3"];
if (((EdgeShape)fixture.Shape).HasVertex0)
((EdgeShape)fixture.Shape).Vertex0 = (jsonToVec("vertex0", edgeValue));
if (((EdgeShape)fixture.Shape).HasVertex3)
((EdgeShape)fixture.Shape).Vertex3 = (jsonToVec("vertex3", edgeValue));
}
else if (null != fixtureValue["loop"])
{// support old
// format (r197)
JObject chainValue = (JObject)fixtureValue["loop"];
int numVertices = ((JArray)chainValue["x"]).Count;
Vertices vertices = new Vertices();
for (int i = 0; i < numVertices; i++)
vertices.Add(jsonToVec("vertices", chainValue, i));
fixture = FixtureFactory.AttachChainShape(vertices, body);
}
else if (null != fixtureValue["chain"])
{
JObject chainValue = (JObject)fixtureValue["chain"];
ChainShape chainShape = new ChainShape();
int numVertices = ((JArray)chainValue["vertices"]["x"]).Count;
Vertices vertices = new Vertices();
for (int i = 0; i < numVertices; i++)
vertices.Add(jsonToVec("vertices", chainValue, i));
// FPE. See http://www.box2d.org/forum/viewtopic.php?f=4&t=7973&p=35363
if (vertices[0] == vertices[vertices.Count - 1])
{
var vertices2 = new Vertices(numVertices - 1);
vertices2.AddRange(vertices.GetRange(0, numVertices - 1));
chainShape.CreateLoop(vertices2);
fixture = body.CreateFixture(chainShape);
}
else
fixture = FixtureFactory.AttachChainShape(vertices, body);
var fixtureChain = fixture.Shape as ChainShape;
var hasPrevVertex = chainValue["hasPrevVertex"] == null ? false : (bool)chainValue["hasPrevVertex"];
var hasNextVertex = chainValue["hasNextVertex"] == null ? false : (bool)chainValue["hasNextVertex"];
if (hasPrevVertex)
fixtureChain.PrevVertex = (jsonToVec("prevVertex", chainValue));
if (hasNextVertex)
fixtureChain.NextVertex = (jsonToVec("nextVertex", chainValue));
}
else if (null != fixtureValue["polygon"])
{
JObject polygonValue = (JObject)fixtureValue["polygon"];
Vertices vertices = new Vertices();
int numVertices = ((JArray)polygonValue["vertices"]["x"]).Count;
if (numVertices > Settings.MaxPolygonVertices)
{
Console.WriteLine("Ignoring polygon fixture with too many vertices.");
}
else if (numVertices < 2)
//.........这里部分代码省略.........
示例4: Initialize
public override void Initialize()
{
base.Initialize();
GameInstance.ViewCenter = Vector2.Zero;
_twoShape = new Vertices
{
new Vector2(5.510646f,-6.312136f),
new Vector2(5.510646f,-9.534955f),
new Vector2(-6.016356f,-9.534955f),
new Vector2(-6.016356f,-6.837597f),
new Vector2(-1.933609f,-0.7320573f),
new Vector2(-0.6714239f,1.242431f),
new Vector2(0.07130214f,2.498066f),
new Vector2(0.4939168f,3.344996f),
new Vector2(0.7957863f,4.093408f),
new Vector2(0.9769094f,4.743301f),
new Vector2(1.037288f,5.294677f),
new Vector2(0.9643505f,5.967545f),
new Vector2(0.7455474f,6.44485f),
new Vector2(0.5806286f,6.610869f),
new Vector2(0.3776243f,6.729462f),
new Vector2(0.1365345f,6.80062f),
new Vector2(-0.1426414f,6.824349f),
new Vector2(-0.4218241f,6.798073f),
new Vector2(-0.6629166f,6.719252f),
new Vector2(-0.8659183f,6.587883f),
new Vector2(-1.030829f,6.403981f),
new Vector2(-1.158469f,6.141973f),
new Vector2(-1.249639f,5.776335f),
new Vector2(-1.32257f,4.734189f),
new Vector2(-1.32257f,2.935948f),
new Vector2(-6.016356f,2.935948f),
new Vector2(-6.016356f,3.624884f),
new Vector2(-5.970973f,5.045072f),
new Vector2(-5.834826f,6.129576f),
new Vector2(-5.710837f,6.586056f),
new Vector2(-5.520398f,7.0389f),
new Vector2(-5.263501f,7.488094f),
new Vector2(-4.940154f,7.933653f),
new Vector2(-4.556844f,8.350358f),
new Vector2(-4.120041f,8.71307f),
new Vector2(-3.629755f,9.02178f),
new Vector2(-3.085981f,9.276493f),
new Vector2(-2.487104f,9.475718f),
new Vector2(-1.8315f,9.618026f),
new Vector2(-1.119165f,9.703418f),
new Vector2(-0.3501012f,9.731889f),
new Vector2(1.117107f,9.644661f),
new Vector2(1.779295f,9.535644f),
new Vector2(2.393876f,9.383026f),
new Vector2(2.960846f,9.186799f),
new Vector2(3.480206f,8.946972f),
new Vector2(3.951957f,8.663539f),
new Vector2(4.376098f,8.336502f),
new Vector2(5.076675f,7.592458f),
new Vector2(5.577088f,6.755733f),
new Vector2(5.877342f,5.82633f),
new Vector2(5.977431f,4.804249f),
new Vector2(5.921109f,3.981021f),
new Vector2(5.752138f,3.134446f),
new Vector2(5.470524f,2.264521f),
new Vector2(5.076274f,1.371247f),
new Vector2(4.406482f,0.2123121f),
new Vector2(3.298271f,-1.454563f),
new Vector2(1.751642f,-3.629379f),
new Vector2(-0.233405f,-6.312136f),
};
int beforeCount = _twoShape.Count;
_twoShape.AddRange(_twoShape); //Duplicate the points
_twoShape = SimplifyTools.MergeIdenticalPoints(_twoShape);
Debug.Assert(beforeCount == _twoShape.Count); //The merge should have removed all duplicate points.
const int xOffset = 18;
const int yOffset = 18;
_upperLeft = new Vertices(_twoShape);
_upperLeft.Translate(new Vector2(-xOffset, yOffset));
_upperLeft = SimplifyTools.ReduceByArea(_upperLeft, 0.1f);
_upperRight = new Vertices(_twoShape);
_upperRight.Translate(new Vector2(xOffset, yOffset));
_upperRight = SimplifyTools.ReduceByNth(_upperRight, 3);
_lowerLeft = new Vertices(_twoShape);
_lowerLeft.Translate(new Vector2(-xOffset, -yOffset));
_lowerLeft = SimplifyTools.ReduceByDistance(_lowerLeft, 0.5f);
_lowerRight = new Vertices(_twoShape);
_lowerRight.Translate(new Vector2(xOffset, -yOffset));
_lowerRight = SimplifyTools.DouglasPeuckerSimplify(_lowerRight, 0.5f);
}
示例5: ToVertices
public Vertices ToVertices()
{
Vertices vertices = new Vertices();
vertices.AddRange(Flatten());
return vertices;
}
示例6: Convert
public Vertices Convert(params Vector2D[] vertices)
{
var farseerVertices = new Vertices(vertices.Length);
farseerVertices.AddRange(vertices.Select(t => ToSimUnits(Convert(t))));
return farseerVertices;
}