本文整理汇总了C#中Vertices.IsConvex方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.IsConvex方法的具体用法?C# Vertices.IsConvex怎么用?C# Vertices.IsConvex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.IsConvex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Clean
public static void Clean(PolygonGroup group)
{
var shape = group.ToShape();
var partitioned = new Dictionary<int, List<List<Vector2>>>();
for (var i = 0; i < shape.Vertices.Count; i++)
{
var polygon = shape.Vertices[i];
var farseerVertices = new Vertices(polygon);
if (farseerVertices.IsConvex())
{
partitioned.Add(i, new List<List<Vector2>> { polygon });
continue;
}
var simplified = SimplifyTools.CollinearSimplify(farseerVertices);
var partition = Triangulate.ConvexPartition(simplified, TriangulationAlgorithm.Bayazit);
var vertices = partition.Select(verts => verts.Select(v => new Vector2(v.X, v.Y)).ToList()).ToList();
partitioned.Add(i, vertices);
}
var polygons = @group.Children.Cast<Polygon>().ToList();
group.Children.Clear();
var index = 0;
var hash = polygons.ToDictionary(k => index++, v=>v.Name);
for (var i = 0; i < partitioned.Count; i++)
{
var name = hash[i];
var partition = partitioned[i];
if (partition.Count == 1)
{
TransformPolygon(@group, partition[0], name);
}
else
{
for (var j = 0; j < partition.Count; j++)
{
var n = j > 0 ? name + "-" + (j + 1) : name;
var p = partition[j];
TransformPolygon(@group, p, n);
}
}
}
}
示例3: 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);
}
示例4: TextureFromVertices
public Texture2D TextureFromVertices(IEnumerable<Vector2> vertices, string textureRef, Color color, float materialScale)
{
Texture2D texture = null;
if (this.IsInitialized)
{
// 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.Delauny);
}
else
{
decomposedVerts = new List<Vertices>();
decomposedVerts.Add(verts);
}
List<VertexPositionColorTexture[]> verticesFill = new List<VertexPositionColorTexture[]>(decomposedVerts.Count);
Texture2D material = ContentController.Instance.GetTextureMaterial(this.device, textureRef);
materialScale /= material.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);
texture = this.RenderTexture((int)Math.Ceiling(vertsSize.X), (int)Math.Ceiling(vertsSize.Y), material, verticesFill);
}
return texture;
}
示例5: 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;
}