本文整理汇总了C#中Vertices.ForceCounterClockWise方法的典型用法代码示例。如果您正苦于以下问题:C# Vertices.ForceCounterClockWise方法的具体用法?C# Vertices.ForceCounterClockWise怎么用?C# Vertices.ForceCounterClockWise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices.ForceCounterClockWise方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReverseShape
public static PolygonShape ReverseShape(params Vector2[] verts)
{
Vertices ver = new Vertices(verts);
ver.ForceCounterClockWise();
return new PolygonShape(ver, 4.0f);
}
示例2: updateSS
private void updateSS()
{
output = new float[5000];
output2 = new float[5000];
Vertices ssVertices = new Vertices();
ssVertices.Holes = polygon.ControlVertices.Holes;
foreach (Point2D point in polygon.ControlVertices)
{
ssVertices.Add(point);
}
if (mirrorMode)
{
for (int x = polygon.MirrorVertices.Count - 1; x >= 0; x--)
{
ssVertices.Add(polygon.MirrorVertices[x]);
}
foreach (Vertices hole in polygon.MirrorVertices.Holes)
{
ssVertices.Holes.Add(hole);
}
}
if (ssVertices.IsSimple())
{
ssVertices.ForceCounterClockWise();
float[] points = new float[ssVertices.Count * 2];
for (int i = 0, j = 0; i < ssVertices.Count * 2; j++, i = i + 2)
{
points[i] = ssVertices[j].X;
points[i + 1] = ssVertices[j].Y;
}
if (ssVertices.Holes.Count > 0)
{
int i = 0;
int totalSpaceNeeded = 0;
foreach (Vertices hole in ssVertices.Holes)
{
hole.ForceClockWiseHole();
totalSpaceNeeded += hole.Count * 2;
}
float[] holes = new float[totalSpaceNeeded];
int[] holeEnds = new int[ssVertices.Holes.Count];
int x = 0;
foreach (Vertices hole in ssVertices.Holes)
{
for (int j = 0; j < hole.Count; j++, i = i + 2)
{
holes[i] = hole[j].X;
holes[i + 1] = hole[j].Y;
}
holeEnds[x++] = hole.Count;
}
cpp.SSAwithHoles(points, points.Length, holes, holeEnds, holeEnds.Length, output, output2, _gui.getSubdivideSize());
}
else
{
cpp.SSAwithoutHoles(points, points.Length, output, output2, _gui.getSubdivideSize());
}
}
}
示例3: ConvexPartition
/// <summary>
/// Decompose the polygon into several smaller non-concave polygon.
/// If the polygon is already convex, it will return the original polygon, unless it is over Settings.MaxPolygonVertices.
/// Precondition: Counter Clockwise polygon
/// </summary>
/// <param name="vertices"></param>
/// <returns></returns>
public static List<Vertices> ConvexPartition(Vertices vertices)
{
//We force it to CCW as it is a precondition in this algorithm.
vertices.ForceCounterClockWise();
List<Vertices> list = new List<Vertices>();
float d, lowerDist, upperDist;
FVector2 p;
FVector2 lowerInt = new FVector2();
FVector2 upperInt = new FVector2(); // intersection points
int lowerIndex = 0, upperIndex = 0;
Vertices lowerPoly, upperPoly;
for (int i = 0; i < vertices.Count; ++i)
{
if (Reflex(i, vertices))
{
lowerDist = upperDist = float.MaxValue; // std::numeric_limits<qreal>::max();
for (int j = 0; j < vertices.Count; ++j)
{
// if line intersects with an edge
if (Left(At(i - 1, vertices), At(i, vertices), At(j, vertices)) &&
RightOn(At(i - 1, vertices), At(i, vertices), At(j - 1, vertices)))
{
// find the point of intersection
p = LineTools.LineIntersect(At(i - 1, vertices), At(i, vertices), At(j, vertices),
At(j - 1, vertices));
if (Right(At(i + 1, vertices), At(i, vertices), p))
{
// make sure it's inside the poly
d = SquareDist(At(i, vertices), p);
if (d < lowerDist)
{
// keep only the closest intersection
lowerDist = d;
lowerInt = p;
lowerIndex = j;
}
}
}
if (Left(At(i + 1, vertices), At(i, vertices), At(j + 1, vertices)) &&
RightOn(At(i + 1, vertices), At(i, vertices), At(j, vertices)))
{
p = LineTools.LineIntersect(At(i + 1, vertices), At(i, vertices), At(j, vertices),
At(j + 1, vertices));
if (Left(At(i - 1, vertices), At(i, vertices), p))
{
d = SquareDist(At(i, vertices), p);
if (d < upperDist)
{
upperDist = d;
upperIndex = j;
upperInt = p;
}
}
}
}
// if there are no vertices to connect to, choose a point in the middle
if (lowerIndex == (upperIndex + 1) % vertices.Count)
{
FVector2 sp = ((lowerInt + upperInt) / 2);
lowerPoly = Copy(i, upperIndex, vertices);
lowerPoly.Add(sp);
upperPoly = Copy(lowerIndex, i, vertices);
upperPoly.Add(sp);
}
else
{
double highestScore = 0, bestIndex = lowerIndex;
while (upperIndex < lowerIndex) upperIndex += vertices.Count;
for (int j = lowerIndex; j <= upperIndex; ++j)
{
if (CanSee(i, j, vertices))
{
double score = 1 / (SquareDist(At(i, vertices), At(j, vertices)) + 1);
if (Reflex(j, vertices))
{
if (RightOn(At(j - 1, vertices), At(j, vertices), At(i, vertices)) &&
LeftOn(At(j + 1, vertices), At(j, vertices), At(i, vertices)))
{
score += 3;
}
else
{
score += 2;
}
}
else
{
score += 1;
//.........这里部分代码省略.........
示例4: PolygonTrigger
public PolygonTrigger( GameWorld world, Texture2D active_texture,
Texture2D inactive_texture, Vector2[] points, TriggerableObject triggered_object = null,
TriggerType type = TriggerType.FLOOR, float cooldown = -1, float rotation = 0, String name = "Trigger",
String texture_name = TNames.ground_switch_inactive )
: base(world, active_texture, inactive_texture, Vector2.Zero, triggered_object, type, cooldown, rotation, name, texture_name)
{
Vector2 diff = points[0] - points[(int)Math.Ceiling( points.Length / 2f )];
float multiplier = Math.Min( Math.Abs( diff.X ), Math.Abs( diff.Y ) );
m_width_height = new Vector2( multiplier, multiplier ) * 2;
Vector2 sum = Vector2.Zero;
foreach ( Vector2 p in points ) {
sum += p;
}
pos = sum / points.Length;
m_position = pos;
for ( int i = 0; i < points.Length; i++ ) {
points[i] -= pos;
}
if ( texture_name == TNames.wall && m_is_destructible ) {
m_texture_name_change = TNames.breakwall;
//m_texture = GameScreen.GAME_CONTENT.Load<Texture2D>(m_texture_name);
}
else if ( texture_name == TNames.tile ) {
m_texture_name_change = TNames.tile;
//m_texture = GameScreen.GAME_CONTENT.Load<Texture2D>(m_texture_name);
}
m_points = points;
Vertices verts = new Vertices( points );
Vertices collinear_simplified = SimplifyTools.CollinearSimplify( verts );
Vertices merge_simplified = SimplifyTools.MergeIdenticalPoints( collinear_simplified );
//Since it is a concave polygon, we need to partition it into several smaller convex polygons
//List<Vertices> vert_list = BayazitDecomposer.ConvexPartition(merge_simplified);
verts = merge_simplified;
verts.ForceCounterClockWise();
m_points = verts.ToArray();
}