本文整理汇总了C#中Vertices.NextVertex方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.NextVertex方法的具体用法?C# Vertices.NextVertex怎么用?C# Vertices.NextVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.NextVertex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeIdenticalNeighborPoints
/// <summary>
/// Merges Identical points that are connected to eachother in the polygon.
/// </summary>
/// <param name="vertices">The vertices.</param>
public static Vertices MergeIdenticalNeighborPoints(Vertices vertices)
{
for (int i = 0; i < vertices.Count ; i++)
{
Point2D cur = vertices[i];
Point2D nex = vertices.NextVertex(i);
if (cur.X == nex.X && cur.Y == nex.Y)
{
vertices.Remove(nex);
}
}
return new Vertices(vertices);
}
示例2: CollinearSimplify
/// <summary>
/// Removes all collinear points on the polygon.
/// </summary>
/// <param name="vertices">The polygon that needs simplification.</param>
/// <param name="collinearityTolerance">The collinearity tolerance.</param>
/// <returns>A simplified polygon.</returns>
public static Vertices CollinearSimplify(Vertices vertices, float collinearityTolerance = 0)
{
if (vertices.Count <= 3)
return vertices;
Vertices simplified = new Vertices(vertices.Count);
for (int i = 0; i < vertices.Count; i++)
{
Point2D prev = vertices.PreviousVertex(i);
Point2D current = vertices[i];
Point2D next = vertices.NextVertex(i);
//If they collinear, continue
if (MathUtils.IsCollinear(ref prev, ref current, ref next, collinearityTolerance))
continue;
simplified.Add(current);
}
return simplified;
}
示例3: ReduceByDistance
/// <summary>
/// Reduces the polygon by distance.
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <param name="distance">The distance between points. Points closer than this will be 'joined'.</param>
/// <returns></returns>
public static Vertices ReduceByDistance(Vertices vertices, float distance)
{
//We can't simplify polygons under 3 vertices
if (vertices.Count < 3)
return vertices;
Vertices simplified = new Vertices();
for (int i = 0; i < vertices.Count; i++)
{
Vector2D current = vertices[i];
Vector2D next = vertices.NextVertex(i);
//If they are closer than the distance, continue
if ((next - current).LengthSquared() <= distance)
continue;
simplified.Add(current);
}
return simplified;
}
示例4: TextureFromVertices
public Texture2D TextureFromVertices(Vertices vertices, MaterialType type, Color color, float materialScale)
{
// copy vertices
Vertices verts = new Vertices(vertices);
// scale to display units (i.e. pixels) for rendering to texture
Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
verts.Scale(ref scale);
// translate the boundingbox center to the texture center
// because we use an orthographic projection for rendering later
AABB vertsBounds = verts.GetAABB();
verts.Translate(-vertsBounds.Center);
List<Vertices> decomposedVerts;
if (!verts.IsConvex())
{
decomposedVerts = Triangulate.ConvexPartition(verts, TriangulationAlgorithm.Earclip);
}
else
{
decomposedVerts = new List<Vertices>();
decomposedVerts.Add(verts);
}
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
materialScale /= _materials[type].Width;
for (int i = 0; i < decomposedVerts.Count; ++i)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVerts[i].Count - 2)]);
for (int j = 0; j < decomposedVerts[i].Count - 2; ++j)
{
// fill vertices
verticesFill[i][3 * j].Position = new Vector3(decomposedVerts[i][0], 0f);
verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVerts[i].NextVertex(j), 0f);
verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVerts[i].NextVertex(j + 1), 0f);
verticesFill[i][3 * j].TextureCoordinate = decomposedVerts[i][0] * materialScale;
verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVerts[i].NextVertex(j) * materialScale;
verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVerts[i].NextVertex(j + 1) * materialScale;
verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = color;
}
}
// calculate outline
VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * verts.Count];
for (int i = 0; i < verts.Count; ++i)
{
verticesOutline[2 * i].Position = new Vector3(verts[i], 0f);
verticesOutline[2 * i + 1].Position = new Vector3(verts.NextVertex(i), 0f);
verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = Color.Black;
}
Vector2 vertsSize = new Vector2(vertsBounds.UpperBound.X - vertsBounds.LowerBound.X, vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y);
return RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _materials[type], verticesFill, verticesOutline);
}
示例5: ReduceByDistance
/// <summary>
/// Reduces the polygon by distance.
/// </summary>
/// <param name="vertices">The vertices.</param>
/// <param name="distance">The distance between points. Points closer than this will be removed.</param>
public static Vertices ReduceByDistance(Vertices vertices, float distance)
{
if (vertices.Count <= 3)
return vertices;
float distance2 = distance * distance;
Vertices simplified = new Vertices(vertices.Count);
for (int i = 0; i < vertices.Count; i++)
{
Point2D current = vertices[i];
Point2D next = vertices.NextVertex(i);
//If they are closer than the distance, continue
if ((next - current).LengthSquared() <= distance2)
continue;
simplified.Add(current);
}
return simplified;
}
示例6: DrawVertices
public void DrawVertices(Vertices verts, Color color)
{
if (!_hasBegun)
{
throw new InvalidOperationException("Begin must be called before DrawVertices can be called.");
}
for (int i = 0; i < verts.Count; ++i)
{
if (_lineVertsCount >= _lineVertices.Length)
{
Flush();
}
_lineVertices[_lineVertsCount].Position = new Vector3(verts[i], 0f);
_lineVertices[_lineVertsCount + 1].Position = new Vector3(verts.NextVertex(i), 0f);
_lineVertices[_lineVertsCount].Color = _lineVertices[_lineVertsCount + 1].Color = color;
_lineVertsCount += 2;
}
}
示例7: PolygonTexture
public static Texture2D PolygonTexture(Vertices vertices, string pattern, Color mainColor, Color patternColor, Color outlineColor, float materialScale)
{
if (_contentWrapper != null)
{
// copy vertices
Vertices scaledVertices = new Vertices(vertices);
// scale to display units (i.e. pixels) for rendering to texture
Vector2 scale = ConvertUnits.ToDisplayUnits(Vector2.One);
scaledVertices.Scale(ref scale);
// translate the boundingbox center to the texture center
// because we use an orthographic projection for rendering later
AABB verticesBounds = scaledVertices.GetAABB();
scaledVertices.Translate(-verticesBounds.Center);
List<Vertices> decomposedVertices;
if (!scaledVertices.IsConvex())
{
decomposedVertices = Triangulate.ConvexPartition(scaledVertices, TriangulationAlgorithm.Earclip);
}
else
{
decomposedVertices = new List<Vertices>();
decomposedVertices.Add(scaledVertices);
}
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVertices.Count);
if (_textureList.ContainsKey(pattern))
{
materialScale /= _textureList[pattern].Width;
}
else
{
materialScale = 1f;
}
for (int i = 0; i < decomposedVertices.Count; i++)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVertices[i].Count - 2)]);
for (int j = 0; j < decomposedVertices[i].Count - 2; j++)
{
// fill vertices
verticesFill[i][3 * j].Position = new Vector3(decomposedVertices[i][0], 0f);
verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVertices[i].NextVertex(j), 0f);
verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVertices[i].NextVertex(j + 1), 0f);
verticesFill[i][3 * j].TextureCoordinate = decomposedVertices[i][0] * materialScale;
verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVertices[i].NextVertex(j) * materialScale;
verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVertices[i].NextVertex(j + 1) * materialScale;
verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = mainColor;
}
}
// calculate outline
VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * scaledVertices.Count];
for (int i = 0; i < scaledVertices.Count; i++)
{
verticesOutline[2 * i].Position = new Vector3(scaledVertices[i], 0f);
verticesOutline[2 * i + 1].Position = new Vector3(scaledVertices.NextVertex(i), 0f);
verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = outlineColor;
}
Vector2 vertsSize = new Vector2(verticesBounds.UpperBound.X - verticesBounds.LowerBound.X, verticesBounds.UpperBound.Y - verticesBounds.LowerBound.Y);
return _contentWrapper.RenderTexture((int)vertsSize.X, (int)vertsSize.Y, _textureList.ContainsKey(pattern) ? _textureList[pattern] : null, patternColor, verticesFill, verticesOutline);
}
return null;
}
示例8: SanityCheck
private static bool SanityCheck(Vertices vertices)
{
//Make sure it is is a polygon
if (vertices.Count < 3)
return false;
//Make sure it has a large enugh area
if (vertices.GetArea() < 0.00001f)
return false;
//Make sure no vertices are too close to each other
for (int i = 0; i < vertices.Count; ++i)
{
Vector2 current = vertices[i];
Vector2 next = vertices.NextVertex(i);
Vector2 edge = next - current;
if (edge.LengthSquared() < Settings.Epsilon * Settings.Epsilon)
return false;
}
return true;
}
示例9: TextureFromVertices
public Texture2D TextureFromVertices(Vertices vertices, Texture2D material, Color fillColor, bool hasOutline, Color outlineColor, float materialScale)
{
Vertices verts = new Vertices(vertices);
AABB vertsBounds = verts.GetCollisionBox();
verts.Translate(-vertsBounds.Center);
List<Vertices> decomposedVerts;
if (!verts.IsConvex())
{
decomposedVerts = EarclipDecomposer.ConvexPartition(verts);
}
else
{
decomposedVerts = new List<Vertices>()
{
verts
};
}
//fill
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
for (int i = 0; i < decomposedVerts.Count; i++)
{
verticesFill.Add(new VertexPositionColorTexture[3 * (decomposedVerts[i].Count - 2)]);
for (int j = 0; j < decomposedVerts[i].Count - 2; j++)
{
verticesFill[i][3 * j].Position = new Vector3(decomposedVerts[i][0], 0f);
verticesFill[i][3 * j + 1].Position = new Vector3(decomposedVerts[i].NextVertex(j), 0f);
verticesFill[i][3 * j + 2].Position = new Vector3(decomposedVerts[i].NextVertex(j + 1), 0f);
verticesFill[i][3 * j].TextureCoordinate = decomposedVerts[i][0] * materialScale;
verticesFill[i][3 * j + 1].TextureCoordinate = decomposedVerts[i].NextVertex(j) * materialScale;
verticesFill[i][3 * j + 2].TextureCoordinate = decomposedVerts[i].NextVertex(j + 1) * materialScale;
verticesFill[i][3 * j].Color = verticesFill[i][3 * j + 1].Color = verticesFill[i][3 * j + 2].Color = fillColor;
}
}
//outline
VertexPositionColor[] verticesOutline;
if (!hasOutline)
{
verticesOutline = new VertexPositionColor[0];
}
else
{
verticesOutline = new VertexPositionColor[2 * verts.Count];
for (int i = 0; i < verts.Count; i++)
{
verticesOutline[2 * i].Position = new Vector3(verts[i], 0f);
verticesOutline[2 * i + 1].Position = new Vector3(verts.NextVertex(i), 0f);
verticesOutline[2 * i].Color = verticesOutline[2 * i + 1].Color = outlineColor;
}
}
Vector2 vertsSize = new Vector2(vertsBounds.UpperBound.X - vertsBounds.LowerBound.X, vertsBounds.UpperBound.Y - vertsBounds.LowerBound.Y);
return RenderTexture((int)System.Math.Ceiling(vertsSize.X), (int)System.Math.Ceiling(vertsSize.Y), material, verticesFill, hasOutline, verticesOutline);
}